Sun's JavaFX Takes On Flash, Silverlight

At this morning's session of the JavaOne conference in San Francisco, executives of Sun Microsystems are expected to announce the near-term availability of a version of Java exclusively geared to rich Internet application (RIA) developers. Commandeering Microsoft's leftover, unused brand name (".NET FX"), Sun is said to have dubbed this new system "JavaFX."

Its target market, based on information Sun gave exclusively to the trade press and which was leaked early, will be the developers of Web-enabled applications outside the browser. Although that was Java's target market to begin with, Sun appears to be concentrating on the portable graphics developer, in an attempt to fill in the gaps between Java and Flash. In recent years, Adobe's Flash has become the platform of choice due to its ability to scale graphics onto multiple devices, which is now beginning to include cell phones and handsets.

As part of the suite, Sun is expected to announce a new and perhaps initially bewildering embedded language called JavaFX Script - not JavaScript, not ECMAScript (one standardized form of JavaScript), not AJAX (Asynchronous JavaScript). This may be the culmination of what had been called "Project Flair," which could perhaps be described as JavaScript if Java's creators had created it.

Previous attempts by Sun's marketing people to describe Flair without giving away the secret, have led to some confusion. It will be interesting to see, for instance, whether JavaFX Script is actually written in JavaScript as had earlier been suggested (which might make things a little slow) or run as a separate kernel from Java altogether, which would seem on the surface to defeat the whole point of attaching a scalable vector graphics model onto Java in the first place.

3:45 pm May 8, 2007 - As it turns out, JavaFX Script is a scripting language utilizing a subset of Java concepts, mixed with some new concepts that substitute for their more object-oriented counterparts. The result is a purely procedural language that is biased toward the production of graphic objects, and the input and output of data.

Its strong point is the facilitation of exchanges between server and client over the Web, but the language itself is almost a throwback to the ALGOL-derived languages of the 1970s and early ‘80s. It’s less object-oriented, and more pragmatic.

For the most part, JavaFX resembles JavaScript (which was originally developed outside of Sun, for Netscape) more than it does Java. As with JavaScript, you declare variables using the var keyword; and while you should declare variables, they’re not necessarily explicitly typed. In other words, the interpreter can determine for itself whether a variable whose initial value is set to 0, should not be an alphanumeric string.

Furthermore, if you declare var iValue as equal to [1, 2, 3], the interpreter can determine for itself that iValue is an array. And like JavaScript, JavaFX uses the import statement to borrow classes directly from a Java library.

But aside from JavaScript’s familiar syntax of declarative instructions closing with semicolons, the JavaFX language branches off on its own, proving decisively that it’s not JavaScript. For example, its handling of arrays and lists is more like a database, with instructions like insert [4, 5] as last into iValue; which is a very straightforward method of appending entries at the end of an array.

Further, the language actually makes use of predicates - a concept typically used in database languages – for declaring criteria for entries from an array that should be deleted, as in delete iValue[. >= 4]; Here, everything in the square brackets acts as the predicate – the criteria for which deletion should take place, in this case, everything greater than or equal to 4. The period acts like a reflexive operator, or like the old DOS symbol for “this” when referring to “this directory.”

JavaFX Script (a.k.a. “JavaFX,” according to Sun) programs can run within the existing Java 1.6 kernel. We tried a few demos ourselves this afternoon, which ran without our having to have modified the Java kernel ourselves first. Rather, the kernel downloaded the extensions needed for it to handle scalable vector graphics in the background.

Rather than rely on multiple inline references to Java graphics libraries, JavaFX refines the graphical framework. It does not embed anything in a Web page. Rather, it enables you to declare functional graphic elements using a fairly self-explanatory and non-confusing syntax...that is most definitely not JavaScript, or anything like it.

In practice, a JavaFX-enabled program could take the place of a rich Internet application developed using AJAX, or using the scalable vector graphics toolkits for Flash and Silverlight (which are both generally dependent to some degree on AJAX anyway). But the fundamentals are different. Typical RIAs are constructed in such a way that the HTML page acts as a substrate for the graphical or text objects with which the user interacts. No such HTML substrate exists in JavaFX.

Instead, in an almost uniquely unremarkable fashion, graphic objects are declared like variables, and attributes are assigned to them individually. The syntax is structured and tabulated, rather than jumbled together like an inline instruction, so the newcomer can assimilate the basic principle of how to declare an object without having to memorize which term corresponds with what attribute.

The staggering of attributes onto individual lines, while probably optional, is quite intentional. It enables developers to get a better handle on the attributes of objects, in what may prove to be a far more intuitive way than with CSS.

Conceivably, just before the declaration of the Circle object, the statement filter [] could be added, setting up an array for Photoshop-like filters to be applied to the object, or to whatever Group of objects are declared within. So if you expand the filter array, for instance, to include filter [ShadowFilter], you immediately create the default drop-shadow for the declared object.

Veteran Java programmers will note that, at least for now, JavaFX makes use of graphic objects borrowed from the realm of Swing, Sun’s 2D graphics library.

So here’s how the RIA scene stacks up at present: With the advantage of the biggest installed base is Adobe Flash, which racks up the lion’s share of scalable vector graphics applications on the Web. While Adobe is expanding the Flash system with the Flex environment, its language is based on an embedded XML schema that remains browser-dependant.

Microsoft answered the challenge last month with Silverlight, a .NET subset that can run in Linux and Mac OS, which teases developers with compatibility with its ASP.NET AJAX version, but then tries to lure those same developers into the broader realm of .NET development with applications languages like C#. It starts out browser-dependent, but in full fruition doesn’t have to be.

Coming from the opposite end of the field is Sun’s JavaFX, which builds on the Java platform by creating a new language that the same interpreter can execute (just like the .NET Framework can interpret multiple languages), that tries to be JavaScript the way Sun would have done it from the beginning.

But Sun’s objective is to try to yank RIAs off the browser as much as possible, moving clients into a realm where they’re no longer dependent upon Microsoft or open-source groups to keep the technological ball rolling. It is a very interesting time indeed to be a Web developer.

A JavaFX rendition of Motorola's 'Studio Moto' site, which is rendered elsewhere using Flash.