Java 21
Java 21 LTS was released on time to the public. The release has been available for download since 21st September 2023.
Pattern matching is maturing nicely. The hope is that more solutions will more advanced data stream manipulation and functional programming algorithms. Complex inheritance structure are no more considered as good practices in regular application. The pattern matching extensions nicely provide idioms to solve similar design problems.
The support for virtual threads is reaching full integration in the official Java distribution. Extensions such as scoped values are available as preview feature. The tail-call optimization for recursive calls is sadly still missing.
Amber Project
The amber initiative is completing the changes with pattern matching. Start adapting your coding idioms and use pattern matching.
The visitor pattern can simply be implemented as a switch expression with pattern matching. As a bonus, the compiler will verify completeness if your class hierarchy uses sealed inheritance.
The syntactic improvements initiated by Amber and core group are;
The string template feature is worth the effort to study the provided functions. My code could be considerably simplified when using this functionality.
Loom Project
The loom initiative is completing the major changes associated with virtual threads.
-
Scoped Values Preview
-
Structured Concurrency Preview
Virtual threads are now an official part of the Java universe. Your design can create as many threads as you want without restrictions.
Most of the Java developers never create thread instances. The feature is useful for library and framework creators.
Panama Project
The panama initiative is iterating through their interfaces. They synchronize their interfaces with the Valhalla and Lilliput activities as much as possible.
-
Vector API Sixth Incubator
-
Foreign Function & Memory API Third Preview
Valhalla Project
As usual, the Valhalla initiative did not release any improvements in the current release.
It is time that value objects are proposed in the near future. The project is going for ten years.
Lilliput and Leyden Projects
The lilliput initiative aims to reduce memory usage.
Miscellaneous Improvements
Obsolete features are removed:
Extensions to existing features:
Stumbling Blocks
Once again Lombok up to version 1.18.28 is not working with JDK 21 [1]. The project uses internal unsafe functions, which are no longer supported in this Java release.
The edge snapshot release has experimental support for JDK 21. You need the following additions in your Gradle Build Tool configuration.
|
All other libraries and tools I am using worked without trouble. Major libraries test their current release with early-access and solve the problems before the official release of a new Java version.
Lessons Learnt
Gradle toolchain feature simplifies experimenting with a new Java version. The current version of Gradle Build Tool runs under Java 21.
IntelliJ IDEA provides support for newer JDK before their official release. It tremendously simplifies exploration of new features.
Often you can use the continuous integration pipelines of GitHub or GitLab platforms. No virtual machines with an experimental Java version are available.
Use different distributions to harden your code and explore alternative solutions. The Eclipse foundation temurin distribution is very nice.
Migrate all your active products to the new Java version. Invest effort to enhance source code and use the new features. So, you will avoid technical obsolesce and geriatric applications.
Links
-
[1] Java 20. Marcel Baumann. 2022.
-
[2] Vaadin. Marcel Baumann. 2022.
-
[3] Java 17. Marcel Baumann. 2021.
-
[4] Java 16. Marcel Baumann. 2021.
-
[5] Java 10 aka 18.3 Changes. Marcel Baumann. 2018.
-
[6] Immutability in Java. Marcel Baumann. 2022.
-
[7] Modern Java Constructs. Marcel Baumann. 2022
-
[8] Modern Java Development. Marcel Baumann. 2021.