20 September 2009

Ten Interesting Aspects Of JavaFX Script

With the JavaFX Script programming language being cited by many as one of JavaFX's main strengths it is time to look at the language's interesting aspects. Some aspects will pleasantly surprise you, while others will come as a shock. Here are the 10 interesting aspects of the language.

1. Built-in support for generators

Comes in handy for generating multiple items. In particular it is commonly used for generating multiple nodes for use in layouts. Each generated node may be customized differently to accommodate different data being supplied for display.

2. Can run actions at a later time

Useful for displaying splash screens properly when there is some background processing going on. Below is some sample code that demonstrates this (in a script):

// Splash screen is displayed here.

public function run(args: String[]): Void

function doBackgroundProcessing(): Void
// Background processing is done here.
// Display the main screen, and then close the splash screen.

What is important to remember here is that the function you are passing to the deferAction function must have a return type of Void. The deferAction function allows the splash screen to be fully displayed, and we can have the main screen displayed just after the splash screen is closed.

3. Can format dates in strings

Some concise syntax is provided by JavaFX Script to enable you to embed date formatting in strings.
All of the date formatting options in the SimpleDateFormat class can be used, for example:

var formattedDate = "{%MM/dd/yy java.util.Date{}}";

In the above code a % char is used followed by the date format and a Date object to format a date in an expression.
It may be possible in future JavaFX releases that regular expressions can be used as a string formatting option.

4. No support for static functions, variables and constants

An exception to this is with scripts, not classes. It would be interesting to know why JavaFX Script has no static support (an important design decision that was made?). Someone from the JavaFX development team would be able to shed more light on this.

5. Basic support for lookups (on nodes only)

Very handy when you do not want to keep a variable around, and want to temporarily access a node in order to run an action on it or make some changes. It may be possible that lookup support will be expanded to other areas (more general support) in future JavaFX releases.

6. Function parameters are immutable

At first this will be strange for those that have not done functional programming before. Since JavaFX Script has built in support for functional programming this makes sense. By making function parameters immutable it means that a function can safely perform operations on the parameter, without changing it thus when the program runs no funny side effects will occur.

7. Built-in support for mixins

Mixins are like interfaces except that you can define behavior in functions. Since mixins replace multiple inheritance it has made it easy to have a mixin or class inherit from multiple sources (mixins) in a predicable (clean) way. Do note that a mixin cannot be initialised.

8. First class internationalization support

This is one of the best features of JavaFX Script since it makes it a piece of cake to internationalize a program. Some unique syntax is used to make it easy to internationalize strings which hook up to a fxproperties file, for example:

##"Window Title"
scene: Scene{}

The title property's value is tied to a key called "Window Title" which is prefixed by ## (indicates an internationalised string). Here is the corresponding resources_en.fxproperties file that contains that key:

"Window Title" = "Main Window"

Some people would consider this to be another form of lookup in JavaFX Script. It is very much up to debate if this is the case.

9. Built-in support for animation

It is much easier to handle animation when it can be done directly without the need for a library (less abstraction), and most properties can be manipulated via binding for use on a timeline. The unique JavaFX Script syntax provides a concise way to animate nodes quickly in a scene graph.

10. Built-in support for binding

Makes it very easy to keep properties in sync, thanks in part to the unique JavaFX Script syntax. Even better is the fact that you do not need to create any tedious, and error prone boiler code to do it which helps to reduce overall maintenance.

Some of the formatting of this blog post is incorrect since I am unable to get the editor to properly change the formatting (major bug). Hopefully this will be resolved in time for my next blog post.

08 September 2009


With so much information available on HTML 5 at the moment, in particular with the rumor of HTML 5 killing off all the other major RIA technologies (JavaFX, Silverlight, Flex). Now is a good time to discuss the advantages and disadvantages between the two. Currently HTML 5 is being touted as the one technology to do everything, however to be honest it will be good at some areas, worse in others. Certainly many people will get a reality check once HTML 5 is used in real world projects. This reminds me of when Java was introduced since in a way history is repeating itself all over again.

