Close

JDK 23: Fresh Innovations in Java 23

Expected to launch in September, Java 23 brings forth a range of novel elements including previews of module import declarations, stream gatherers, and integration of primitive types within patterns, instanceof statements, and switch constructs.

The lineup of proposed features for Java Development Kit (JDK) 23, the upcoming iteration of standard Java, has expanded to eight. A recent addition includes a third preview unveiling implicitly declared classes and instance main methods, tailored to simplify Java for novices.

Set for release on September 17, JDK 23 introduces a vector API, undergoing its eighth incubation phase, a second preview of stream gatherers, a repeated look at a class-file API, and a peek into primitive types within patterns, instanceof statements, and switch constructs. Additionally, there are new features like module import declarations, Markdown documentation comments, and a transition of the Z Garbage Collector to generational mode as the default. Early access builds for JDK 23 are available on jdk.java.net.

Previously showcased in JDK 21 and JDK 22, implicitly declared classes and instance methods aim to streamline the Java syntax, facilitating beginners to initiate programming without delving into intricate language features. In JDK 23, enhancements include automatic import of three static methods for basic text I/O and on-demand importation of all public top-level classes and interfaces from packages exported by the java.base module.

The module import declarations, slated for preview in JDK 23, enhance Java’s functionality by enabling concise import of all packages from a module. This proposal simplifies the usage of modular libraries without necessitating them to be within a module. The objective is to streamline the integration of modular libraries by allowing the importation of entire modules at once, thus reducing clutter and aiding beginners in accessing third-party libraries and fundamental Java classes seamlessly.

Markdown documentation comments, conceived in September, propose to allow JavaDoc documentation comments to be composed in Markdown alongside HTML and JavaDoc @tags, simplifying their readability and writing process. This change aims to extend the Compiler Tree API to accommodate Markdown content, without altering the interpretation of existing documentation comments.

Another significant change in JDK 23 is the transition of the Z Garbage Collector’s default mode to the generational mode, aiming to enhance Java application performance by prioritizing the collection of young objects. This move signals a shift towards focusing on generational ZGC, aimed at reducing maintenance costs associated with supporting multiple modes.

The vector API, incubated since JDK 16, introduces a platform-agnostic API for expressing vector computations that compile optimally on supported CPU architectures. This proposal aligns with Project Valhalla’s goals to augment Java’s object model with value objects, ensuring reliable runtime compilation and performance across architectures.

Stream gatherers, previewed in JDK 22, enhance the stream API by supporting custom intermediate operations, thereby enhancing flexibility and expressiveness in stream pipelines. Similarly, the class-file API aims to provide a standardized interface for processing class files, enabling JDK components to migrate to a standard API and eliminate the need for third-party libraries like ASM.

Additionally, JDK 23 introduces primitive types in patterns, instanceof statements, and switch constructs, allowing for more robust pattern matching with primitive types, further aligning instanceof with safe casting and extending pattern matching capabilities.

Several other features from JDK 22 might also find their way into JDK 23, such as statements preceding super(…), string templates for dynamic string composition, scoped values for sharing immutable data, derived record creation, and proposals like hot code heap, designed to improve application execution times.

Looking ahead, Oracle has outlined its plans for Java in 2024, aiming to enhance various OpenJDK projects including Amber for smaller, productivity-oriented features, Babylon for extending Java to foreign programming models like GPUs, and Valhalla for optimizing Java’s object model with value objects to eliminate performance bottlenecks.