Jim has posted 66 posts at DZone. You can read more from them at their website. View Full User Profile

Getting Ready for the Imminent JavaFX SDK 1.0 Release

10.30.2008
| 5206 views |
  • submit to reddit

As you may know, the OpenJFX Compiler project has been making improvements to the JavaFX language out in the open, so I'd like to get you up to speed on these in preparation for when the entire JavaFX SDK 1.0 is released yet this fall.  Today I'll discuss some of these language changes:

def Jam

A keyword has been introduced, named def, that is designed to be used to define constants in JavaFX.  The value of a variable declared with def may not be subsequently changed, except through the bind mechanism.  For example, in the code snippet below, the second line won't compile because it is attempting to assign a value to PI after it has been declared with def:

 def PI:Number = 3.14159;
PI = 22.0 / 7.0; // This line doesn't compile

Use var Everywhere -- attribute is History

For consistency, the var keyword is now used to declare instance variables, replacing the attribute keyword.  The result is that var is used to declare local variables, instance variables, and module (script) level variables.  Of course, we've been using var all along to declare local variables in a function.  The following (contrived) JavaFX program contains examples of using var and def in the ways just discussed:

/*
* DeclaringVariablesMain.fx -
* An example of declaring variables in JavaFX SDK 1.0
*
* Developed 2008 by James L. Weaver (jim.weaver at jmentor.com)
* to demonstrate how to declare variables in using def and var in JavaFX
*/

//script-level variable that also is a constant (def)
def PI:Number = 3.14159;

class Vehicle {
//instance variables
var wheels:Integer;
var wheelDiameter:Number;

function getVehicleType():String {
//local variable
var types:String[] = [
"Unicycle",
"Motorcycle",
"Tricycle",
"Car"
];
types[wheels - 1];
}

function totalWheelsCircumference():Number {
wheels * wheelDiameter * PI;
}
}

//script-level variable
var myG6 =
Vehicle {
wheels: 4
wheelDiameter: 14
}

//println is a built-in function now
println("Total wheels circumference of my G6 {myG6.getVehicleType()} "
"is:{myG6.totalWheelsCircumference()}");

Here is the output that I received when running this program:

Total wheels circumference of my G6 Car is:175.92904

Other Noteworthy Items

As shown above, we no longer have to import java.lang.System to use the print and println functions.  Also, remember that since JavaFX is a block expression language, return statements aren't necessary in the functions above.  The value of a block is the last expression in the block.

In future posts I'll continue discussing JavaFX languages enhancements that have been introduced in the OpenJFX Compiler project.  This will help you prepare for the JavaFX SDK 1.0 release that is just around the corner!

Regards,

Jim Weaver
http://JavaFXpert.com

Published at DZone with permission of its author, Jim Weaver.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Jacek Furmankiewicz replied on Thu, 2008/10/30 - 7:01am

Don't get me wrong Jim. I am seeing a lot more excitement about the JavaFX API, rather than the language itself. Most people seem more interested in using from regular Java, rather than making a risky investment in a brand new language.

I would recommend to you that all of these examples should be shown in both JavaFX and using regular Java (with the JavaFX APIs)...just my $0.02

 

Otengi Miloskov replied on Thu, 2008/10/30 - 8:20am in response to: Jacek Furmankiewicz

+1

I want to see the API with Java not JavaFX script, also why I have to use def for constants and var for variables?, it was better like Groovy use def for everything even constants.

JavaFX script looks not so well designed little bit a mess, IMHO.

my 2c too.

Jeff Devis replied on Thu, 2008/10/30 - 8:25am

 

OtengiM, totally agree with you

swing developper deserve more attention,

 

Jacek Furmankiewicz replied on Thu, 2008/10/30 - 9:11am in response to: Otengi Miloskov

And on the same path, are you guys finally going to change the Project Scenegraph license from pure GPL to at least GPL with classpath exception so that non-GPL code can use it?Same thing applies to the JavaCSS project that is Sun-developed...

Carl Antaki replied on Fri, 2008/10/31 - 4:29pm

Jacek is right we're all Swing developers. I find what's the most interesting for me is the ability to play videos in a cross platform manner as well as using the platform's native players and the animation part. There is still no good documentation and good tutorials. The syntax might be very easy and straightforward for the ones that designed the language but for us it's not the case and we still prefer Swing and most our code is written using Swing, also appart from the Hello World examples, it would be beneficial to show how large apps could use JavaFX.  A tutorial on how to integrate JavaFX code in Swing application would be appreciated. I would definitely have preferred the time to be spent on fixing the bugs already present in Swing such as the ugly JFileChooser and the other bugs in Swing.

Richard Bair replied on Fri, 2008/10/31 - 2:18pm

Hi Carl,

I think it is important to realize that Swing is the preferred way for writing truly large control-rich applications. JavaFX 1.0 is much more targeted at the nike.com type of applications, data visualization applications, and other applications which are really rich graphically. Swing is your friend for enterprise applications :-). For example, JavaFX 1.0 doesn't have a component toolkit. 

Richard 

