Java 23, set to be released in September, will introduce several new features, including previews of module import declarations, stream gatherers, structured concurrency, and flexible constructor bodies.
The upcoming Java Development Kit (JDK) 23, the latest version of standard Java, will feature 11 proposed enhancements. Recent additions to this list include previews of structured concurrency and flexible constructor bodies, along with the planned deprecation of memory access methods in sun.misc.UnSafe for future removal.
Scheduled for release on September 17, JDK 23 will also feature a vector API in its eighth incubation, a second preview of stream gatherers, a second preview of a class-file API, and a preview of primitive types in patterns, instanceof, and switch statements. Additional features include module import declarations, Markdown documentation comments, and setting the generational mode of the Z Garbage Collector as the default. Another significant update is a third preview of implicitly declared classes and instance methods. Early access builds of JDK 23 are available at jdk.java.net.
JDK 23 plans to deprecate the memory-access methods in sun.misc.Unsafe, aiming for their removal in future versions. These unsupported methods have been replaced by standard APIs like the VarHandle API and the foreign function and memory API. The OpenJDK project encourages developers to transition from sun.misc.Unsafe to these new APIs to facilitate a smooth migration to modern JDK releases. The proposal’s goals include preparing the ecosystem for the future removal of these methods and helping developers identify their reliance on them. The plan does not intend to remove sun.misc.Unsafe entirely, as some of its non-memory access methods will be deprecated and removed separately.
Structured concurrency, which aims to simplify concurrent programming by treating groups of related tasks as a single unit of work, will receive its third preview in JDK 23. This feature has been previewed in both JDK 21 and JDK 22. Its goals include reducing common concurrency risks, such as thread leaks and cancellation delays, and improving the observability of concurrent code.
The flexible constructor bodies feature, previously known as statements before super(…) and previewed in JDK 22, will get a second preview in JDK 23. This feature allows fields to be initialized in the constructor body before calling the superclass constructor. It aims to provide developers with greater flexibility in writing constructor logic while ensuring that constructors execute in a top-down order.
Implicitly declared classes and instance methods, previously previewed in JDK 21 and JDK 22, simplify the Java language for beginners. These enhancements allow new programmers to write simpler code and gradually adopt more advanced features. JDK 23 will add automatic import of three static methods for text I/O with the console and on-demand import of public classes and interfaces from the java.base module.
Module import declarations, a new preview feature in JDK 23, will allow importing all packages exported by a module in a concise manner. This proposal, aimed at simplifying the use of modular libraries, does not require the imported code to be in a module itself. Its goals include reducing the verbosity of multiple import declarations and making it easier for beginners to use third-party libraries.
Markdown documentation comments, proposed last September, will enable JavaDoc comments to be written in Markdown, making them easier to read and write. This proposal will also extend the Compiler Tree API to handle Markdown content, without affecting the interpretation of existing comments.
JDK 23 will also switch the Z Garbage Collector (ZGC) to generational mode by default, improving performance by collecting young objects more frequently. The non-generational mode will be deprecated, with future development focusing on generational ZGC to reduce maintenance costs.
The vector API, in incubation since JDK 16, will continue to evolve, providing an API for vector computations optimized for supported CPU architectures. This API aims to offer a clear and concise interface, reliable runtime compilation, and performance on x64 and AArch64 architectures, with graceful degradation and platform-agnostic design, aligning with Project Valhalla’s goals.
Stream gatherers, first previewed in JDK 22, will enhance the stream API with custom intermediate operations, making stream pipelines more flexible and expressive, capable of handling infinite streams.
The class-file API, designed to process class files according to the JVM specification, will continue to evolve, replacing the JDK’s internal use of the third-party ASM library with a standard API.
JDK 23 will also include a preview of primitive types in patterns, instanceof, and switch statements, enhancing pattern matching by supporting primitive type patterns and extending instanceof and switch to all primitive types.
Additional features previously previewed