DEV Community

araf
araf

Posted on

What's New in JDK 24: Final, Preview, Incubator & Experimental Features with Real Examples

Java Development Kit (JDK) 24, released in March 2025, delivers significant enhancements in language design, performance, runtime, and developer productivity. This guide covers the new features by category β€” Final, Preview, Incubator, and Experimental β€” with examples and practical use cases.


βœ… Final Features

πŸ”Ή JEP 457: Class-File API

Standard API for reading, writing, and transforming .class files. Great for IDEs, agents, and static analyzers.

ClassModel model = ClassFile.read(Path.of("MyClass.class"));
model.methods().forEach(System.out::println);
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή JEP 461: Stream Gatherers

A flexible abstraction to define custom stream collection logic.

var result = List.of("Java", "24", "rocks")
    .stream()
    .collect(Gatherers.joining(" "));
System.out.println(result); // Java 24 rocks
Enter fullscreen mode Exit fullscreen mode

πŸ§ͺ Preview Features (Use --enable-preview)

🧩 JEP 488: Primitive Types in Patterns, instanceof, and switch (Second Preview)

Pattern matching now supports primitive types in all contexts (instanceof, switch, record patterns).

Object input = 42;
if (input instanceof int i) {
    System.out.println("It's an int: " + i);
}
Enter fullscreen mode Exit fullscreen mode

🧩 JEP 494: Module Import Declarations (Second Preview)

Allows succinct import of entire modules, streamlining modular code reuse.

import module java.se.*; // Hypothetical syntax
Enter fullscreen mode Exit fullscreen mode

🧩 JEP 492: Flexible Constructor Bodies (Third Preview)

Supports statements before super(...) or this(...) in constructors, enabling early field initialization.

class User {
    final String id;
    User(String name) {
        id = name.toUpperCase(); // Allowed before super()
        super();
    }
}
Enter fullscreen mode Exit fullscreen mode

🧩 JEP 495: Simple Source Files and Instance Main Methods (Fourth Preview)

Allows writing programs without needing a class declaration.

void main() {
    System.out.println("Hello from simple Java!");
}
Enter fullscreen mode Exit fullscreen mode

🧩 JEP 487: Scoped Values (Fourth Preview)

Share immutable context across threads more safely than ThreadLocal.

ScopedValue<String> USER_ID = ScopedValue.newInstance();
ScopedValue.runWhere(USER_ID, "abc123", () -> {
    System.out.println(USER_ID.get());
});
Enter fullscreen mode Exit fullscreen mode

🧩 JEP 478: Key Derivation Function API

New cryptographic API for deriving secure keys.

KDF kdf = KDF.getInstance("HKDF");
SecretKey derived = kdf.deriveKey(...);
Enter fullscreen mode Exit fullscreen mode

🚧 Incubator Features

πŸ”¬ JEP 489: Vector API (Ninth Incubator)

Offers SIMD-style programming with reliable runtime compilation to vector instructions.

FloatVector va = FloatVector.fromArray(SPECIES, a, 0);
FloatVector vb = FloatVector.fromArray(SPECIES, b, 0);
FloatVector vc = va.add(vb);
Enter fullscreen mode Exit fullscreen mode

🧬 Experimental Features

πŸ§ͺ JEP 450: Compact Object Headers

Reduces memory footprint and increases performance via smaller object headers. Enabled with:

-XX:+UnlockExperimentalVMOptions -XX:+UseCompactObjectHeaders
Enter fullscreen mode Exit fullscreen mode

πŸ§ͺ JEP 483: Ahead-of-Time Class Loading and Linking

Improves startup time by preloading class metadata during previous runs.


πŸ§ͺ JEP 491: Synchronize Virtual Threads without Pinning

Enhances virtual thread scalability by avoiding platform thread pinning.


πŸ”§ Additional Improvements

  • JEP 499: Structured Concurrency (Fourth Preview) – Treat related threads as a single unit for better cancellation and error handling.
  • JEP 475: Late Barrier Expansion for G1 – Performance boost for the G1 garbage collector.
  • JEP 490: ZGC now runs in generational mode by default.
  • JEP 486: Security Manager permanently disabled.
  • JEP 496/497: Quantum-resistant cryptographic algorithms.

πŸ’‘ Real-World Use Cases

Use Case Feature Why It’s Useful
Bytecode tools Class-File API Easy .class parsing/modification
Stream processing Stream Gatherers Custom intermediate operations
Cryptographic systems KDF API, Quantum-safe Modern, secure cryptography
Teaching & scripting Simple Source Files Beginner-friendly Java
Thread context Scoped Values Safe data sharing across threads

πŸ› οΈ Get Started with JDK 24

  1. Download: OpenJDK 24 or Oracle JDK 24
  2. Compile Preview Code:
javac --enable-preview --release 24 Example.java
java --enable-preview Example
Enter fullscreen mode Exit fullscreen mode
  1. Use a Supported IDE: IntelliJ IDEA, Eclipse, or VS Code with Java 24 plugin.

πŸš€ Wrap-up

JDK 24 continues Java’s mission to evolve for modern applications. From better startup and memory usage to developer ergonomics and secure cryptography β€” it’s a strong upgrade for devs at any level.

πŸ‘‰ Have you tried Java 24? What’s your favorite feature?

Follow for more deep dives into Java, JVM performance, and productivity tools. β˜•πŸ’»

Top comments (0)