When I installed the latest Sun JDK 6 recently, one of the installer wizard screens had a JavaFX logo on it, and I wondered what it was, so I checked it out. It turns out that JavaFX is a family of products from Sun to compliment Java, specifically geared towards designers and web developers creating dynamic web content. The Java language was originally supposed to do this anyway, but it never really got off the ground for web content in the face of Flash and Javascript. Java is a fairly traditional programming language, with it’s syntax based on C and is likely to give any web developers and designers, who aren’t necessarily classically trained programmers, a bit of a shock. JavaFX contains a completely new language, which is declarative in style, and hence should make it easier to code graphical UIs and content based around concepts like screens, images, animations etc. rather than worry it’s users with threads, memory management and data structures.
Something that also caught my eye was it’s mobile cousin, JavaFX Mobile. Sun has been successful in getting Java technology into mobile phones, a lot of mobile phones to be precise! A few minutes of Googling didn’t come up with any actual figures, however I would go so far as to say that Java ME is probably the most ubiquitous general purpose computing application platform on the planet, in terms of numbers of in use handsets today. I expect actual numbers are available to industry insiders who pay subscriptions to data gathering companies, rather than casual internet searchers!
According to Bruce Hopkins in an article on Sun’s web site, there are Three Reasons Why Your Next Java ME Mobile Application Should Include JavaFX Mobil. I’m not going to be using JavaFX in my next mobile application however, and I’ll explain why in relation to Bruce’s reasons one at a time.
A declarative syntax is certainly useful when getting non-programmers to actually produce content for your application. Looking at it from a mobile games point of view, I work with game and level designers who take an engine that I create and use it to build a game. This is a two way parallel process, not something that happens in series. A designer will create an initial specification including a feature set, the programmer will go away and implement that, and then as the level designer (often the same person as before) uses the engine to create and add game content (eg. levels), there will be a back and forth dialog with the programmer as new features are proposed and potentially implemented, bugs ironed out and the newly designer created content fed back into the game build process.
The tools that the programmer creates to give to the designer often contain a scripting language. It would be nice to build a fully featured graphical design tool specific to every game, but time constraints usually prevent that. The designer almost always has to get their hands dirty with some game scripting. This might be in a custom language written by the programmer, or it could be in a general purpose scripting language like Ruby, Lua or Python to name three. Either way, it’s likely to be heavily declarative in nature. The designer will use the script to declare game elements, like the level layout, player start position, enemy positions, enemy types and actions, scripted events keyed to triggers and timers, etc. In this respect, JavaFX Mobile looks like it might be are great tool, a declarative language already built on top of the game implementation language (Java ME)…
However, as a programmer, have a look at this syntax and see if you’d give it to a designer?
package notifier;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
var img = Image {
url: "{__DIR__}email.png"
}
Stage {
width: 200
height: 250
title: "Mail Notifier"
scene: Scene {
content: [
ImageView {
image: img
x: 0
y: 0
}
Text {
font: Font {
size: 16
}
x: 10
y: 140
content: "New Email Received!"
}
]
}
}
There are way to many curly brackets for a start, giving you all that nesting to contend with. And look at those square braces in the middle there, what the hell are they suppose to mean? There’s no way I would save any time by giving this to a designer, I’d be constantly hand holding them through the compile errors and reminding them when they need one type of bracket or another. There are lots of existing scripting languages that have a much cleaner and more natural syntax for ease of use by non-programmers. Creating your own language can also be an enticing prospect, but it’s not something to get into lightly. Programming language processors and compiler techniques are a highly complex area to deal in, but experience in it can be very valuable. In the tradition of Blue Peter, here’s one I made earlier:
# Level script file.
# Anything after a hash on a line is a comment.
# Case is not important.
# Initialisation section
code=start
# Dimensions (in tiles) and tile size (in pixels)
level dim=54,50 tilesize=16 id=mission3 number=3
flags=!revealed, !complete, !failed, !shop
nametext=Text_mission3_name
introtext=Text_mission3_prologue
outrotext=Text_mission3_epilogue
respawn_id=respawn1
# Garret's start position
character type=garrett id=garrett posn=51,48.95 anim=idle:0:left
# 2nd guard in left tower
item type=map id=map3 posn=0,0 flags=hidden,infront
character type=guard id=guard2
posn=10,23.95
anim=walk:0:right
pocket_id=map3
action=patrolling_left
end0=left:8,27 end1=right:8,19 look=10 stand=5 health=8 hit=2
# End of initialisation section
endcode
# Triggers that cause things to happen
code=triggers
# Map trigger
trigger action_id=reveal_map when
test_flags item id=map3 flags=owned
endtrigger
# End of triggers
endcode
# Actions that are run by triggers
code=actions
# reveal the map
action id=reveal_map
setflags level id=mission3 flags=revealed
endaction
# End of actions
endcode
The comparisons here should be pretty obvious. No braces or nesting to worry about, just 3 separate sections that contain code for different purposes. No import statements, which comes from the domain specific nature of the language. I myself can never remember which package or library a class comes from most of the time, someone scripting for me shouldn’t have to. The one common element between both examples is named parameters. That’s something I would consider essential in any language intended for a non-programmer to use, at least JavaFX has that right.
On the surface, this is a pretty good reason to use JavaFX, if it wasn’t for the fact that all those millions of mobile devices available in the shops today won’t support it! Only the very latest handsets will have support for it included, and the numbers of those sold are going to pale in comparison to the existing device take up figures. That’s the big problem with mobile development, the massive device fragmentation problem. I expect that it will take at least 1 years for any new Java ME feature to make it into handsets, and then at least another year on top of that before enough handsets are available to make it worthwhile developers using that feature. I’m assuming that JavaFX mobile needs device manufacturers to make devices that support it. It may be possible to code using the JavaFX script and have the source compile to standard Java bytecode that runs on existing MIDP 2.0 devices. If that’s the case, then fantastic, as long as the required supporting libraries aren’t 100′s of kilobytes big! There are still phones that only support jars of 64k or less, I’m looking at you Nokia Series 40 v1 devices.
I’ll concede that this feature is quite nice, and certainly makes trivial examples like updating a text field when a slider moves nice and easy. I’d like to see some more heavyweight usage examples though, and I’d like to see what non-programmer designers make of it. If programmers are going to be writing the scripts, they’ll probably quite quickly run into it’s limitations and end up writing custom code for all sorts of circumstances. I won’t rag on this feature too much at the moment though since I’ve got more to learn about it. One thing I will say though is that it’s simply one language feature, and not something I think should weigh heavily on any decision to use JavaFX in a project or not.
So, there’s a brief look at JavaFX Mobile and why my next mobile application won’t use it. It’s certainly interesting, and might have more relevance to non-game applications, but I predict it won’t be a feature anyone shouts about loudly for very long!