Pet Store with JavaFX 1.0. Part 1.

I work for a company called Farata Systems. Laura is our office manager, and she doesn’t know Java. Everyone else does.  We work in the enterprise RIA space using Adobe Flex as a main development tool for creating all these Web pages connecting to the server side applications written in Java.

In December of 2008, Sun Microsystems has released the first version of a language for developing UI for RIA. I’ve been watching the evolution of JavaFX from its announcement at JavaOne 2007 till its release, but wasn’t able to find any demos that would prove that this extension of Java platform can be considered as a candidate for boring needs of enterprise applications. Watching demos like a bunch of balls moving inside a glass didn’t look too convincing to me.

We decided to contribute to Java community and invest some time and resources to figure out what JavaFX 1.0 is capable of. Most of the Java developers know what Pet Store application is. For many years this reference implementation has been used by Sun Microsystems as a part of Java BluePrints program for Java EE platform.

The current version of this application is described in the article called “Introducing the Java Pet Store 2.0 Application” that’s available at

We re-used the existing back end of the Pet store, but performed a little facelift by replacing the UI developed with AJAX/JSP/JavaServer Faces with JavaFX 1.0.

I was working on this project with our senior Java developer Alex Litskevich who’s done lots of digging and research trying to find the best solutions whenever we would run into limitations of JavaFX.
The goal of this introductory article is to demo the JavaFX Pet Store. You can watch a quick prerecorded demo at .

In the future, I’ll deploy this application in one of our public servers and will review the code.

Last year, while attending a conference in India, I met an excellent Sun’s software engineer Greg Murray, one of the authors of the idea of Pet Store application.   Greg, I hope you’ll like this version of your pet store.

Flex, JavaFX, Silverlight…

I’ll be honest with you, during development of this application in the back of my mind I’ve been constantly comparing the way things are done in JavaFX with how I’d do the same with Adobe Flex.
Simply put, today, Flex is a lot more productive than JavaFX.  But let’s remember that we are comparing products of versions 3 vs. version 1. If you know how to develop Swing applications, you might want to continue doing this rather than manually creating JavaFX 1.0 wrappers for Java code as we did in our Pet Store.

The biggest issue is that JavaFX 1.0 doesn’t include any UI component library that a Web developer needs. I’m not talking about data grids or tree views. Even such simple things as a hyperlink component aren’t there. I can’t think of any other reason but a trivial lack of time and limited human resources allocated by Sun for development of this new UI set.

Hopefully, Sun will release a JavaFX 2.0 in foreseeable future with a full set of UI components, containers, navigators, and layouts. Just to draw an analogy, Microsoft has released absolutely naked Silverlight 1.0 in 2007, but full featured Silverlight 2.0 became available a year after.
The good news is that Java developers have already started building their own open source components for JavaFX. The name of this project is jfxtras .

On the other hand, I see some features available for JavaFX developers that are missing in Flex.

For example, ActionScript doesn’t support multi-threading. This is not an issue when it comes to communication with remote sites – all remote calls are asynchronous and use callbacks for server-to-client data flows. But if you’d need to write or use an existing Java library that performs some CPU-intensive calculations on the client, I’m sure Java will beat ActionScript.  The syntax of both languages is pretty similar though (see
JavaFX supports eval() function that allows to compile and execute a piece of code on the fly. Flex doesn’t  support this useful feature.

Two-way binding already exists in JavaFX but in Flex will get it only in version 4.

I’ve yet to see some benchmarks comparing Flex and JavaFX network protocol.  The latter just offers XML and REST for data exchange between client and server.  Of course, you can program Java sockets or wrap up an RMI client into JavaFX – would it be faster than ActionScript Real-Time Messaging Protocol? We don’t know. Or take HTTP tunneling between   Java Applet and a server-side Java stream. Would it be faster than using AMF, an HTTP-based binary protocol? We don’t know yet.

JavaFX removes a lot of complications in developing mobile applications. It promises to remove the need of using Java SE for desktop and Java ME for mobile – JavaFX should be the only solution you need. JavaFX Mobile offers hardware acceleration.  Keep in mind, there are 2.6 billion of Java enabled mobile devices! JavaFX has serious advantage in this domain over Flash Lite.

JavaFX 1.1 is about to be released. It offers performance improvements, bug fixes, new features in the mobile space, but no major additions to the desktop platform.

I understand that this is not a good time to ask for some serious cash injections, but if executives of Sun Microsystems won’t find a way to double the size of the team working on the future version of JavaFX, entire Adobe Flex team can safely go on sabbatical for a year.  If the money is tight, the sooner JavaFX will go open source, the better.

Even though I wouldn’t start developing with JavaFX a project that needs to go in production this year, overall, JavaFX looks promising. Try it out and see for yourself.

Yakov Fain