![]() |
|||||||||||||||||||
|
|
|||||||||||||||||||
Conference Tools
|
Technical Session: Introduction to JavaFX ScriptOne of the most-populated sessions of the first day of the 2009 JavaOne conference was Introduction to the JavaFX Programming Language (TS-5576), by Stuart Marks, a developer at Sun Microsystems. The session was a whirlwind of important information that no novice JavaFX programmer should be without. Marks started off by describing JavaFX as a "scripting language for interactive graphics, media, and animation." He pointed out some of JavaFX technology's key features:
JavaFX has many scriptlike features, as well as the convenience of data binding. It also allows programmers to create functions both inside and outside of classes, function variables, and even anonymous functions. In addition, it has rich object functionality, including the ability to inherit both classes and a new type of pseudoclass in JavaFX 1.2 called a mixin, which is similar to interfaces in Java technology. Marks then mentioned that JavaFX technology has "sort of" a scripty feel to it. A JavaFX script is essentially a sequence of expressions. In other words, everything inside JavaFX -- including loops, conditionals, and even blocks -- is, in fact, an expression that results in some value, even if the value is simply In this session, attendees also learned that in the JavaFX environment, all variables must be declared, either with a However, while JavaFX can use type inference, Marks pointed out that JavaFX is statically typed. In other words, the language figures out what type a variable is at compile time, never at runtime. Marks then introduced the base JavaFX types: Another useful bit of information: You can also place full expressions inside the curly braces, where the expression will resolve to the appropriate value to insert into the In JavaFX, functions are declared using the function add(argOne: Integer, argTwo: Integer) {
result = argOne + argTwo;
println("{argOne} + {argTwo} = {result}");
}
The session also introduced JavaFX classes. Classes are declared using the
class Customer {
var firstName: String;
var lastName: String;
var phoneNum: String;
var address: Address;
function printName() {
println("Name: {firstName} {lastName}");
}
function printPhoneNum(){
println("Phone: {phoneNum}");
}
function printAddress(){
println("Street: {address.street}");
println("City: {address.city}");
println("State: {address.state}");
println("Zip: {address.zip}");
}
}
Marks then spent some time on sequences. Sequences are analogous to arrays in the Java programming language, but with additional functionality that makes the data easier to manage. For example, you can abbreviate a known range in a sequence by using the first entry, followed by two dots and the final entry. You can determine the size of a sequence by using the Much as in the Java programming language, you can use the Binding is one of the most valuable features of JavaFX technology. Bound variables work by mapping any changes to one variable immediately to another, so that the two always remain in sync. However, Marks pointed out that A Finally, the The As such, programming in JavaFX is similar to programming in Java technology, but implementing classes is a little different. For example:
JavaFX is a wonderful new language for programming rich clients, and this session showed some of the best that JavaFX has to offer. For more information, including examples of each of these features, see the official JavaFX home page. Do you have comments about this article? We welcome your participation in our community. Please keep your comments civil and on point. You may optionally provide your email address to be notified of replies - your information is not used for any other purpose. By submitting a comment, you agree to these Terms of Use. |
||||||||||||||||||
ContactUs | About Sun | Privacy | Terms of Use | Trademarks Conference content is subject to change. Copyright 1996 - 2009 Sun Microsystems, Inc. |
![]() |
|