Sun is bringing its JavaFX development framework to mobile devices. The latest release of the JavaFX SDK, version 1.1, offers full support for mobile JavaFX development and includes an emulator for testing mobile device compatibility. The move could help Java retain its relevance on handhelds as rival Adobe works to boost the popularity of Flash and AIR for mobile development.

JavaFX, which was first announced in 2007 and rolled out to the public in December 2008, is a framework for building rich Internet applications on top of Java. It includes a scene graph library and a unique scripting language that provides a declarative syntax for constructing sophisticated graphical user interfaces. Its graphics capabilities include support for animation, visual effects, gradients, and translucency.

JavaFX content integrates well with existing Java code, which means that developers can use it to bring better user interfaces to legacy Java applications and to build new Java software that can rival Flash programs in rich interactivity. JavaFX Mobile is designed to run on devices that support Java ME. A number of carriers and handset makers—including Orange, Sprint, Sony Ericsson, and LG—have already committed to bundling it on upcoming products.

"By delivering JavaFX Mobile on top of the wireless Java platform, Sun is now bringing expressiveness to the most pervasive and powerful platform in the mobile industry," said Sun client software group VP Jeet Kaul in a statement. "We are thrilled with the excitement and interest we're seeing for JavaFX from many of the world's top handset manufacturers, service providers and ISVs, which will help us bring this new technology to market and to the world very quickly."

JavaFX common and desktop API profiles

One of Sun's goals is to make JavaFX work seamlessly across desktop and mobile targets with support for a wide range of devices. JavaFX Mobile supports the "core" API profile, which includes a subset of the JavaFX APIs that are supported on the desktop.

The APIs that are not available in the core set include the visual effects packages (shadows, blurring, lighting, and reflection), the Swing user interface components, and support for introspection. You can see specifically which parts of the API are missing from the common set by toggling between the "desktop" and "common" lists at the JavaFX API index page in the reference documentation.

In theory, developers should be able to make JavaFX applications that run on both desktop and mobile devices by sticking to just the common API elements. In practice, it seems like a lot of existing JavaFX code and demos already depend on features that are not supported in the common API profile. Fortunately, the difference between the desktop and common API profiles is slim enough to make porting relatively easy.

Developers can test applications with JavaFX Mobile by installing version 1.1 of the SDK and configuring the project in the NetBeans IDE to run in the mobile emulator. To do this, simply open the project properties dialog, navigate to the "Run" page, and select the "Run in Mobile Emulator" option. After setting that preference, NetBeans will automatically launch the emulator when you run the program in the IDE.

My own simple demo application, which I developed for my hands-on review of the initial JavaFX release, requires features from the desktop API profile and consequently isn't compatible out of the box with JavaFX Mobile. This is also true of most of the demo applications that Sun provides with the SDK. Sun provides a mobile variation of the Display Shelf demo which does work out of the box, so it's a pretty good place to start if you just want to see the emulator in action.

The Display Shelf Mobile demo also provides some useful insight into the process of porting desktop JavaFX applications to work with the common API profile. If you run a diff to compare the Display Shelf and Display Shelf Mobile demos, you can see that Sun didn't have to change much to get it to work.

JavaFX Mobile is intended to work on everything from high-end smartphone products to basic handsets. Although this will allow JavaFX Mobile applications to reach a broad audience, it creates some challenges for developers. Runtime performance and screen resolution will not be consistent across that entire product spectrum and developers will have to build their JavaFX software accordingly.

Other features

JavaFX 1.1 includes a number of other improvements in addition to mobile support. The JavaFX media production suite got an update, performance and stability have been improved, and several new features—such as full-screen support—have been added for desktop applications.

JavaFX is still not supported on the Linux platform, but Sun says that it is fully committed to achieving Linux compatibility. Sun wants the Linux port to use platform components like GStreamer and integrate well with native services.

Java ME has traditionally been one of the most popular vehicles for delivering third-party software on mobile devices. This is changing rapidly as developers turn to native mobile frameworks in order to get more advanced functionality and broader support for accessing underlying phone features. Flash is also beginning to displace Java in the mobile space in much the same way that it already has on the Web. JavaFX Mobile could infuse Java with new life on handheld devices and give it a much-needed edge against Flash and other emerging technologies.