[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/Snailclimb/JavaGuide/main/docs/java/new-features/java24.md [Back]  [Original]

---
title: Java 24 
description:  JDK 24  Java 
category: Java
tag:
  - Java
head:
  - - meta
    - name: keywords
      content: Java 24,JDK24,JEP ,,GC ,
---

JDK 24  2025  3  LTS 2025  9  LTS  **JDK 25**

JDK 24  24 

- [JEP 478: Key Derivation Function API ( API, )](https://openjdk.org/jeps/478)
- [JEP 483: Early Class-File Loading & Linking ()](https://openjdk.org/jeps/483)
- [JEP 484: Class File API ( API)](https://openjdk.org/jeps/484)
- [JEP 485: Stream Gatherers ()](https://openjdk.org/jeps/485)
- [JEP 486: Disable the Security Manager ()](https://openjdk.org/jeps/486)
- [JEP 487: Scoped Values (, )](https://openjdk.org/jeps/487)
- [JEP 495: Simplified Source Files and Instance Main Methods (, )](https://openjdk.org/jeps/495)
- [JEP 497: Quantum-Resistant Digital Signature Algorithm (ML-DSA) ()](https://openjdk.org/jeps/497)
- [JEP 499: Structured Concurrency (, )](https://openjdk.org/jeps/499)

 JDK 8  JDK 25 

![](https://oss.javaguide.cn/github/javaguide/java/new-features/jdk8~jdk24.png)

## JEP 478: Key Derivation Function API API

 API  API  JDK 24 

 API HKDF 

```java
//  KDF  HKDF-SHA256 
KDF hkdf = KDF.getInstance("HKDF-SHA256");

//  Extract  Expand 
AlgorithmParameterSpec params =
    HKDFParameterSpec.ofExtract()
                     .addIKM(initialKeyMaterial) // 
                     .addSalt(salt)             // 
                     .thenExpand(info, 32);     // 

//  32  AES 
SecretKey key = hkdf.deriveKey("AES", params);

//  KDF 
```

## JEP 483: Early Class-File Loading & Linking

 JVM JEP 483  Spring PetClinic  AOT  42%

 AOT  `-XX:AOTMode=record``-XX:AOTConfiguration``-XX:AOTMode=create`  `-XX:AOTCache`

## JEP 484: Class File API API

 API  JDK 22 [JEP 457](https://openjdk.org/jeps/457) JDK 23 [JEP 466](https://openjdk.org/jeps/466) JDK 24 

 API  API Java  ASM

```java
//  ClassFile 
ClassFile cf = ClassFile.of();
//  ClassModel
ClassModel classModel = cf.parse(bytes);

//  "debug" 
byte[] newBytes = cf.build(classModel.thisClass().asSymbol(),
        classBuilder -> {
            // 
            for (ClassElement ce : classModel) {
                //    "debug" 
                if (!(ce instanceof MethodModel mm
                        && mm.methodName().stringValue().startsWith("debug"))) {
                    // 
                    classBuilder.with(ce);
                }
            }
        });
```

## JEP 485: Stream Gatherers

 `Stream::gather(Gatherer)` `Gatherer` 

 `filter``map`  `distinct` `Stream::gather`  Stream  `Stream::gather`   Stream API 

 `Stream::gather(Gatherer)` 

```java
var result = Stream.of("foo", "bar", "baz", "quux")
                   .gather(Gatherer.ofSequential(
                       HashSet::new, //  HashSet,
                       (set, str, downstream) -> {
                           if (set.add(str.length())) {
                               return downstream.push(str);
                           }
                           return true; // 
                       }
                   ))
                   .toList();// 

//  ==> [foo, quux]
```

## JEP 486: Disable the Security Manager

JDK 24  `Security Manager` `java -Djava.security.manager`  `Security Manager`  Java Java 

## JEP 487: Scoped Values, 

Scoped Values

```java
final static ScopedValue V = ScopedValue.newInstance();

// In some method
ScopedValue.where(V, )
           .run(() -> { ... V.get() ... call methods ... });

// In a method called directly or indirectly from the lambda expression
... V.get() ...
```



## JEP 491: Virtual Threads Synchronization Without Pinning

 `synchronized`   `synchronized`   (Pinning)

 `synchronized`  Java   I/O   `synchronized` 

## JEP 493: Linking Run-Time Images Without JMOD Files JMOD 

JDK  JMOD  jlink  JDK  JMOD  JDK  25%



- Jlink  Java 9  Java  JRE
- JMOD 

## JEP 495: Simplified Source Files and Instance Main Methods, 

 `main`  Java  `main`  Java 

 `main` 

```java
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
```

 `main` 

```java
class HelloWorld {
    void main() {
        System.out.println("Hello, World!");
    }
}
```



```java
void main() {
   System.out.println("Hello, World!");
}
```

## JEP 497: Quantum-Resistant Digital Signature Algorithm (ML-DSA)

JDK 24 Module-Lattice-Based Digital Signature Algorithm, **ML-DSA**

ML-DSA NIST FIPS 204 

## JEP 498: Warnings When Using `sun.misc.Unsafe` Memory Access Methods ( `sun.misc.Unsafe` )

JDK 23([JEP 471](https://openjdk.org/jeps/471))  `sun.misc.Unsafe`  JDK 24  `sun.misc.Unsafe` 



- `java.lang.invoke.VarHandle`JDK 9 (JEP 193) 
- `java.lang.foreign.MemorySegment`JDK 22 (JEP 454)  `VarHandle` 

`MemorySegment`  Foreign Function & Memory API API`VarHandle`  APIForeign Function & Memory API  JDK 22 

```java
import java.lang.foreign.*;
import java.lang.invoke.VarHandle;

// 
class OffHeapIntBuffer {

    // VarHandle
    private static final VarHandle ELEM_VH = ValueLayout.JAVA_INT.arrayElementVarHandle();

    // 
    private final Arena arena;

    // 
    private final MemorySegment buffer;

    // 
    public OffHeapIntBuffer(long size) {
        this.arena  = Arena.ofShared();
        this.buffer = arena.allocate(ValueLayout.JAVA_INT, size);
    }

    // 
    public void deallocate() {
        arena.close();
    }

    // volatile
    public void setVolatile(long index, int value) {
        ELEM_VH.setVolatile(buffer, 0L, index, value);
    }

    // 0
    public void initialize(long start, long n) {
        buffer.asSlice(ValueLayout.JAVA_INT.byteSize() * start,
                       ValueLayout.JAVA_INT.byteSize() * n)
              .fill((byte) 0);
    }

    // 
    public int[] copyToNewArray(long start, int n) {
        return buffer.asSlice(ValueLayout.JAVA_INT.byteSize() * start,
                              ValueLayout.JAVA_INT.byteSize() * n)
                     .toArray(ValueLayout.JAVA_INT);
    }
}
```

## JEP 499: Structured Concurrency, 

JDK 19  API JDK 24  API  `java.util.concurrent`



 API  `StructuredTaskScope`

`StructuredTaskScope` 

```java
    try (var scope = new StructuredTaskScope()) {
        // fork
        Subtask subtask1 = scope.fork(task1);
        Subtask subtask2 = scope.fork(task2);
        // 
        scope.join();
        // 
        ... process results/exceptions ...
    } // close
```

 JDK 

Web Proxy Viewer  |  New URL  |  Original Page