In our new Java Monthly edition, we’d like to introduce you to Gail Anderson. She was kind enough to share her experience on 12 more Java-related questions.
Gail Anderson is the Director of Research and founding member of the Anderson Software Group, a leading provider of training courses in Java, JavaFX, Python, Go, Modern C++, and Docker and Kubernetes. She is a Java Champion and the co-author of nine textbooks on software programming, including “The Definitive Guide to Modern Java Clients with JavaFX”. Gail also contributed to the book “97 Things Every Java Programmer Should Know!”. Her current passion includes JavaFX with GraalVM for cross-platform mobile applications.
Web site: asgteach.com
Dreamix: Use of mobile and web applications have been spiking up for the past few years. Where do you see the future of desktop applications? What are their pros & cons?
Gail Anderson: Desktop applications will continue to fulfill an important use case: they run on a host computer without the need of an internet connection.
Pros: Desktop applications provide
– better security and privacy (e.g., communication and data security),
– complex functionality (e.g., IDEs, word processors, image editors, illustration tools, complex document processors),
– a single executable with an installer (e.g., using jpackage),
– execution speed that is not dependent on an internet connection.
Cons: Desktop applications must be downloaded and installed. They are not usually free. They must be updated (this applies to mobile apps as well).
Dreamix: What did JavaFX improve compared to Swing?
Gail Anderson: There are so many nice JavaFX features! Here are a few:
– JavaFX supports hardware-accelerated graphics (2D and 3D)
– Clean Java API
– CSS Styling, which provides a nice separation of styling from underlying component code
– Easy-to-use animation
– Observable properties and binding – great for keeping UI/UX consistent
– Nice concurrency API for managing long-running background tasks that update/affect UI
– Hierarchical scene graph – makes manipulating components easy because they can be grouped and configured
– Declarative FXML for composing a UI, plus a drag-and-drop desktop application called Scene Builder that produces FXML
– Creates a separation between view and controller code
– Truly cross-platform, including Windows, Mac OS, Linux, iOS, Android, and embedded
– OpenJFX is a well-supported project that is being constantly improved and enhanced. (Swing is only being maintained, not improved.)
Dreamix: Why was JavaFX excluded from JDK? What was the main effect?
Gail Anderson: Are we still asking this question?
JavaFX was never part of OpenJDK, but Oracle at one point bundled JavaFX binaries with their distribution of the JDK. This change was poorly understood and thus it created confusion for developers and companies.
However, the separation allows JavaFX to develop separately and not depend on the Java release cycle. JavaFX is currently a well-supported open source project (OpenJFX) lead by Gluon. In fact, JavaFX 19 is on track for release in September.
Furthermore, with the Java module system, you can include only the JavaFX/Java modules that you need, resulting in smaller executable images.
Dreamix: What do you think about the embedded application areas for JavaFX?
Gail Anderson: It appears to me that Gluon and others are putting quite a bit of effort into supporting embedded targets. JavaFX applications can run on JVM for ARM devices (32/64 bits) and, additionally, you can create native images for AArch64. The native image support includes Gluon Substrate with ahead of time compilation using the GraalVM native image builds. With built-in Wi-Fi and Bluetooth, Raspberry Pi’s are versatile computing devices
Dreamix: Would you recommend FXGL to the game developers?
Gail Anderson: Absolutely. FXGL is well-maintained and since it is JavaFX, you can target desktop, embedded, and mobile devices. You can read more about it here: https://github.com/AlmasB/FXGL. The reference includes several tutorials to get you started. Disclaimer: I haven’t developed a game using FXGL myself (but I would . . . )
Dreamix: Which IDE do you use for JavaFX development?
Gail Anderson: JavaFX projects are generally maven-based, making them portable among IDEs. I use either IntelliJ or Apache NetBeans. I have used both, but prefer Apache NetBeans since I am most familiar with it.
Dreamix: How do you implement DI in JavaFX?
Gail Anderson: Conveniently, Gluon has an abstraction for DI frameworks called Gluon Ignite, which I have used with Spring Boot. It works well. Gluon Ignite supports Guice, Micronaut, Spring, Spring Boot, and Dagger.
Furthermore, with Gluon Ignite, you can use DI with FXML controllers. This is important because the FXML Loader itself builds and injects FXML objects accessible from the controller code.
Gluon Ignite supports JSR-330 (Dependency Injection for Java).
Dreamix: Are there any popular companies which have adopted JavaFX? Why did they adopt it?
Gail Anderson: I’m not privy to adoption decisions, but I would imagine that JavaFX adoption would be influenced by the privacy and security features of Java and the superior 2D and 3D graphics available with JavaFX. For example, Sean Phillips (@SeanMiPhillips) has been recognized for his work on the Deep Space Trajectory project a few years ago (here is a short video description: https://www.youtube.com/watch?v=WO34EkYPPpc). This product created at AI Solutions has been used by NASA and leverages the enhanced JavaFX graphics capabilities and raw drawing of canvas.
More recently, Sean has uploaded an example application showing JavaFX 3D visualization: https://www.youtube.com/watch?v=ax7bvAcPI8c.
The U.S. Navy has adopted JavaFX for some projects. I presume their interest lies in the long list of advantages JavaFX provides, as well as the privacy and security provided by Java.
Dreamix: Is JavaFX truly write once and run everywhere? Can you port JavaFX applications easily on Android and iOS?
Gail Anderson: Yes, JavaFX is truly write once run everywhere. However, you have to accept that some targets may not be acceptable for a given application due to factors that have nothing to do with Java or JavaFX.
For example, I created a simple Tilt Maze game that is available in both the Apple App Store (iOS) and Google Play (Android). It uses the exact same Java/JavaFX source code for both targets. However, it does not run on a desktop because the program relies on the device’s accelerometer to manipulate the game.
That being said, I coded and debugged a large part of the game on the desktop due to the desktop’s quick edit-compile-run cycle, mocking a substitute behavior for the non-existent accelerometer.
Note that the form factor among desktop, tablet, and mobile devices are enough different that even for the simplest application, there may be changes to the UI. Fortunately, JavaFX has FXML, CSS, and Scene Builder to help developers keep the view and controller separate.
While Java and JavaFX are truly write once run everywhere, you will encounter a myriad of “configuration” differences between Android and iOS targets. The respective stores have their own guidelines and steps for submitting apps and signing them. But, with Gluon Substrate, GraalVM, and JavaFX, you can create native images for both targets from the same Java/JavaFX source. Furthermore, the native images (ahead of time compilation) provide fast startup times, reduced image size, and fast execution. It is truly a brave new world for JavaFX mobile application development.
Dreamix: What resources would you recommend for the readers who want to start learning JavaFX?
– The Definitive Guide to Modern Java Clients with JavaFX 17: Cross-Platform Mobile and Cloud Development 2nd ed. Edition (I am a contributor.)
– Online JavaFX tutorials by Jakob Jenkov: https://jenkov.com/tutorials/javafx/index.html
– Get started creating your own project: https://start.gluon.io/
– Beware of online JavaFX sources that are out-of-date!
Dreamix: How do you update yourself about the latest trends in Java?
– gluonhq.com site for news on new JavaFX releases, support targets, and long-term support options for JavaFX. (For example, Gluon just published an article announcing a new JavaFX rich text control, RichTextArea.)
– Several people and companies in the JavaFX world that are active: Gluonhq.com (@GluonHQ), Johan Vos (@johanvos), José Pereda (@JPeredaDnr), Almas Baim (@AlmasBaim) Zoran Sevarac (@zsevarac), Sean Phillips (@SeanMiPhillips). There are many more.
– Foojay.io (https://foojay.io): provides updates on new Java features and releases as well as JavaFX topics. [Friends Of OpenJDK, so the material is broadly sourced within the greater Java community.]
Dreamix: Can you recommend a favorite book about programming? What about a favorite book in general?
– UML Distilled Third Edition: A Brief Guide to the Standard Object Modeling Language by Martin Fowler: this classic is a great example of a concise and readable book on an involved topic.
– In general, I enjoy reading fiction. Anything by Haruki Murakami will be a lyrical and poignant read on human joy and love, sorrow and pain. In particular, The Wind-Up Bird Chronicle and Norwegian Wood are favorites.
– Most recently I’m reading Great Circle by Maggie Shipstead, an empowering story of a fictional female aviator attempting to circumnavigate the globe in 1950 following the line of a great circle (here, a path intersecting both north and south poles).
Is there anything else you would like to ask Gail Anderson? 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!