RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


JavaFX Enters the RIA Race : Page 5

JavaFX Script is a new scripting language from Sun meant to provide rich user interfaces to compete with AJAX, Silverlight, and many other RIA technologies. What does JavaFX look like, how does it work, and will it succeed? Those questions and more are answered in this introductory review of JavaFX.

Automatic binding keeps the user interface and objects synchronized. But how do actions like the return investment calculation get kicked off? Notice that in this user interface, there are no buttons for the user to push to initiate action. Another neat feature provided by JavaFX is triggers. Triggers are events that fire on data modifications. They behave like listener methods, but are simple to use and program. In this example, triggers were established for any update to any of the InvestmentTool attributes. In the trigger below, for example, anytime an InvestmentTool instance's attribute numberOfYears is set to a new value, this "update" trigger fires resulting in a call to the getReturn() method.

trigger on InvestmentTool.numberOfYears = value {
However, a trigger can be set up for any type of object/data modification. Triggers can be set up for new instance creation or even insert, replacements or deletes to a multi-valued attribute (like an Array).

Static Typing
As you saw in the class definition of InvestmentTool (see Listing 4), attributes are typed. So are other variables in JavaFX. Unlike JavaScript, JavaFX is a statically typed language. Like JavaScript, however, if you don’t specify a type on a variable when it is declared, its type is determined based on its use. So, the following code implicitly types x as an Integer.

var x;
x = 3;
However, because of its static typing, once set, a variable in JavaFX cannot be assigned a value of a different type. While the code below would be legal in JavaScript, in JavaFX, it results in an "IncompatiableTypes" compile error.

var x;
x = 3;
x = "hello";
Beyond classes/objects, JavaFX supports four primitive types: String, Boolean, Number, and Integer. These correspond to Java's java.lang.String, java.lang.Boolean, java.lang.Number, and any of byte, short, int, long, or java.math.BigInteger for JavaFX's Integer.

Java APIs
You may have noticed in the getReturn() or hypotenuseLength(a, b) methods described above, both made reference to Java's java.lang.Math class and used one of its methods (see Listing 4). Just as in regular Java classes, the first lines of InvestmentCalculator.fx contain import statements.

import javafx.ui.*;
import java.lang.Math;
Indeed, JavaFX programs can import and use Java classes and interfaces just as they are used in standard Java applications. Proponents of JavaFX are sure to highlight this feature as it allows JavaFX to reuse existing Java code and helps reduce the learning curve for those concerned about yet another scripting language.

JavaFX Still Young
The ability to quickly develop and more easily maintain rich GUIs that are based on the powerful and well-known Swing API gives JavaFX its appeal. While not Java, its Java base and ability to use Java when required or desired reduces the learning curve and allows for a great deal of immediate reuse. However, JavaFX is still very young and still gaining its sea legs. There are some issues you may want to consider before adopting JavaFX wholesale. It has even been suggested that JavaFX in its current state "doesn't really give developers the ability to do much they couldn't do already, its function is primarily to make existing Java technologies easier to use together."

To date, there are no visual editors for JavaFX development. For a technology that aims to satisfy user interface and the RIA community needs, this will have to be rectified. It appears that this is a well-known need and one that is to be addressed shortly. As Chris Oliver has suggested in his weblog, "So far I haven't spent time trying to develop serious visual tools to support [JavaFX] development, however once the language and API's have stabilized that's definitely something I want to do."

Figure 9. Documentation: Using control-shift to get the code assist documentation for many classes in NetBeans shows just how much documentation work is still to be completed.

By the way, for those anticipating Sun is going to use JavaFX to replace Swing, Sun insists this is not the case. Directly from OpenJFX FAQ page, Sun says it "is not replacing Swing with JavaFX; instead, JavaFX Script makes Swing much easier to use."

Developer documentation and IDE support is also thin. Even though plug-ins for NetBeans and Eclipse are available (as shown above), simple programming features such as syntax color highlighting and code formatting are missing. Even the code assist documentation suggests there is still a lot of work to be done. Open the documentation for many classes in the IDE and you notice how much "TODO" documentation placeholders exist in this early JavaFX release (see Figure 9).

Finally, the early versions of JavaFX don't provide much insight on how this scripting language will integrate and tie into the larger application picture. For example, how will JavaFX assist with solid UI content and style separation? How will JavaFX applications at the client-side communicate effectively and asynchronously with the server-side? How do JavaFX applications get deployed or provisioned to the client, especially on mobile/consumer devices?

More Questions Than Answers
JavaFX enters a young and burgeoning RIA marketplace.Will it survive? Will it become the UI scripting language of choice especially for Java developers? It is still too early to make that prediction. However, given its ties to Java and the ability to take RIAs beyond the desktop browser into mobile and consumer devices without rewrites is an attractive offering worthy of exploration and careful study today with possible implementation contemplation tomorrow.

Jim White is an instructor with Intertech Training. He is also co-author of Java 2 Micro Edition, (Manning).
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date