Java 21

2023 09 02 head

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 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.

Virtual threads are now 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 directly thread instances. The feature is useful for library and framework creators.

Panama Project

The panama initiative is iterating through their interfaces. They synchronize as much as possible their interfaces with the Valhalla and Lilliput activities.

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.

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 more 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.

  • add the repository maven { url "" }

  • use the dependency org.projectlombok:lombok:edge-SNAPSHOT for the library and the annotation processor

All other libraries and tools I am using worked without troubles. 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 IDE 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.

1. Version 1.18.30 was released in 2023-09-20 and provides initial support for JDK 21. Late but it still saves the day.