About Christian Horsdal

Independent Consultant helping clients architect and develop real world solutions. Typically, but not always, based on the broader Microsoft ecosystem.

XAML or JavaFx?

This a quick, subjective, unauthorative and very non-scientific comparison of building applications with XAML and with JavaFx. The comparison is based on my personal experience working with each. On the XAML side this means WPF and Win8 store apps. On the JavaFx side this means a Windows 7 application.
 
 
 
 
 
 
 

JavaFx

JavaFx is touted by Oracle (and Sun back in the day) as new and modern way to build UIs. It’s focused on supporting the flexibility and graphical niceness that modern UIs demand. JavaFx can run in and out of browser, and on various OSs.

My experience with JavaFx is building a good looking and quite modern desktop application targeting only Windows 7. We opted for writting the view code in ScalaFx, a declarative JavaFx DSL in Scala. This works fine: The application looks good, performs fine, and the code base is pretty clean. But there are few things bothering me:

  • The UI code is just not as declarative as I would have liked. In general we’ve found that the built-in controls do not suit our needs, so most of the UI is build from .pngs, that have mouse events attached to them. These events change the .pngs around for hover, clicked and so on. While this works just fine, it means that there is more logic in the views than I’d have liked.
  • In part as a consequence of the above, it’s hard to create something like a XAML datatemplate and then bind the data into it. Again this results in more imperative logic in the views.

The things I really like are:

  • The fact that we can use Scala in the views really cuts down on the amount of noise in the view code, compared to Java counterparts, in my opinion. For instance attaching the mouse event handlers is a lot easier with a language where functions are first class citizens.
  • It’s fairly easy to run the view code in headless mode from tests. This enables a decent albeit slightly slow TDD workflow for the view code.

XAML

XAML is used in a range of Microsofts UI technologies including WPF and the Win8 store app (formerly Metro) and Silverlight. The XAML UI frameworks are also focused on supporting the needs of moderns UIs, and also runs both in and out of browser.

My experience with XAML is from WPF and Win8 store apps, where we’ve followed the MVVM approach without any particular framework, but with some homegrown conventions inspired by Caliburn.Micro to ease some of the repetition in XAML – particularly around binding.

This has also worked out well, resulting in nice applications, but again there are some things that bother me:

  • First and foremost I detest writing code in XML. So I’m not a fan of the XAML language at all. You might, at this point, say that XAML is meant to be generated by tools, not written by humans. And you may be right. Nonetheless, my experience is that you do write most of your XAML by hand. I find doing that to be much quicker and more maintainable than using Blend or Visual Studio to edit XAML.
  • I don’t like the code behinds. We’ve kept them quite small in the projects I’ve worked on, but they are still there tempting developers at weak moments to hide untestable code.

The things I really like are:

  • As with JavaFx it’s fairly simple to run the views headlessly for testing. Again this enables an acceptable TDD workflow. Again albeit somewhat slow.
  • Databinding works very well. Especially with some conventions in place to cut down on boilerplate code.
  • Datatemplates in particular enable keeping the views declarative.

Conclusion?

Hmm, I don’t think I have enough data here to conclude much. What I will conclude though is that for building Windows applications my experience is that both JavaFx and XAML will get the job done, but it’s faster to work with XAML, because the databinding is easier, the datatemplates help a lot and there seems to be less hand rolling controls.

Beware though: The projects I’m comparing are not the same, so there is a certain level of comparing apples and oragnes going on. Also this very subjective. So YMMV.

Update – 2012-12-21

Based on feedback I’ve decided the conclusion above is too vague. To clarify: In my experience both technologies work, but XAML is faster (and thus cheaper, and faster to market) to work with.
 

Reference: XAML or JavaFx? from our JCG partner Christian Horsdal at the Horsdal blog.

Related Whitepaper:

Java Essential Training

Author David Gassner explores Java SE (Standard Edition), the language used to build mobile apps for Android devices, enterprise server applications, and more!

The course demonstrates how to install both Java and the Eclipse IDE and dives into the particulars of programming. The course also explains the fundamentals of Java, from creating simple variables, assigning values, and declaring methods to working with strings, arrays, and subclasses; reading and writing to text files; and implementing object oriented programming concepts. Exercise files are included with the course.

Get it Now!  

3 Responses to "XAML or JavaFx?"

  1. Carlos says:

    XAML also means Windows 7…or even Vista. When you say “XAML is faster (and thus cheaper…)”, I think we have a problem. It can be faster, but cheaper not really. Visual Studio, Blend and some of WPF good looking controls are not free neither cheaper. I don’t know JavaFx, but I think the IDE and some other tools are free…

    • HighCore says:

      Carlos: Why do the java guys alway bring the same stupid argument about supposedly not free tools?? Don’t want to pay for Visual Studio?? Use Visual Studio Express!!!! ITS FREE… and of course it supports WPF. Don’t like Visual Studio because it’s not “open source”…. Use SharpDevelop…. can’t you see your argument is completely irrelevant??

    • publicENEMY says:

      The os is not free. The tools are not free. But doesnt mean cost of development is cheaper for other free alternatives. Tools and os are not the only thing thats cost in any development. Other things like expertise, manpower, timeline do costs. Product quality also matters as it related to how much sales you get. Im not saying microsoft platform is greater than java or anything like that(nothing is perfect), but i detest people who only factored in the cost of ide and os in to make their judgement.

Leave a Reply


two + 8 =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

15,153 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books