

Learn from Java Champion Johan Vos: JavaFx in the Age of Browsers
In our new Java Monthly edition, we’d like to introduce you to Johan Vos. He was kind enough to share his experience on 8 Java-related questions.
Johan Vos started to work with Java in 1995. He was part of the Blackdown team, porting Java to Linux. In 2015, he co-founded Gluon, a company enabling the mobile/embedded Java enterprise. Johan is a Java Champion and member of the Devoxx steering group. He is one of the authors of the Pro JavaFX books, the author of Quantum Computing for Developers, and he has been a speaker at numerous conferences. He and Gluon received a Duke Choice award in 2014 and 2015. He contributes to a number of projects, including OpenJFX, OpenJDK, GraalVM. He is the project lead for OpenJDK Mobile and the co-lead for OpenJFX.
Java Monthly: In an age where browser based applications are dominating, how do you see the future of desktop applications? What is their biggest strength?
Johan Vos: Web browsers make it very easy to provide content and basic functionality to end users. That serves many use cases, and it’s great.
But for more complex functionality, and for content or applications that have strong security or privacy requirements, a web browser is not always the best container. In this area, Java provides the required basic infrastructure, including built-in security at different levels, maturity, scalability etc. With JavaFX being the de facto standard for UI applications in Java, it is also very easy for Java developers to create user interfaces that allow for very complex interactions.
Note: As of recently, there is basic support for deploying JavaFX applications inside a web browser. Check out this link.
Java Monthly: Are there non-obvious scenarios where you think desktop applications are currently being neglected?
Johan Vos: In the IT industry, there has always been a moving balance between thin clients and fat clients. Many models either go for a completely thin client or for a full fat client. Reality is often more nuanced and hybrid. Data storage is typically happening in clouds, but processing happens both locally and in the cloud.
An example of this, in the AI world, is Federated Learning. Typically, a model is created and stored in a cloud instance, and clients download that model to make predictions etc. In order to improve the model, data is then sent from clients to the cloud, where the model is retrained. This often leads to privacy and legal issues: it is not always allowed or desired to upload data to cloud systems without consent of the people involved.
But today’s end-user devices (laptops, phones or embedded devices) are powerful enough to do at least some model training, and instead of sending the raw data, they can send the delta of the model to the cloud — which does not contain private data anymore.
In this case, it is a major win if the cloud software and the client software is similar. We have some POC’s that show how a model can be retrained by a combination of clients and cloud instances, all running the same Java software.
Java Monthly: What changed when JavaFX was separated from the JDK? Did it help its growth?
Johan Vos: Actually, JavaFX actually was never part of the JDK. That is, the OpenJDK project never included the OpenJFX code. The OpenJFX project is, and has been since very long, a separate project in the OpenJDK organisation.
What most people refer to when they talk about this subject, is the fact that one particular company (Oracle) used to bundle JavaFX binaries with their distribution of the JDK, and they decided to remove that.
From a technical point, this was a great thing to do. The core JDK is a crucial component in many projects and technologies, and its focus should really be on the core of Java itself. While UI frameworks or libraries are very important to many applications, not all Java applications require a UI. Hence, it would make the core bigger, and the management of the JDK more complex.
Also, as a separate project, JavaFX has much more flexibility then when it would be part of the core JDK.
From a communication point, though, the “separation” was much worse. Many developers and companies felt there was no clear communication or explanation. That did cost lots of goodwill, and it took years to regain the trust from the community.
From a technical point, the “separation” caused growth, as more developers joined the process. The communication debacle (or the lack of communication) was a major challenge for this growth, but we’re now at the point where most companies and developers realise that the fact that one company for some reasons changed their bundling approach does not mean that JavaFX is in bad health.
Java Monthly: How do you implement DI in JFX? Do you do it with the built-in service locator or with a library like Spring? If the approach is with java.util.ServiceLoader, does it go in the direction of modularisation of the project so that each module can communicate through its open interfaces?
Johan Vos: That’s a great question, I get asked about this often. Since JavaFX purely relies on the core JDK API’s, there is nothing that forces developers in one or another direction. We see projects using Spring, and other projects using the ServiceLoader concept, or combinations. Any DI framework that can be used in Java can be used in JavaFX. With Gluon, we have an abstraction for DI frameworks called Gluon Ignite, and we provide examples for e.g. Spring and Micronaut. But there is really no limitation, and developers can use the DI frameworks they are familiar with.
Having said that, we see a tendency towards the bundling of Java applications into a single executable (e.g. leveraging an AOT compiler). This is particularly interesting for client applications in environments without a JVM installed.
Java Monthly: Do you use Jpackage or Jlink to build an executable file that carries everything in it or a minimal one that needs Java, DB, etc.?
Johan Vos: Yes, that is one of the reasons why Java client applications today are easier to use than e.g. 10 years ago. With jpackage (and jlink under the hood), it’s easy to create installers that contain everything that is needed to run the application. End-users are familiar with this approach, and they don’t have to install and maintain a JVM first, or configure a local database. This drastically lowers the barrier for installing and using Java and JavaFX applications on the client.
Going one step further, thanks to AOT compilers and e.g. GraalVM native-image, it is not even required to bundle a JVM with the application. This is where Gluon Substrate comes in the picture: it combines the bytecode containing a specific application with the bytecode and native code of all dependencies, and compiles that (using GraalVM native-image) into a native executable for a specific platform, including Windows, Mac, Linux, iOS, Android, ARM devices (e.g. Raspberry Pi).
Java Monthly: Which are the best resources that you would suggest for people going into the JavaFX world?
Johan Vos: Since JavaFX provides a number of Java API’s, the basic resources for Java are applicable to JavaFX as well. The starting point for JavaFX is https://openjfx.io which contains links to the latest releases, release notes, API documentation, and the getting started tutorials. A cool initiative from Dirk Lemmermann is https://www.jfx-central.com/home . This website, written in JavaFX, contains a number of links to projects and libraries.
Great code snippets are also available from Gerrit Grunwald, at https://harmoniccode.blogspot.com/.
Java Monthly: What is the best open source project that can be used as an easy entry and good showcase of JavaFX capabilities? Which are its definitive features?
Johan Vos: If you want to combine learning with gaming, I highly recommend FXGL from Almas Baimagambetov. FXGL is a game engine leveraging JavaFX, and it allows developers to easily create games in Java. There are many examples, ranging from simple games to very complex games, so it is a great tool to get familiar with the concepts of JavFX.
Java Monthly: What are your favourite places to get your programming news from?
Johan Vos: Foojay.io is a relatively young, new platform that contains news and information related to Java, and many Java experts contribute to Foojay.io.
Is there anything else you would like to ask Johan Vos? What is your opinion on the questions asked? Who would you like to see featured next? Let’s give back to the Java community together!