One of the really awesome things about Java is its forward compatibility. This means that existing Java code can benefit from language features that didn't even exist when the code was written. This applies on two different levels - first, there are the fully automatic cases where, e.g., improvements to the JIT compiler or garbage collector make your existing code run faster. There's also an intermediate kind where you can use new language features when you write new code, even though that code interacts with existing code that doesn't directly support those new features.
Every new Java release brings some new features that you can start using right away, as well as other features that we at Vaadin might use in the future for architectural decisions or API design once the latest Vaadin version can use that Java version. Vaadin 24 remains compatible with Java 17, and the same goes for Vaadin 25, which we will release by the end of this year. But we also ensure compatibility with newer Java versions, so you can start using Java 24 today with any supported Vaadin version back to at least Vaadin 14.
Let's see what Java 24 brings to the table, specifically in the context of Vaadin applications!
The unrelated
Some new Java features don't directly relate to what Vaadin does or how it's typically used. First, there are a bunch of JEPs related to removing or deprecating old functionality to ensure Java can remain successful in the future.
- Remove the Windows 32-bit x86 Port
- Deprecate the 32-bit x86 Port for Removal
- Permanently Disable the Security Manager
- ZGC: Remove the Non-Generational Mode
- Prepare to Restrict the Use of JNI
- Warn upon Use of Memory-Access Methods in sun.misc.Unsafe
Next, Java 24 introduces new cryptography features. Vaadin doesn't directly use this kind of functionality even though it might be indirectly used through, e.g., the servlet container.
- Key Derivation Function API (Preview)
- Quantum-Resistant Module-Lattice-Based Key Encapsulation Mechanism
- Quantum-Resistant Module-Lattice-Based Digital Signature Algorithm
Finally, there are some generic new features that just aren't very relevant for typical Vaadin applications.
- Vector API (Ninth Incubator) is more about number crunching, which is typically not relevant in web applications.
- Simple Source Files and Instance Main Methods (Fourth Preview) help for simple cases and when teaching Java but might not be useful for sophisticated enterprise applications.
- Synchronize Virtual Threads without Pinning does not affect Vaadin since we're using ReentrantLock for the main synchronization and the synchronized keyword only in some specific cases that would otherwise not be affected by pinning.
- Linking Run-Time Images without JMODs could be useful in some very specific cloud deployment cases but doesn't directly impact Vaadin use.
The directly usable
My list of improvements that you can benefit from right away starts with various performance improvements. In addition to these main features described in JEPs, there are also many other smaller performance improvements in Java 24.
- Generational Shenandoah (Experimental)
- Late Barrier Expansion for G1
- Compact Object Headers (Experimental)
- Ahead-of-Time Class Loading & Linking
These changes can improve the performance of existing applications without any code changes. Using the AOT cache improved startup time by 6% for my simple test application, whereas compact object headers resulted in a 17% reduction in memory use per user session.
Next are some generic language and library features that can be useful for any kind of application, including those that use Vaadin. You can start using these right away in your application code without requiring any changes in Vaadin.
- Stream Gatherers
- Primitive Types in Patterns, instanceof, and switch (Second Preview)
- Flexible Constructor Bodies (Third Preview)
- Module Import Declarations (Second Preview)
- Structured Concurrency (Fourth Preview)
The design opportunities
Finally, here are some JEPs that I find interesting with my product architect hat on, especially when thinking about future improvements we could make to Vaadin. At the same time, I realize that we cannot use these until some undefined future version that no longer needs to work with older Java versions.
- Class-File API should make it easier for us to support newer Java versions. Today, we need to wait until various 3rd party libraries are updated before we can enable support. If all those libraries, along with the class analysis done directly by Vaadin, would use this new API, then new Java versions could be automatically compatible in many cases and require minimal effort in the remaining cases.
- Scoped Values (Fourth Preview) could, in the future, replace the use of
ThreadLocal
, for, e.g.,UI.getCurrent()
. This should give some performance improvements, make our implementation easier to understand, and reduce the risk of accidentally leaking references. - Module Import Declarations (Second Preview) could be useful for Vaadin APIs. The challenge is that we might have to change our code structure to use Java's module system to benefit from this feature, so it's not certain we will actually do this.
- Structured Concurrency (Fourth Preview) could potentially be supplemented with Vaadin-specific APIs for integrating with
UI.access
.
The summary
As you can see, any new Java version has a wide variety of improvements. You can start benefitting from most of them right away just by updating the Java version you're using. Out of the changes in Java 24, I'm most excited about the compact object headers since memory use is often a concern for Vaadin users, and this change seems to be a very nice improvement in that regard.
Which change are you most excited about? Share it in the comments!