JavaFx preview released, here’s my HelloWorld app and some initial thoughts

August 1, 2008

Sun Microsystems today announced a preview release of the JavaFX SDK.

I’ve been observing this new entrant into the RIA space from the outside but today I thought it was time to dig in a little bit. So I got my hands on the latest Netbeans wit JavaFx support and cooked up this little Hello World application….
 

Initial thoughts

Here are my initial thoughts of the technology .. I will try and share more detailed opinion, once I know the technology a little better ..

  • I don’t particularly like the YAML like declarative syntax for describing UI .. I think XML as used by Flex and Silverlight is more readable .. but I guess this is more of a personal preference
  • The Netbeans IDE for JavaFx is fairly basic and somewhat buggy right now, I hope this will improve over time
  • Did they really achieve their goal of making Java UI development simpler than Swing? .. I’m not so sure … I guess I’m still getting used to the JavaFx style of UI development
  • JavaFx needs a good way to share source, Flex’s really easy way of sharing code has helped adoption, since it makes is very easy for the people in the community to share and learn from each other

 
Launch Application using Java Web Start
(Note, Java 1.6 is required)
 

Source:


/*
* Main.fx
*
* Created on Aug 1, 2008, 6:00:51 AM
*/

package helloworld;

import javafx.application.Frame;
import javafx.application.Stage;
import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.text.Text;
import javafx.scene.Font;
import javafx.scene.FontStyle;
import javafx.scene.paint.Color;

/**
* @author Mrinal Wadhwa
*/
public class HelloNode extends CustomNode {

public function create(): Node {
return Group {
content: [
Text {
font: Font {
name: "Verdana"
size: 30
style: FontStyle.PLAIN
}
x: 60, y: 110
fill: Color.WHITE
stroke: Color.WHITE
content: "Hello World from JavaFx"
}]
};
}
}

Frame {
title: "Hello World !"
width: 500
height: 250
closeAction: function() {
java.lang.System.exit( 0 );
}
visible: true

stage: Stage {
fill: Color.DARKGRAY
content: HelloNode{}
}
}

I will share more detailed code whenever I get some more time to play with JavaFx. Meanwhile here are a few resources that will help you learn ..

I look forward to the final release of Java SE Update 10 and the final release of JavaFx SDK .. these are exciting times in RIA land.

