WordPress Ad Banner

Java Development Kit 22 Unveils Exciting Features: A Comprehensive Overview


The upcoming Java Development Kit 22, expected to launch in March 2024 as the next version of Java Standard Edition, incorporates eight new features. Among these, a preview of the class-file API, region pinning for the G1 garbage collector, and a second preview of implicitly declared classes and instance methods have been recently introduced.

A potential ninth feature, stream gatherers, is tentatively slated for JDK 22 but is not officially listed on the OpenJDK web page as of November 20.

WordPress Ad Banner

The latest additions join a lineup that includes a preview of statements before super(…), a second preview of string templates, unnamed variables and patterns, a foreign function and memory API, and the seventh incubator of a vector API. Early-access builds for JDK 22 are accessible for Linux, Windows, and Mac at jdk.java.net.

The class-file API, a preview feature, aims to provide a standard API for parsing, generating, and transforming Java class files. The goal is to facilitate the migration of JDK components to this standard API, ultimately eliminating the need for the JDK’s internal copy of the third-party ASM library. This move addresses the challenge posed by the rapid evolution of the Java class-file format due to the six-month release cadence, ensuring frameworks can keep pace with the format changes.

Region pinning for the G1 garbage collector focuses on reducing latency during Java Native Interface (JNI) critical regions. The objective is to prevent the need to disable garbage collection during these critical regions, avoiding thread stalling and minimizing regressions in garbage collection pause times.

Implicitly declared classes and instance methods, currently in preview in JDK 21, are undergoing changes and a second preview in JDK 22. This feature aims to simplify the Java language for beginners, allowing them to write streamlined declarations for single-class programs and gradually incorporate more advanced features as their skills progress.

Stream gatherers, a preview feature in JDK 22, seeks to enhance Java’s Stream API by supporting custom intermediate operations. This aims to make stream pipelines more flexible and expressive, allowing manipulation of data in ways not easily achievable with existing built-in operations.

The preview of statements before super(…) addresses constructors, permitting statements unrelated to the instance being created to appear before an explicit constructor. This provides developers with greater flexibility in expressing constructor behavior while maintaining the order of class instantiation.

String templates, in a second preview in JDK 22, complement Java’s existing string literals and text blocks by incorporating expressions and template processors. This enhances program readability, simplifies the writing of dynamic strings, and improves security by supporting validation and transformation of template expressions.

The seventh incubator, a vector API, enables vector computations in Java, reliably compiling to optimal vector instructions on supported CPU architectures. It aims for clarity, platform-agnosticism, and reliable runtime compilation and performance.

Unnamed variables and patterns, previewed in JDK 21, capture developer intent by allowing unused variable declarations or nested patterns. This improves code maintainability and readability.

The foreign function and memory API, previously previewed in JDK 19, JDK 20, and JDK 21, allows Java programs to interoperate with code and data outside the Java runtime, eliminating the brittleness of JNI.

Scheduled for release on March 19, 2024, JDK 22 is a Feature release with six months of support from Oracle. It will not be a Long Term Support (LTS) release like JDK 21. JDK updates occur every six months, with LTS releases every two years. Upcoming capabilities for JDK 22 may include structured concurrency and computed constants. The release is set to go through rampdown phases in December and January, followed by two release candidates in February 2024.