04 June 2009

JavaFX 1.2 On Linux

Yesterday I had an excellent opportunity to give JavaFX 1.2 a spin on Ubuntu Linux (8.04 LTS - Desktop Edition). A 30 Kbps ADSL connection is used as the Internet Connection. All performance figures are informal and will greatly differ between Linux desktops. Some additional media codecs have been installed, which provide support for additional media file formats (including WMV and WMA) for GStreamer in Linux.

Before installing the JavaFX 1.2 SDK I installed JDK 1.6 (Update 14) which is a requirement for the JavaFX SDK. However the Java browser plugin had to be configured afterwards for Firefox, which is not as difficult as many might think it is. It is as simple as creating a link in Firefox's profile folder that points to the plugin itself. Do note that it is highly recommended that you setup the JDK_HOME and JAVA_HOME environment variables. After installing and configuring the JDK a test was in order to see if the browser plugin was properly functioning, which I can safely say passed with flying colours. You will need to have the Java browser plugin working in order to run most of the sample JavaFX applets on the official JavaFX site.

Installation of the JavaFX 1.2 SDK went smoothly, it was a matter of running the shell setup script and moving the SDK folder to the correct location. What I was most impressed with in terms of installation was the NetBeans IDE (with built-in JavaFX support). The experience was totally seamless, even the JDK was picked up by the IDE's installer and the JavaFX SDK was already included with the IDE. Right from the start of starting up the IDE I was able to create and run a JavaFX application in 15 minutes which included basic multimedia support.

In terms of multimedia support on Linux as many Linux users will know, is a hit and miss affair. When it came to testing multimedia support with JavaFX was was pleasantly surprised with the experience, since it had exceeded all my expectations. The following media formats that I had tested with my own JavaFX application work out of the box:

  • WMV (WMA has not been tested but is most likely to work)
  • MP4
  • OGG
  • FLV

Only the MP3 media format did not work as expected. During the first 3 seconds of playing an MP3 file everything sounded fine until stuttering occured. JavaFX has a built-in events to handle the stuttering effect. I have not used the event (inside the application) in light of the problem with the MP3 file. What I found strange is that on the official JavaFX site the JavaFX media player is used on Windows to play the videos, but on Linux I am forced to use the Flash media player. This appears to be due to the faulty platform detection code because I saw the following message on the web page, "Note: you have reached this page because you are on a platform not currently supported by JavaFX. If you think you have reached this page in error, please click here.".

The biggest highlight on the JavaFX SDK release for Linux has to be the performance, which is absolutely outstanding. From running applets to desktop applications I hardly noticed any pauses or freezes while the programs were running. My hat goes off to Sun for this since this is certainly one area where JavaFX can not only get ahead of other competitors, but also increase adoption by developers.

I personally decided to stress test the Java browser plugin by running 10 JavaFX applets (from the Samples section of the official JavaFX site) simultaneously. Most users will not run that many applets at once, however it is still useful to see how performance and stability fares when multiple applets are running. Firefox did not crash once when all ten applets were running and the reserved memory usage for the plugin (java_vm process) was not too bad at 153.2 MB. On average 15.32 MB is reserved for each applet. What needs to be done in memory usage though is to have memory released as soon as an applets exits (the Windows version already has this capability).

Now comes the part where many people will shudder (including me) at the thought of starting up/launching applets. In the past this has been a real archiles heel for Java desktop applications. I can proudly say after testing start times for applets (in the Samples section on the official JavaFX site) that startups are MUCH faster. In the worst case one applet took 14 seconds to startup. On the opposite side of the coin there were quite a few applets that took no longer than 3 seconds (there were even ones that only took a second!).

Upon attempting to run all sample applets (on the official JavaFX site) I found that most applets would startup and run properly. Here are following samples that do not run properly:

  • Draggable MP3 Player (cannot play any MP3 music and cannot drag applet out of the web browser)
  • Keystroke Motion (applet does nothing when applet is selected and keys are entered)
  • Video Cube (refuses to play an FLV file whic)

The biggest downside for the deployment of JavaFX applets is that some of them totally freeze the web browser while starting up. If you are a user then you would totally be intimidated by this to the point where you would avoid any websites that freeze the web browser. The freezing normally occurs for no more than 3 seconds for most applets. This freezing has to be resolved in time for the next update of the JRE for Linux. By that time JavaFX developers will be ready to test deployment of applets.

As for awful surprises all JavaFX applications that I have launched through Java Web Start fail to start up at all. All of these failures have once thing in common, the MalformedURLException is displayed as the root cause of the failure. Java Web Start was not broken like this in previous releases of the JRE for Linux. It will certainly be a top priority to fix Java Web Start for Linux in time for the next release of the JRE.

Integration of JavaFX applications with the OS is a real plus. I can copy and paste text to and from a JavaFX Text Box, I can even copy and paste text via drag and drop. Do note that text cannot be selected by word with the keyboard or mouse. Creating full screen applications does not currently work properly (the title bar is missing). Maximizing and minimizing the application works as expected.

For some reason media streaming is hit and miss with the Media Box sample (on official JavaFX site). During the first few seconds of playing the video the sound plays just fine before it cuts out. The Video Cube sample fails to play the FLV file (a MediaUnsupportedException is displayed in the message) even though it is playable in my JavaFX desktop application.

Overall I would highly recommend the JavaFX SDK for software developers that are using Linux despite that fact that Sun has classified the SDK as being in Beta. In my opinion I consider the SDK to be a release candidate, but that is up for debate by other developers. Despite the deployment situation being bad developers can very comfortably create JavaFX applications right away. In the mean time look out for the next update of the JRE which should improve deployment from being bad to not too bad. By that time you can safely test the deployment of JavaFX applications.

JavaFX 1.2 is a HUGE step forward which should help with its adoption, and advocacy even though it is a little bit behind its competitors in some areas (deployment, UI building), but ahead in others (performance, component architecture, binding, cross platform support). It is very good to see JavaFX rapidly catching up to its competitors, and that Larry Ellison is extremely enthusiastic about it, to the point where he is prepared to make a full commitment (this includes development). Now it would be nice to see a SVG to FXM converter (many people are using Inkscape as an open source alternative to Photoshop - this is starting to become common place with JavaFX) with the next JavaFX SDK release, and the GUI designer which I am VERY eager to try out.

A note to Sun about support for developing JavaFX mobile applications on Linux. Linux has a very large presence in the mobile development area. Since the first versions of the CDLC and CDC SDKs (before they were rolled into the JME SDK) there has been solid support for Linux. It is very disappointing to see that there is hardly any support for Linux with the JavaFX SDK on the mobile side. Also there is no JME SDK (version 3) for Linux. I am expecting that there will be an actual JavaFX mobile emulator, as well as a release of JME SDK (version 3) for Linux by the time the next JavaFX SDK is released.

While JavaFX mobile applications can be developed on Linux (in theory) there is no way to properly test and deploy them on a mobile emulator, or mobile device. Considering that JavaFX is going to shake up the mobile development scene for the better, would it not make sense to provide a good level of support for Linux in order to have widespread adoption?