For the basis of this article I will be commenting on what was mentioned in the well written article titled, HTML 5 Starts Looking Real. Be warned that while the web page is loaded that you may experience a very sluggish web browser, due to the Flash ads that have been embedded in the article. So be sure to close the web page as soon as you have read the article.

In the referenced article there is a lot of coverage on openness and why it matters, the author seems to think that HTML 5 will take over because it is fully open. But there is much more to it than having a technology that is open. While I am a firm beliver in using open source as much as possible, and where it makes sense to do so, I understand that to get the best out of software development you need to have balance.

Often this balance means being prepared to use something that may not be fully open sourced. Some of the best software/technologies in use today are not fully open sourced. If a software/technology is partly open sourced does that completely stop you from utilising it? Obviously that may not be a yes answer to that question since you may see some advantages with having some parts closed sourced, even though you prefer them to be open. Although all of the RIA technologies are not fully open sourced that does not stop people from using them.

As the referenced article mentions, flexibility is another major part to take into consideration when looking at HTML 5 and RIA technologies. Especially if you need to develop a highly sophisticated applications that tie into the underlying software/hardware platform. This is going to be an area that places HTML 5 at a significant disadvantage in relation to RIAs since it will largely be constrained to the capabilities of the web browser used by the user.

Advantages Of Using HTML 5
  • Can easily have search engines go through all content
  • Minimal learning curve since most people already know the basics of HTML
  • Cheaper budget with using any free tool that can handle HTML
  • Large pool of developers to choose from when forming a development team
  • Easier to deploy HTML 5 applications since HTML is supported natively by the web browser, and does not require any installation

Disadvantages Of Using HTML 5
  • Limited ability to take advantage of new software development techniques since the choice of programming languages is limited
  • Will take longer to evolve since it is a combination of standards that are developed by different groups
  • User experience will greatly vary between software/hardware platforms (lack of consistency)
  • Limited flexibility and power since HTML is constrained to the capabilities of the web browser
  • Poor choice for mobile platforms since it will not take advantage of the hardware and will provide very limited capabilities
  • Inconsistencies of HTML being implemented between web browsers (different parts of the standard are implemented)
  • Performance is largely constrained to the bandwidth that is available to the user
  • User may need be connected to use an HTML 5 application
  • Very limited support for media formats
  • Lack of good tooling to be productive in developing large sized HTML 5 applications
  • Basic animation and media features

Advantages Of Using RIA
  • Can provide a guarantee of a reasonably good user experience (consistently) between different software/hardware platforms
  • Can evolve quickly since it is developed by a single company/organisation
  • Able to take advantage of new software development techniques since there is a wide range of programming languages to choose from
  • Good tooling for developing large sized RIA applications (increased productivity)
  • Good performance and power since RIAs can take advantage of the software/hardware platform
  • Reasonably consistent implementation of features between software/hardware platforms (including mobile)
  • Good performance with access to the hardware
  • Wide support for media formats
  • Excellent choice for mobile platforms since it will take advantage of the hardware features and can provide a reasonable user experience
  • Advanced animation and media features

Disadvantages Of Using RIA
  • More difficult to deploy since a plugin will need to be installed first
  • Deployment of RIA applications are largely restricted to software/hardware platforms that have a plugin available
  • Smaller pool of developers to choose from when forming a development team
  • Increased learning curve since completely new technologies need to be learned
  • Search engines may be unable to go through content effectively

In general if you are planning to develop a simple application quickly that is not very sophisticated, and needs to be easily deployed then HTML 5 is a good choice. On the other hand if you are developing a highly sophisticated application, that requires a consistently good user experience then RIA is a good choice.

Also RIA should be favoured over HTML 5 if an application is going to be developed for mobile hardware platforms. Remember that a good user experience and the ability to have the application take advantage of the hardware (can be customised to the hardware), are the main considerations when developing applications for mobile.