The Artima Developer Community
Sponsored Link

Java Community News
John O'Conner Explains JavaFX Functions and Operations

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

John O'Conner Explains JavaFX Functions and Operations Posted: Oct 9, 2007 12:30 PM
Reply to this message Reply
Summary
JavaFX is Sun's new scripting language for rich-client user interfaces. As a domain-specific language, it differs from Java in many ways, such as how JavaFX programs are structured around functions and operations. John O'Conner explains the distinction between functions and operations in a recent Sun Developer Network article.
Advertisement

JavaFX Script is Sun's new scripting language for developing rich clients. Because it targets the domain of user interfaces, JavaFX Script includes programming constructs that make UI development easier. Two basic JavaFX constructs supporting UI development are functions and operations. John O'Conner's latest Sun Developer Network article, JavaFX Script Functions and Operations explains the difference between the two, and how they relate to data binding, a common UI development task.

The JavaFX Script programming language allows you to create both functions and operations, and the difference between the two is significant but not entirely clear at first glance.

JavaFX Script function bodies can contain only variable declarations and a return statement. No loops or conditional operations are allowed. Functions have limited side effects and are intended to transform one or more values to another.

Functions are interesting because they reevaluate their return value whenever their parameters or any other referenced variable changes. This is a useful feature when you want to bind an object to a specific value that might frequently update...

JavaFX Script operations most resemble Java methods. Like functions, operations can have parameters and return values. One big difference from functions is that operations can also contain if-then, while-loops, for-loops, and other conditional statements. You declare an operation much the way you declare a function, but use the keyword operation instead.

The ability of functions to re-evaluate their values based on changes in function parameters, as well as their limited potential side-effects, support the concept of data binding, a common UI programming task. JavaFX Script provides explicit data binding between two properties via the bind operator:

JavaFX Script has a bind operator that allows one attribute to track changes in another attribute. Binding an attribute to another means that the bound attribute will always be aware of changes in the target attribute...

The bind operator works well with functions too. Because functions incrementally update their results whenever either their arguments or referenced variables change, binding to a function works just as well as binding to a single attribute. In fact, functions really are designed to be used with bindings. You can use them to refactor bindings into reusable subroutines that automatically track all their dependencies, including both their parameters and referenced variables in their body.

What do you think of JavaFX script as a DSL for user interfaces?

Topic: Cedric Beust on Programming Erlang Previous Topic   Next Topic Topic: Jean-Marie Dautelle on Java Measures and Units


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us