Migrating to the JavaFX 1.1 Release

14 02 2009

My original post about migrating from the preview release turned out to be quite a lot more popular than I expected, probably due to the sheer amount of changes to deal with.  Fortunately, the amount of change in the JavaFX 1.1 Release is miniscule in comparison. However, you may still run into a few language and API changes that will affect any moderately complicated application.

To start with, the most important thing of note is that the JavaFX 1.1 release is not binary compatible with JavaFX 1.0.  This means that you will have to recompile not only your application, but also all libraries that it depends upon.  (For you JFXtras users out there, we are working on a JavaFX 1.1 compatible release that is already available in source form, and will be shipped Tuesday 2/17)

Once you start compiling your applications, you may trip across some of the following language changes:

  • Variables declared public-init/public-read/def cannot be overriden – My favorite subclassing trick is now gone…  public-init variables can now only be initialized in the object constructor.  If you would like to override a variable in the subclass consider changing the permissions to public-init protected instead. (Thanks to Robert Field for recommending this workaround)
  • Number no longer has double precision – For performance reasons (particularly on mobile devices), Number is now mapped to a Java Float instead.  If you were counting on the additional precision, your application may not function as expected, but you can take advantage of the Double type directly thanks to the additional type support (see below for more information).
  • Stricter requirement for adding override – There were some cases where the compiler would not flag a compiler error if a method was missing the override keyword.  Now it is required everywhere.
  • Duplicate variable initialization – It used to be last initialization wins, but now the first one does… simply remove the redundant initialization and you are good to go.  This has been filed as JFXC-2665 and will be fixed with a compiler warning in Marina.  (Thanks to Uday Dhanikonda for pointing out the corresponding defect)
  • Code generation for variable get/set has changed – If you are directly accessing JavaFX code from Java, the mechanism for getting and setting property definitions has changed from a wrapper object to direct getters and setters on the interface.

While the API changes are minimal, there were a few things changed or some cool things you definitely want to take advantage of:

  • HttpRequest no longer has shutdown/shutdownNow – If you use either of these methods, you are going to have to remove them and recompile your code.
  • Additional core types – You can now use Character, Byte, Short, Long, Float, and Double as types in JavaFX to map to the corresponding Java types.  Several places in the API (including reflection) have been expanded to support the additional types.
  • Inclusion of FXD classes – The classes needed to manipulate FXD files generated by the Production Suite are now included in the core JavaFX distribution.  This includes: Duplicator, FXDContent, FXDLoader, and UiStub.
  • XML enhancements – Lots of small enhancements in the XML support.  The ones visible in the API are extra options on the PullParser for ignoreWhiteSpace and UNKNOWN events for errors.  Also the ability to emit QNames as XML strings.
  • Duration now divisible by other durations – There is now an extra div method on the Duration class so you can divide one duration by another.
  • And don’t forget the new mobile support!

Finally, for those of you using NetBeans, you will overall be very very happy with the latest release.  It adds in lots of improvements and bugfixes that make everything from adding imports, to formatting your code, to working with dependent projects much easier.  However, a few things to watch out for include:

  • Static imports are not working – While static imports compile fine, the IDE considers them an unused import even if you have used it in the file.  This is exacerbated by the next item.
  • Over-aggressive formattting – Whenever you press return on the last line of the file, the whole document will get reformatted.  This is great if it does the right thing, but there are a few boundary cases like static imports, misalignment of javadoc comments, and aggressive line breaking that will make it more of a nuisance than a benefit for now.

While I have hit on many of the highlights of the new release, it is also worthwhile to check out the JavaFX 1.1 Release Notes.  In particular, they list a number of still unresolved issues that are good to know about when you are developing an application for different platforms or mobile development:


I hope this information is helpful to the JavaFX early adopters out there, and please comment on any differences or additional changes you notice in the comments section!




4 responses

14 02 2009
Michael Galpin

What about long strings? Concatenation? Triple quotes?

15 02 2009
Java Desktop links of the week, February 16th | Jonathan Giles

[…] of the changes, Stephen Chin posts about how to migrate your JavaFX applications from previous releases onto the latest 1.1 release. This document will be invaluable to JavaFX developers wondering how to migrate, so give it a […]

16 02 2009

really cool

17 02 2009
Notes from Stephen Chin on Migrating to the JavaFX 1.1 Release - Use JavaFX

[…] As a result of JavaFX SDK 1.1 being released last week, Stephen Chin created an article that highlights the changes from JavaFX SDK 1.0.  […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: