Book Review: JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-Side Applications

   

Books Index

by James L. Weaver
Publisher: Apress
ISBN: 1-59059-945-4
Publication Date: October 2007

Reviewed by Robert Eckstein
December 2007

Speeding ahead of the curve with one of the first JavaFX Script books is Apress's new JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-Side Applications. It's obvious from the onset that author James L. Weaver is passionate about JavaFX technology. Not only is he the owner of the Learn JavaFX blog, he is also an active user on the Open JFX compiler group. In short, the book is an inexpensive way to come up to speed on JavaFX Script technology, and with five chapters and approximately 200 pages of material, it's a quick and easy read for those who are already familiar with graphical user interface (GUI) programming in the Java platform.

Note that at the writing of this review, the book was a print-on-demand title: If you order it through the conventional channels, it will take some time to deliver because the publisher has to print and bind it first. If you don't want to wait, however, there is a simpler solution: Download the PDF of the entire book from the Apress Web site. Aside from the ability to instantaneously read it, this has the wonderful side effect of saving the publisher printing, binding, and distribution costs. This savings is then passed on to you -- the cost for the downloadable PDF is a very agreeable USD $12.50, approximately half the cost of the print version.

Chapter Contents

The book starts with a brief, four-page chapter -- a high-level introduction to what JavaFX Script technology is and where it fits into the Java programming world. The second chapter discusses JavaFX development environments and provides a quick introduction to the declarative programming structure of JavaFX using the simplest of development tools: JavaFX Pad. Here, you'll also be teased with some of the native JavaFX GUI widgets, such as Frame, Canvas, Text, and Font -- items you'll visit in more detail later in the book.

Because I was already familiar with the basics of JavaFX Script technology, I leafed through the first two chapters in five minutes. Things got interesting in Chapter 3, where the author starts by outlining the model and view classes for a simple tool that creates a word-search puzzle in a 9-by-9 square grid. After a short tour of the program itself -- where we're left wondering whether the author considers Pluto a dwarf-planet -- we dive into the meat of the design on pages 36 to 39. Programmers who are already familiar with Swing will find the initial containment hierarchy of the tool fairly straightforward and easy to grasp.

In fact, Swing programmers can largely breeze through some of the easier design items, such as menus, toolbar, frames, and simple dialog boxes, not only because they have used these components countless times in the past but because JavaFX technology frequently calls down to the Swing libraries to get its job done. So even with the new declarative syntax, understanding the hierarchy and how it works is fairly simple.

The bulk of Chapter 3 -- some 50 pages, a good portion of which is code -- then works to explain the more interesting items: model and view classes that are assigned to the grid's elements. This was my favorite part of the chapter because I could take some of the arbitrary conventions that the author introduces and reuse them as design patterns for my JavaFX code. For example, assigning a model and view class to the entire grid is an obvious strategy, as well as assigning a model and view class to each of the 81 squares in the grid. However, bundling all of the GUI event handlers -- that is, the code that is executed when, say, a user presses a button -- into a single JavaFX class is an interesting approach that works well with the program structure, allowing the same handler code to be executed from multiple entry points such as a mouse click on the grid or a menu item selection. This "reusable handler" concept is similar to Actions in the Java Swing world.

On page 53, the relationships between the model, view, and handler classes are shown in full detail with a look at the initialization code. However, the author does not explore them in detail until Chapter 4. Here, we start to get into the specifics of the JavaFX Script programming language, including items that Java programmers will not have seen before, such as triggers, sequences (which one of the JavaFX Script compiler developers described as "arrays on steroids"), and operations.

You may be wondering about triggers. Triggers are an interesting concept that database programmers are likely to be familiar with: A section of code is executed only when a condition that is defined as a trigger occurs. Here is an example of a trigger that keys off a change of a Boolean attribute myBooleanAttribute in the MyJavaFXClass class:

trigger on MyJavaFXClass.myBooleanAttribute = newBooleanResult {

    if (newBooleanResult) {    //  is true
        //  Do something
    } else {                   //  is false
        //  Do something else
    }
}
 

The first part of Chapter 4 shows how to use triggers for testing assertions on model code, a less common but valuable technique in JavaFX Script. Once you start using triggers, however, you'll quickly realize that using them effectively takes a bit of rethinking on the part of the traditional Java programmer. In fact, the book mentions several types of triggers -- assertion triggers, creation triggers, replacement triggers, insertion triggers, and deletion triggers -- and each one has a specific use that becomes clear once you start to look at some example techniques. For example, replacement triggers are a useful feature that, after you look at them more carefully, seem to obviate getter/setter accessor functions that a Java programmer might be tempted to place in a JavaFX class.

Next, Weaver introduces the reader to sequences and their common uses in JavaFX Script. This naturally leads to a detailed explanation of the models of the word-search example, a tidy excuse to reintroduce us to JavaFX Script statements, operators, and conventions. For the most part, these are similar or identical to Java technology, so Java programmers will find themselves quickly flipping through this part, although my favorite additions are the do and do later statements, which help with concurrent processing. The do statement is especially useful if you're executing code on the event-dispatching thread (EDT).

On a side note, page 107 shows another gem in the rough: a recommended structure for a JavaFX Script class file. I tried this out for a few days with my JavaFX classes and found that it was logical enough to adopt it.

Once you've mastered the basics of the language, you're then ready to plow into Chapter 5, which introduces one of the key strengths of the JavaFX Script programming language: support for graphical libraries. A quick introduction to the underlying Java 2D libraries is in order, and the book jumps straight into it, explaining the various shapes and graphic objects that are available to any JavaFX Script programmer, as well as using the ubiquitous Group object to logically hold them together. Some of these libraries are sufficiently different from Java technology that you'll want to read this chapter carefully.

Finally, creating a custom graphical component in JavaFX technology requires a bit of handholding the first time through, and Chapter 5 does exactly that, coming full circle in an explanation of how the custom user interface (UI) view widget for the word search works. At this point, the author explains the rest of the JavaFX widgets in full detail. I found this detailed explanation the most important part of Chapter 5, because it gave me some design strategies that I can use with my own custom JavaFX graphical components.

Summary

As with any title that is first out of the gate, you have to be aware that the book explains a technology that is still being developed, first from the original F3 specs into the JavaFX Script language, which debuted at the 2007 JavaOne conference. Even now, development is progressing with the JavaFX Script compiler project.

Consequently, this book doesn't cover every aspect of JavaFX. For example, the book has only a small section in Chapter 5 on animations, which you can expect to be a significant portion of JavaFX Script in the next two years. In fact, Sun is currently working on a developer tool that will greatly assist both content producers and programmers in creating animations using JavaFX Script.

That being said, the book is easy to follow and covers its announced topics in glorious detail. So if you're looking for a good introduction to the JavaFX Script language, at a price that's sure to impress, this first book on JavaFX Script is hard to beat.

For More Information
Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
Your email address (no reply is possible without an address):
Sun Privacy Policy

Note: We are not able to respond to all submitted comments.
false ,,,,,,,,,,,,,,,