News from Nov 02, 2009

  2009/11/02
JavaFX first experience
Last changed: Nov 02, 2009 16:36 by Ürgo Ringo
Labels: javafx, ria, mvc, eclipse, netbeans

Intro

JavaFX is a quite new platform for developing Rich Internet Applications (RIAs).
The claim is that it:

  • reaches every Internet consumer - on desktops, mobile, and new devices too.
  • delivers high performance - and the ability to engage creative professionals in the design process.
  • leverages existing skills and enterprise infrastructure.
  • is totally free, and open source.
  • provides content owners with control and ownership of their own data.

At first glance it seems, that it's true, however, if you start digging into it, you may be disappointed. Firstly, there is not so much good examples or showcases on the Internet, that show good sides of it. For instance, there is a "video of a really cool demo", that was done at Java One conference ..... even though the demo crashed a couple of times. Another official showcase can be found here. Basically, both showcases show how cool things can be animated, how cool it is to get application out of browser and put it into desktop.

However, for me it doesn't seem to be really the point, why I would choose JavaFX to write RIA! Hence I continued searching.... Something more suitable, what I would like to see I found here. Yeah, that's already something...but! Just take a look at the code of this application (it was written by one of JavaFX developers, not some "startup programmer"!)

I am not sure if someone would like to work with constructions like this: "}}]}}]}}]}]}}]}}".

JavaFX & MVC

Other thing I wanted to check is how hard it is to write some kind of MVC using JavaFX. Basically, it is possible, but it will not be "plain MVC" pattern. The designers of JavaFX did not separate code and mark-up, as it is done in Flex or Silverlite. However, it does support communication with plain Java. So, you can find a way to implement your controller in Java and connect it to your view, that is written in JavaFX. More information about writing UI controller can be found here.

What else.... Maybe testing?

If you will write your application so that UI is totally separated from business logic, then the latter can be tested with usual JUnit or some other framework. However, it is also possible to write some kind of tests for JavaFX code. They have JavaFX Unit Test base class for creating declarative, fluent, behavior-driven tests. It is also possible to use the usual way to write tests - read more here.

OK...that concerned business logic, but how to test UI?

Traditional Selenium-like tests wont help here, due to JavaFX application just embeds into your web-page, as usual Java applet. It's not integrated into DOM, so you cannot operate with its elements, to find something on page. One solution I found could be using FEST-Swing library (honestly, the "SWING" word scares me a lot:S). Basically, it is a "Java library, released under Apache 2.0 license, that provides a fluent interface for functional Swing GUI testing. This library provides an easy-to-use API that makes creation and maintenance of GUI tests easy.". In other words - the same Selenium-like framework, but for SWING applications. There you can operate with elements in the frame. Seems, that everything is OK here....but no! For some reason this library can't find JavaFX elements and components, even if they are JavaFX swing components. So basically it is not possible to test JavaFX with FEST library without additional effort. Some workarounds to this are described here:

Performance

To my mind this is the most critical issue that JavaFX has at the moment. There are a lot of blogs on the Internet you can find about it. I just want to mark some thoughts I found that might be interesting:

  • it does not support all modern browsers! For instance, simple JavaFX applets don't always work for IE and Opera. It absolutely does not work in Safary. All that after JavaFX creators said that there should not be compatibility issues with browsers, like you are facing with JavaScript.
  • Check out this blog:
    • JavaFX — 14 fps
    • Firefox + Silverlight (JavaScript) — 56 fps
    • Firefox + Flex — 62 fps
    • Adobe AIR — 62 fps
    • Firefox + Silverlight (CLR) — 99 202 fps (update: 202 fps after fixing main timer’s latency)
    • CPU Utilization: http://java.dzone.com/articles/node-count-and-javafx

There is more...

  • Bad plugin for Eclipse: no content assist(even for plain java), no formatting, no imports resolve possibility, no autocomplition, poor component base. The NetBeans plugin is much better - it has everything that Eclipse doesn't. About 90% of developers use NetBeans to write JavaFX applications according to this
  • Why JavaFX sucks http://pacoup.com/2008/12/08/why-javafx-sucks/
  • Unnecessary new syntax. Well, it is created mostly for designers, but why <> instead of != if it is Java based technology?
  • ...

Conclusion

JavaFX has a long way to go...

This is a post from my colleague Alexander Gavrilov

Posted at 02 Nov @ 10:50 AM by Ürgo Ringo | 4 Comments