Significant Changes in JDK 23 Release
See JDK 23 Release Notes for additional descriptions of the new features and enhancements, and API specification in JDK 23.
The following are some of the updates in Java SE 23 and JDK 23:
Language Preview Features
- Pattern matching is now enhanced by allowing primitive type patterns in all pattern contexts. The
instanceof
andswitch
operators, expressions, and statements work with all primitive types.See JEP 455: Primitive Types in Patterns, instanceof, and switch (Preview) and the following sections in Java Platform, Standard Edition Java Language Updates:
- Module Import Declarations enable you to succinctly import all of the packages exported by a module with a module import declaration. It simplifies the reuse of modular libraries without requiring the imported code to be in a module.
See JEP 476: Module Import Declarations (Preview) and Module Import Declarations in Java Platform, Standard Edition Java Language Updates.
- Flexible Constructor Bodies enable you to add statements that don't reference the instance being created before an explicit constructor invocation. This feature helps you to prepare arguments for a superclass constructor by performing nontrivial computations or to validate arguments you want to pass to a superclass constructor.
See JEP 482: Flexible Constructor Bodies (Second Preview) and Flexible Constructor Bodies in Java Platform, Standard Edition Java Language Updates.
- Implicitly Declared Classes and Instance Main Methods enable students to write their first programs even without learning the full set of language features designed for large programs. Students can write streamlined declarations for single-class programs and then seamlessly expand their programs to use more advanced features as their skills grow.
See JEP 477: Implicitly Declared Classes and Instance Main Methods (Third Preview) and Implicitly Declared Classes and Instance Main Methods in Java Platform, Standard Edition Java Language Updates.
- String Templates were first previewed in JDK 21 (JEP 430) and in JDK 22 (JEP 459). String templates were intended to be re-previewed in JDK 23 (JEP 465). However, after extensive feedback and discussion, we concluded that the feature is unsuitable in its current form. There is no consensus on what a better design will be; therefore, we have withdrawn the feature for now, and JDK 23 will not include it.
See March 2024 Archives by thread and Update on String Templates (JEP 459) from the Project Amber amber-spec-experts mailing list for further discussion.
See JEP 12: Preview Features and Preview Language and VM Features in Java Platform, Standard Edition Java Language Updates.
Library Improvements Previews and Incubator
- The Class-File API is used for parsing, generating, and transforming Java class files.
See JEP 466: Class-File API (Second Preview) and Class-File API in Java Platform, Standard Edition Java Virtual Machine Guide.
- Stream gatherers enable you to create custom intermediate operations, which allow stream pipelines to transform data in ways that aren't easily achievable with existing built-in intermediate operations.
See JEP 473: Stream Gatherers (Second Preview) and Stream Gatherers in Java Platform, Standard Edition Core Libraries.
- Structured concurrency treats multiple tasks running in different threads as a single unit of work, thereby streamlining error handling and cancellation, improving reliability, and enhancing observability.
See JEP 480: Structured Concurrency (Third Preview) and Structured Concurrency in Java Platform, Standard Edition Core Libraries.
- Scoped values enables sharing of immutable data within and across threads. They are preferred to thread-local variables, especially when using large numbers of virtual threads.
See JEP 481: Scoped Values (Third Preview) and the
ScopedValue
class in the Java API Specification. - The Vector API is introduced to express vector computations that reliably compile at runtime to optimal vector instructions on supported CPU architectures, thus achieving performance superior to equivalent scalar computations. See JEP 469: Vector API (Eighth Incubator).
Runtime Improvements
- The ZGC garbage collector now runs in the generational mode by default. The non-generational mode of ZGC has been deprecated for removal. This will generally improve application performance, although a small number of workloads that are non-generational in nature may be impacted negatively.
See JEP 474: ZGC: Generational Mode by Default and the section The Z Garbage Collector in Java Platform, Standard Edition HotSpot Virtual Machine Garbage Collection Tuning Guide.
- The Oracle GraalVM JIT compiler (Graal JIT) is now included among the JITs available as part of the Oracle JDK. This integration offers innovations previously made available through Oracle GraalVM, such as novel JIT code optimization techniques (see Compiler Advantages in the GraalVM documentation). This provides developers and system administrators more options to help fine tune and improve peak performance of their applications. The Graal JIT is enabled by passing the command line options to the Java executable:
-XX:+UnlockExperimentalVMOptions -XX:+UseGraalJIT
If you do not pass these flags at JVM startup, the Oracle JDK default JIT (C2) will run as usual.
Tooling
JavaDoc documentation comments can now be written in Markdown syntax along with HTML elements and JavaDoc tags.
See JEP 467: Markdown Documentation Comments and Markdown in Documentation Comments in Java Platform, Standard Edition JavaDoc Guide.
Removed APIs, Tools, and Components
For more details on removals and deprecations, see Features and Options Removed and Deprecated in JDK 23.
In addition, there are security related updates that you need to be aware of. See Security Updates in JDK 23.