Significant Changes in JDK 24 Release
See JDK 24 Release Notes for additional descriptions of the new features and enhancements, and API specification in JDK 24.
The following are some of the updates in Java SE 24 and JDK 24:
Language Preview Features
- Pattern Matching is enhanced by allowing primitive types in all pattern contexts. The
instanceof
operator andswitch
expressions and statements are extended to work with all primitive types.First previewed in Java SE 23, this feature is re-previewed for this release. It is unchanged between Java SE 23 and this release.
See JEP 488: Primitive Types in Patterns, instanceof, and switch (Second 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. This simplifies the reuse of modular libraries without requiring the importing code to be in a module itself.
First previewed in Java SE 23, this feature is re-previewed for this release. In this release:
- Type-import-on-demand declarations shadow module import declarations.
- Modules may declare a transitive dependence on the
java.base
module. - The
java.se
module transitively requires thejava.base
module. Consequently, importing thejava.se
module imports the entire Java SE API.
See JEP 494: Module Import Declarations (Second Preview) and Module Import Declarations in Java Platform, Standard Edition Java Language Updates.
- Flexible Constructor Bodies allow statements in a constructor to appear before an explicit constructor invocation, such as
super(..)
orthis(..)
. These statements cannot reference the instance under construction, but they can initialize its fields. Initializing fields before invoking another constructor makes a class more reliable when methods are overridden.First previewed in Java SE 22 as JEP 447: Statements before super(...) (Preview) and previewed again in Java SE 23 as JEP 482: Flexible Constructor Bodies (Second Preview). This feature is re-previewed for this release without any significant changes.
See JEP 492: Flexible Constructor Bodies (Third Preview) and Flexible Constructor Bodies in Java Platform, Standard Edition Java Language Updates.
- Simple Source Files and Instance Main Methods enable beginners to write their first programs without needing to understand language features designed for large programs. Far from using a separate dialect of the language, beginners can write streamlined declarations for single-class programs and then seamlessly expand their programs to use more advanced features as their skills grow. Experienced developers can likewise enjoy writing small programs succinctly, without the need for constructs intended for programming in the large.
First previewed in Java SE 21 as JEP 445: Unnamed Classes and Instance Main Methods (Preview) and previewed again in Java SE 23. This feature is re-previewed for this release with new terminology and a revised title but otherwise unchanged.
See JEP 495: Simple Source Files and Instance Main Methods (Fourth Preview) and Simple Source Files and Instance Main Methods in Java Platform, Standard Edition Java Language Updates.
See JEP 12: Preview Features and Preview Language and VM Features in Java Platform, Standard Edition Java Language Updates.
Performance and Runtime Improvements
- The size of object headers in the HotSpot JVM is reduced from 96 and 128 bits to 64 bits on 64-bit architectures. This will reduce heap size, improve deployment density, and increase data locality. This is an experimental feature and can be enabled by passing the command line options:
+UnlockExperimentalVMOptions -XX:+UseCompactObjectHeaders
- The implementation of the G1 garbage collector's barriers has been simplified, which record information about application memory accesses, by shifting their expansion from early in the C2 JIT's compilation pipeline to later.
- Ahead-of-Time Class Loading and Linking improves the startup time by making the classes of an application instantly available, in a loaded and linked state, when the HotSpot Java Virtual Machine starts. This is achieved by monitoring the application during one run, and storing the loaded and linked forms of all classes in a cache for subsequent runs.
- The ZGC garbage collector runs in the generational mode by default. The non-generational mode of ZGC is removed.
See JEP 490: ZGC: Remove the Non-Generational Mode and the section The Z Garbage Collector in Java Platform, Standard Edition HotSpot Virtual Machine Garbage Collection Tuning Guide.
- Synchronize Virtual Threads without Pinning improves the scalability of Java code that uses
synchronized
methods and statements by arranging for virtual threads that block in such constructs to release their underlying platform threads for use by other virtual threads.
Library Improvements, Previews, and Incubator
- The Class-File API is a standard API for parsing, generating, and transforming Java class files.
See JEP 484: Class-File API 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 are not easily achievable with the existing built-in intermediate operations.
See JEP 485: Stream Gatherers and Stream Gatherers in Java Platform, Standard Edition Core Libraries.
- Structured Concurrency is an API that simplifies concurrent programming. It treats groups of related tasks running in different threads as a single unit of work, thereby streamlining error handling and cancellation, improving reliability, and enhancing observability.
See JEP 499: Structured Concurrency (Fourth Preview) and Structured Concurrency in Java Platform, Standard Edition Core Libraries.
- Scoped Values enable a method to share immutable data both with its callees within a thread and with child threads. They are easier to reason about than thread-local variables. They also have lower space and time costs, especially when used together with virtual threads and structured concurrency.
See JEP 487: Scoped Values (Fourth Preview) and the
ScopedValue
class in the Java API Specification. - The Vector API expresses 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 489: Vector API (Ninth Incubator) and JEP 11: Incubator Modules.
- An API has been introduced for Key Derivation Functions (KDFs), which are cryptographic algorithms for deriving additional keys from a secret key and other data. This is a preview API.
See JEP 478: Key Derivation Function API (Preview) and The KDF Class in Java Platform, Standard Edition Security Developer's Guide.
- The security of Java applications is enhanced by providing an implementation of the quantum-resistant Module-Lattice-Based Key-Encapsulation Mechanism (ML-KEM). Key encapsulation mechanisms (KEMs) are used to secure symmetric keys over insecure communication channels using public key cryptography.
See JEP 496: Quantum-Resistant Module-Lattice-Based Key Encapsulation Mechanism.
- The security of Java applications is enhanced by providing an implementation of the quantum-resistant Module-Lattice-Based Digital Signature Algorithm (ML-DSA). Digital signatures are used to detect unauthorized modifications to data and to authenticate the identity of signatories.
See JEP 497: Quantum-Resistant Module-Lattice-Based Digital Signature Algorithm.
Removals and Warnings for Future Changes
- Prepare to Restrict the Use of JNI: Warnings are issued about uses of the Java Native Interface (JNI), and the Foreign Function and Memory (FFM) API is adjusted to issue warnings in a consistent manner. All such warnings aim to prepare developers for a future release that ensures integrity by default by uniformly restricting JNI and the FFM API.
See JEP 472: Prepare to Restrict the Use of JNI and Restrictions on and Warnings from Accessing Native Code.
- Permanently Disable the Security Manager: The Security Manager is permanently disabled, and the Security Manager API will be removed in a future release.
See JEP 486: Permanently Disable the Security Manager and The Security Manager Is Permanently Disabled in Java Platform, Standard Edition Security Developer's Guide.
- ZGC: Remove the Non-Generational Mode: The ZGC garbage collector runs in the generational mode by default. The non-generational mode of ZGC is removed.
See JEP 490: ZGC: Remove the Non-Generational Mode and the section The Z Garbage Collector in Java Platform, Standard Edition HotSpot Virtual Machine Garbage Collection Tuning Guide.
- Warn upon Use of Memory-Access Methods in sun.misc.Unsafe: A warning is issued at run time on the first occasion that any memory-access method in
sun.misc.Unsafe
is invoked. All of these unsupported methods were terminally deprecated in JDK 23. They have been superseded by standard APIs, namely the VarHandle API and the Foreign Function & Memory API.See JEP 498: Warn upon Use of Memory-Access Methods in sun.misc.Unsafe.
For more details on removals and deprecations, see Features and Options Removed and Deprecated in JDK 24.
In addition, there are security related updates that you need to be aware of. See Security Updates in JDK 24.