Carl Antaki replied on Fri, 2008/10/31 - 4:58pm in response to: Richard Bair

Hi Richard,

JavaFX might be fast as it's compiled and runs on the JVM but it has 3 problems:

  • To have a good experience it requires Java 6 Update 10 which is only available on Windows and Linux. Every time someone asks Sun about that, they say it's Apple's fault, it might be but for JavaFX to be a widespread technology the new plug in should be available on all platforms? Did we forget the WORA?
  • Startup speed is still too slow. It's still way slower than Flash and Silverlight.
  • Lack of tools
Given all these combined I find it hard for JavaFX to compete with Flash and Sliverlight.

Carl

Osvaldo Doederlein replied on Sat, 2008/11/01 - 12:32pm in response to: Carl Antaki

[quote=carcour]

Hi Richard,

  • To have a good experience it requires Java 6 Update 10 which is only available on Windows and Linux. Every time someone asks Sun about that, they say it's Apple's fault, it might be but for JavaFX to be a widespread technology the new plug in should be available on all platforms? Did we forget the WORA?

[/quote]

On the Mac platform, the requirement is only 6u5 which is the latest Mac JVM available; I tested that. But I don't know if it's generally equivalent... some 6u10 improvements are not needed in the Mac, e.g. the JavaKernel (since the Apple VM is a standard component of OSX); but one improvement in particular, the new J2D-over-D3D9 pipeline, seems to be an important foundation for JavaFX's most sophisticated sfx. I wonder if Apple VM's pipeline is equivalent in the capacity to acceelrate all important J2D APIs, so JavaFX features won't suffer.

Carl Antaki replied on Sat, 2008/11/01 - 1:03pm in response to: Osvaldo Doederlein

I don't own a Mac but if I'm not mistaken Java 5 is the default Java on Mac OS X and Java 6 is only available on 64 bits Mac and Soylatte is available for 32 bits Macs. Except Java developers no one will install Soylatte.

Osvaldo Doederlein replied on Mon, 2008/11/03 - 6:41am in response to: Carl Antaki

[quote=carcour]I don't own a Mac but if I'm not mistaken Java 5 is the default Java on Mac OS X and Java 6 is only available on 64 bits Mac and Soylatte is available for 32 bits Macs. Except Java developers no one will install Soylatte.[/quote]

AFAIK, 32-bits/PowerPC Macs are in the "old garbage" category, not even Apple supports that platform decently anymore...

Andres Almiray replied on Tue, 2008/11/04 - 2:44pm

For those complaining about var/def, take a look at Scala's var/val, looks similar? you bet! while it may be a good idea to standardize how variables and attributes are defined the big problem here is that _all_ current examples of creating a CustomNode are broken! every single one of them uses the now defunct attribute keyword, I'm feeling deja-vu here, didn't this happen just before jfx preview was released on July (the introduction of stage, component relocation)?

I agree that the JavaFX APIs (the JavaFX platform) are the most interesting feature rather than JavaFX Script.

Richard Bair replied on Tue, 2008/11/04 - 5:20pm in response to: Carl Antaki

Hi Carl,

 

 To have a good experience it requires Java 6 Update 10 which is only available on Windows and Linux. Every time someone asks Sun about that, they say it's Apple's fault, it might be but for JavaFX to be a widespread technology the new plug in should be available on all platforms? Did we forget the WORA?

 

I've not generally found this to be the case (and believe me, I build some intense apps). Yes, you need Update 10 to get a good applet experience. Do keep in mind this project is not a 3.0 or 4.0 -- there is lots and lots of improvement coming. There's a lot of low hanging fruit.

Even so, I work on (and in fact am typing on) a 32 bit mac book pro with Java 5. I build and test on it every day. JavaFX runs much faster on Windows with the D3D pipeline than on Mac with Java 5, but we are making headway and this will not always be the case.

 Startup speed is still too slow. It's still way slower than Flash and Silverlight.

Yes it is, and we have several performance optimizations both in terms of class loading and other optimizations that will close this gap. It isn't going to be there overnight, but it is being aggressively worked on.

  Lack of tools

Depends on what you mean by "tools". Do you mean code editors? IDE's? Illustrator? SVG tooling? Matisse like layout?

We do have, and will continue to have, an emphasis on tools. 

It isn't going to be perfect on day 1, but we full well know what we need to do to be competitive and will execute on those things. We will compete. 

Adrian A. replied on Thu, 2008/11/06 - 6:47am

I like Java allot, but will never use JavaFX (it's just the worst possible move from SUN).

Oh, and killing Swing http://www.pushing-pixels.org/?p=758 is pure suicide IMO - will alienate all long time loyal developers. 

Carl Antaki replied on Sat, 2008/11/08 - 10:01pm in response to: Richard Bair

Hi Richard,

By lack of tools I mean for example that Netbeans 6.5 doesn't include JavaFX support. There are no good tutorials about the language since the syntax of the language changed and I haven't seen yet an exciting app written in JavaFX except games. Let's wait to December 2. I'm excited to see what JavaFX will bring. Hopefully it will be good. Good luck to you and all Sun developers.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.