17 Responses - What do you think?

  1. @Mrinal Nice blog -:) But…Isn\’t too much code for a simple Hello World? And why release a NetBeans plug-in that is enough mature to satisfy developers…I wanted to learn JavaFX until you told me about it on Twitter….Now, after reading your post…I really don\’t have interests in learning it….Anyway, hope to see more example and \”pictures\” -:)

    Greetings,

    Blag.

  2. Blag,

    I agree, I could cut out a few lines from the above code .. but it still is quite a bit of code for a hello world app .. I’m sure I could write the same app in Flex with a fraction of the above code. Although I’m going to wait till I write some real code in JavaFX, before I make a judgment. But, as I mentioned above I do find XML to be a better way of describing UIs

    Mrinal

    PS: Sorry about all text and no pictures .. after you mentioned I realized I haven’t been paying attention to that in my recent posts :)

  3. I’m not incredibly well versed in Flex but I would think that if you included all of the lines in your mxml file, along with your actionscript code, they would be comparable in size. Anyone care to post “Hello World” in flex so we can have an old fashioned shootout.

    This said, I did make a demo application using a preview release of JavaFX. I started right before they completely changed their package structure, ugh. While there is a lot to like about the language (first-class functions, databinding built in), I found that it just felt…restrictive after a while.

    Additionally, the larger an object gets, the more complicated the binding. To the point where it gets unwieldy. You’d think that the bind keyword would clean things up. Maybe I just need to play with the language a while longer.

    Glad you like JavaFX. I’d like to see Flash given a run for it’s money.

  4. Robert,

    For your sake I posted a Flex Hello World app :)

    Flex Hello World

    Source

    Its not an exact equivalent since it does not have the windowing code for the Frame that is there in the above JavaFx app … but what is important to note is the readability of code in Flex because of XML being used to describe the interface .. I kinda like that although that may be just a personal preference.

    Could you expand on how you found language restrictive? .. I presume that the solution to large Classes will be to break things down into smaller ones.

    Mrinal

  5. It use to be simpler than this. For example,

    Frame {
    title: “Hello World JavaFX”
    width: 200
    height: 50
    content: Label {
    text: “Hello World”
    }
    visible: true
    }

    I noticed this yesterday when I created a Frame in Netbeans,

    stage: Stage {

    }

    still learning here … but I’m hoping that they don’t move away from the simplicity that was first visioned and they can stay on par with lingo that’s easily recognizable by a ui designer. Adding stuff that a programmer would only understand will seriously detract from the usability aspect and not to mention the ability to clearly see the relationship between layout and code.

  6. That\’s a big download for Hello World. And I guess if you do anything remotely interesting, you are going to need a whole slew of libraries (javamail.jar if sending mail, activation.jar if consuming a webservice etc.).
    I think it will be JavaFX\’s fate that the core JRE is so limited as it is… in contrast to Flex and Silverlight where things just appear to work out of the box without further libs.

  7. sboulay,

    Yeah the old code (in earlier versions of JavaFX) used to be simpler but with the whole stage and customnode thing they made it some what more verbose.

    Mrinal

  8. Its a big download for hello world app! May be that will the deciding factor.

  9. Casper and Thejesh.

    We were having a similar discussion over at an insideria thread and Josh Marinacci from the JavaFX team replied as follows ..

    “Yes, download time will be greatly improved in the future. The JavaFX runtime for desktops will be hosted at a single Sun location, meaning it will be cached once and shared between all JavaFX apps. Additionally, we plan to pre-install / bundle it with future JREs (exact details to be worked out). Remember, this is just a preview release. :)

    Hmmm .. so until they decide they bundle it with JRE .. the first time someone runs a JavaFX app the download will be fairly big … this looks similar to the framework caching feature in Flex only difference being that the Flex framework is a few hundred KB .. while the JavaFX libraries right now are a few MB. I hope this improves.

  10. So many JARs get downloaded right now maybe all of them are not really required, or maybe some of them will be available by default in the JRE once SE 6 Update 10 comes out … If javafxrt.jar is the main runtime jar then that is 520 kb .. that is a fair enough size for a one time download .. I need to understand this better

  11. Thanks for the update Mrinal. It shall be interesting to see. I still think Sun missed the boat on that one when the left the whole browser/desktop game in the end of last decade to focus on the EE space almost exclusively.

    The problem seems to stem from deeply rooted architectural reasons in the code base – now counting 17.000 classes!
    The philosophy of Java turned out to revolve around a ton of design patterns and reliance on external libraries over decent, but de-facto standard means build right in. As I mentioned, I\’ve experienced this only too well when developing client apps which needed to send a mail (1mb jar needed), or consume a web service (4MB jar\’s needed).

    Whenever I play with Silverlight/.NET or Flex I am always amazed how things just work, they are great package deals. I do hope Sun can fix this. But given their loyalty towards old and deprecated stuff in the name of backwards compatibility, I\’m not overly optimistic in this regard.

  12. Gerhard Balthasar
    August 4th, 2008

    @Coffeecakeandcode

    Well, two thing to note: I made a Swing WS-consuming app (which also communicates with a serail COMM port) in Java with the size of 300 kb in total (using KSoap, RxTx and Fat Jar/OneJar). I guess thats pretty slick then…

    Second point: When working with .Net you must remeber, most of the needed DLLs/Libs are already included in the OS. When comparing let’s face JRE against .Net Runtime and JDK against .Net SDK. There’s not much difference left. And with Java YOU have the choice to select from multiple Libs for the problem domain while with .Net you mostly need to stick to M’softs provided Libraries.

    Which in turn is a plus point for easier development though. Well I must commit, as a JAVA developer after coding around Groovy I really like C# after tried it some time ago. Well, after it all depends on your needs and your problem what to pick and what your company allows (forget this for private development :-) .

    For JavaFX: It’s not to to musch do download for the things included in the beta an its not too late at all as most developers do not have the choice what to pick and there will be some years floating by since RIA technolgies are really adopted by the companies as mine (although I was allowed to deveolop a release management with Groovy Monkey…)

    Greetings, GHad

  13. @Gerhard
    I am sure the inclusion of JAX-WS in the recent Java 6 have helped on this, it is now a few years ago and there was no JAX-RPC support build-in whatsoever.

    My point still being valid though, a lot of \”basic stuff\” you simply can\’t do with just the Java runtime. I don\’t really care if the runtime lives in DLL\’s or a big fat rt.jar, same thing. And the choice moniker doesn\’t really score any points either, after all, nothing stops you from shipping your own libraries with .NET or Flex either. Case of point, you HAVE to ship a JAR in many cases in Java, i.e. if you need basic smtp support (sending a mail) that means include javamail.jar or even javaee.jar.

    I like Java. All I am saying is that the out-of-the-box experience or the rt.jar leaves things to be desired, This is especially visible in the client-Java//RIA space where not necessarily needing libraries matter a lot on the experience for the end user.

  14. The yaml is bearable, but the identation style bothers me.

    Is the javafx.ext.swing going to stay around for much longer? At the moment, skinning a swing based JavaFX app looks like it’s going to be too difficult for a UX designer.

  15. It took over 10 seconds to download the app. And then I had to approve it to run. WTF Sun! Haven’t you guys learned any damned thing from Java applets?

  16. javafx is brand new – but I’d bet more than a dollar that it’s gonna give the big boys a run for their money for the simple reason that many universities teach in java. This fact has helped sun dominate the server space against the Redmond hordes. Adding RIA to this knowledge base is like the wake-up call linux got by adding a desktop to the ‘mystically, all powerful’ terminal.

  17. @javanum1 Universities teach Java, they do not teach JavaFX Script the main language used to write JavaFX apps

Your thoughts or questions: