JavaFX vs HTML5

By JavaFX vs HTML5

Choosing a rich client technology is very challenging! Particularly when these technologies are competing to be a leader in their area. In this case we have JavaFX and HTML5. I have done some projects and in both JavaFX and HTML5 for some companies. In this article I would like to share some of my insights on this topic.

This article does not intend be a battle between JavaFX and HTML5 by making one win over the other. Choosing either of the two actually depends on your situation. This article can provide you with some criteria to keep in mind when making a choice for your project.

Target Audience

A question worth answering for a Java Developer is if they should adopt JavaFX for their next user interface app or make the switch to an HTML5 technology. I know and love both technologies and I've been using JavaFX since early 2017. Lately I've mostly been programming web applications and will continue to do so in the coming months.

This article is about rich client applications with a lot of interactive elements.

Comparison Factors

Whenever we lay down differences between two technologies, we must agree upon a set of criteria which we will use to compare said technologies. Some of them include:

  1. Richness
  2. Support for different screen sizes
  3. Long-term support
  4. Learning Curve for the technology
  5. Rolling Replacement
  6. Deployment
  7. Recommendations

1. Richness and Aesthetics of UI

  • JavaFX comes with a decent default theme called Modenawhich is easily customisable with CSS. With HTML5, clearly everything is possible.
  • With JavaFX, we get the excellent ControlsFXproject and also JFXtras which provides complex widgets, something that is a little difficult to find in HTML5.
  • JavaFX also comes with a nice visual designer called JavaFX Scene Builder and we have various tools for HTML5 which are categorised as drag and drop tools.
  • HTML5 can target almost all browsers and all possible screen sizes. This is good but it is also very complex to implement one clean solution that works everywhere.

Since JavaFX mainly targets the desktop and HTML5 all possible screen sizes, it is not really fair to compare the two in terms of richness and aesthetics of UI.

With JavaFX you will not have to think a lot about UI widgets and interactions. You get everything out of the box. So, if you’re implementing a larger business application you will certainly get nice results much faster and easier with JavaFX.

2. Support for Mobiles and Tablets

  • JavaFX is mainly for Desktop use. JavaFX for Android/iOS is a community effort. There is currently no official support by Oracle
  • Targetting mobile and desktop browsers there is no limit for HTML5. But to create a larger application that works accross many different screen sizes is everything but trivial both from a design and from a technical perspective.

Obviously, HTML5 is the winner here.

I haven’t tried any of the JavaFX ports for mobile but from what I’ve seen they don’t seem to be production ready, yet. Through community effort this might change in the near future and could actually be usable. So, definitely create some prototype to see if you can use it.

3.Learning Curve

When you're a Java programmer and you've created some Swing GUIs, learning JavaFX will be simple but worth your time. As a Java Swing developer, the new possibilities JavaFX offers will excite you.

With JavaFX, we get all of the Java 8 features and more, such as:

  • Separating the presentation layer with FXML and SceneBuilder. It is also possible to make JavaFX apps completely in Java, without FXML.
  • Using the new Properties classes and ObservableLists for automatic UI updates.
  • Working with the TableView.
  • Using custom CSS for styling.
  • Create custom charts.

For a Java developer it is quite difficult to make the switch to HTML5. I know because I've gone that route and it has taken me more than two years to really feel comfortable with the web platform and the various web technologies.

Here are some reasons that make it difficult for experienced Java developers to learn HTML5:

  • Many browsers with differing behaviors (Chrome, Firefox, Safari, mobile Safari, different versions of Internet Explorer, etc.)
  • Must learn HTML: This is the easiest part.
  • Must learn CSS: Not too hard to understand the general concepts but very difficult to work with in larger projects. It gets you in a big mess if not done right (no encapsulation!). And making the styles work across many browsers is a great challenge. You’ll end up using some CSS pre-processor like SASS or LESS which adds one more thing you need to learn.
  • Must learn JavaScript (there are alternatives though):
  • No static types: This is difficult to grasp for a Java developer.
  • Tool support: Because there are no static types the IDE can’t help you much with content assists.
  • No real classes: Prototype-based programming.
  • JavaScript oddities: A lot has been said about that.
  • You will end up using a framework or two which is yet another thing to learn.
  • JavaScript itself is ok, but difficult to get right.

It takes quite some time but it is possible for Java developers to make the switch to HTML5 if they are excited about learning new web technologies.

But it will be really difficult for inexperienced web developers to create a well architected and maintainable project.

For Java developers it is quite a large step until they will be able to design reasonable web applications. Migrating a larger Swing application to HTML5 without being an experienced web developers would entail a significant risk of failure.

JavaFX is the obvious winner concerning the learning curve if your primary background is in a non-web language like Java or C#. If you're already comfortable with web technologies or you're excited to learn something new I recommend you give Dart a try.

4. Long-term Support

Let us list the long term support received by each community separately.

JavaFX

  • JavaFX is now part of JRE/JDK for Java 8.
  • Oracle say that JavaFX replaces Swing as the new client UI library.
  • Java is huge and when used on the client, JavaFX is now the default.
  • JavaFX is open source.

HTML5

  • HTML5 is here to stay. But for a business application of significant size you will need to rely on third-party frameworks, tools and maybe even languages.
  • The lifecycle of web frameworks and tools can be quite short. When relying on many third-party libraries and tools you will need to track all the changes and you can only hope that support and updates will continue.

I believe Java will still be with us for quite some time to come. With JavaFX you get almost everything you need for your UI from one single source and you know you can rely on it to stay stable for quite a while. Since JavaFX is open source this at least gives you some confidence that an open source community could provide support even if Oracle wouldn't.

5. Deployment

The promise of Java is "write once, run anywhere". But we've all had problems with deployment of Java programs because the user didn't have the expected Java runtime version.

Deploying web applications only requires a web server that users can access with their browsers. This also makes it very easy to distribute updates.

HTML5 is the winner in terms of deployment even though JavaFX provides a better solution than before with its native packaging.

6. Recommendations

All criteria are relevant but I think there are two that might be relevant for most applications: Learning Curve and Options for Mobile and Tablet.

The Learning Curve depends on your team: How high is the team's motivation to learn web technologies? Do you have any web developers with experience in architecting complex web applications?

If the project is large and your team has limited experience in web technologies I'd consider HTML5 as quite risky. JavaFX might be the safer choice.

Was this article helpful?

Bessy
Eric Murithi Muchenah

Life is beautiful, time is precious. Make the most out of it.

Never miss an Article from this Blog

Get Programming and Technology Tips for Beginners by subscribing now.