What’s New in JDK 23? A Deep Dive into Upcoming Java Features
JDK 23, the next non‑LTS release of the Java platform slated for September 17, introduces a suite of preview features—including scoped values, structured concurrency, flexible constructor bodies, implicit class and instance methods, module import declarations, Markdown Javadoc, vector API enhancements, and a default generational ZGC mode—while deprecating sun.misc.Unsafe memory‑access methods.
Java Development Kit (JDK) 23 is the next standard Java release and has entered the candidate release stage. Its official release date is set for September 17.
The final feature set includes a dozen preview features. Notably, the third preview of string templates, which appeared in JDK 21 and JDK 22, has been removed.
Scoped Values
Scoped values, previously previewed in JDK 21 and JDK 22, allow immutable data to be shared between a method and its caller as well as child threads. They are easier to reason about than thread‑local values and have lower space and time costs, especially when used with virtual threads and structured concurrency. In JDK 23 the API changes: the callWhere parameter now uses a functional interface that can infer checked exceptions, and the old getWhere method has been removed.
Deprecation of Unsafe Memory‑Access Methods
JDK 23 plans to deprecate the memory‑access methods in sun.misc.Unsafe. These methods are replaced by the standard VarHandle API and the Foreign Function & Memory API. Library developers are encouraged to migrate away from sun.misc.Unsafe to ensure smooth migration to future JDK versions.
Structured Concurrency (Third Preview)
The third preview of structured concurrency arrives in JDK 23, building on the earlier previews in JDK 21 and JDK 22. It introduces an API that treats related tasks across threads as a single unit of work, simplifying error handling, cancellation, and improving observability.
Flexible Constructor Bodies (Second Preview)
This preview allows constructor bodies to initialize fields of the same class before an explicit super(...) call, enabling more natural placement of static helper methods or logic that would otherwise need to be in auxiliary constructors.
Implicitly Declared Classes and Instance Methods
Previously previewed in JDK 21 and JDK 22, this feature lets beginners write concise programs without needing to understand large‑scale language features. JDK 23 adds two enhancements: automatically importing three methods for simple console I/O and on‑demand importing of the static java.base module’s exported packages.
Module Import Declarations
A preview feature that simplifies importing all packages exported by a module with a single declaration, reducing boilerplate and making third‑party library usage easier for beginners.
Markdown Javadoc Comments
This proposal allows JavaDoc comments to be written in Markdown instead of the traditional HTML‑plus‑@tags mix, improving readability and enabling tooling that processes Markdown content.
ZGC Switch to Generational Mode
JDK 23 changes the default mode of the Z Garbage Collector (ZGC) to a generational mode, aiming to improve performance by collecting young objects more frequently and retiring the non‑generational mode.
Vector API (Eighth Incubator)
The Vector API, incubated since JDK 16, provides a concise API for expressing vector computations that compile to optimal vector instructions on supported CPUs, with goals of portability, graceful degradation, and alignment with the Valhalla project.
Stream Collectors (Second Preview)
This enhancement adds support for custom intermediate operations in the Stream API, allowing more expressive transformations of potentially infinite streams.
Class File API (Second Preview)
The Class File API offers a standard way to manipulate class files, replacing internal ASM copies and adding streamlined builders for bytecode instructions.
Raw Types, instanceof, and switch in Patterns
A preview that extends pattern matching to raw types, aligning instanceof and switch with all primitive types, and unifying pattern usage across contexts.
String Templates (Removed)
String templates, previewed in JDK 21 and JDK 22, are omitted from JDK 23 after community feedback indicated they had not fulfilled expectations.
Oracle also hinted at upcoming OpenJDK projects for 2024, including Amber (small‑scale productivity features), Babylon (GPU and external programming model extensions), and Valhalla (value‑type enhancements).
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
