Java 21  

Java 21 is the fourth long-term support release under the six-month release cadence. It followed Java 20 and preceded Java 22. Java 25 (September 2025) is the current LTS release, though Java 21 remains in active support through December 2029. 

Java 21 Release Details 

Release DateSeptember 19, 2023
LTSYes
OpenJDK End-of-LifeDecember 2029
Minimum Supported VersionsAzul Zulu: 11, 17, 21, 25 

Java 21 Language Features 

Record Patterns (JEP 440) 

Record patterns destructure record components directly in instanceof and switch expressions. Combined with sealed classes (JEP 409, Java 17), this enables exhaustive pattern matching over algebraic data types. 

static String format(Shape shape) { 

    return switch (shape) { 

        case Circle(var r)        -> “circle: radius=” + r; 

        case Rectangle(var w, var h) -> “rect: ” + w + “x” + h; 

        case Triangle(var b, var h)  -> “triangle: base=” + b + ” height=” + h; 

    }; 

Pattern Matching for switch (JEP 441) 

Finalizes the feature previewed in Java 17 (JEP 406) and Java 18-20. Switch expressions and statements now support type patterns with instanceof semantics, guarded patterns with when clauses, and exhaustive checking against sealed hierarchies. 

static String classify(Object obj) { 

    return switch (obj) { 

        case Integer i when i > 0 -> “positive integer”; 

        case Integer i            -> “non-positive integer”; 

        case String s             -> “string of length ” + s.length(); 

        case null                 -> “null”; 

        default                   -> “something else”; 

    }; 

Java 21 Concurrency 

Virtual Threads (JEP 444) 

Virtual threads are lightweight threads managed by the JVM, not the OS. Millions of virtual threads can run concurrently on a bounded platform thread pool. This makes thread-per-request architectures viable at scale without reactive programming models or async callbacks. 

try (var executor = Executors.newVirtualThreadPerTaskExecutor()) { 

    IntStream.range(0, 10_000).forEach(i -> executor.submit(() -> { 

        Thread.sleep(Duration.ofSeconds(1)); 

        return i; 

    })); 

Virtual threads are suited to I/O-bound workloads (HTTP calls, database queries, file reads). CPU-bound workloads see no benefit over platform threads. 

Structured Concurrency (Preview, JEP 453) 

An API for treating multiple concurrent tasks as a single unit of work. A structured task scope ensures all subtasks complete or fail together, eliminating resource leaks from orphaned threads. Previewed in Java 21, incubated in earlier releases. 

Scoped Values (Preview, JEP 446) 

An alternative to ThreadLocal for immutable data shared across virtual threads. Scoped values are bound for a bounded lifetime and cannot be mutated after creation, avoiding the memory leak and inheritance pitfalls of ThreadLocal. 

Java 21 API and JVM Changes 

Sequenced Collections (JEP 431) 

New interfaces SequencedCollection, SequencedSet, and SequencedMap provide consistent APIs for accessing first and last elements, and iterating in reverse order. List, SortedSet, SortedMap, and LinkedHashSet now extend these interfaces. 

Key Encapsulation Mechanism API (JEP 452) 

An API for key encapsulation mechanisms (KEMs), used in hybrid public-key encryption. Supports KEM algorithms via the existing cryptographic service provider framework. 

Generational ZGC (JEP 439) 

ZGC now operates in generational mode by default, separating young and old generations for improved allocation throughput. Non-generational mode was removed in Java 24 (JEP 490). 

Foreign Function and Memory API (Preview, JEP 442) 

Third preview of the API for calling native code and managing off-heap memory without JNI. Finalized in Java 22 (JEP 454). 

Preview Features 

JEPFeatureStatus
JEP 430String Templates Withdrawn after multiple previews 
JEP 443Unnamed Patterns and Variables Finalized in Java 22 (JEP 456) 
JEP 445Unnamed Classes and Instance Main Methods Finalized in Java 25 (JEP 512) 
downloads-swoosh

Java 21 Downloads

 

 

 

Migration from Java 17 to Java 21

Java 21 is the recommended upgrade for organizations on Java 17 LTS. Migration considerations: 

  1. Virtual threads: No code changes required to existing code. Opt-in via Executors.newVirtualThreadPerTaskExecutor() or Thread.ofVirtual() 
  1. Pattern matching: Existing switch statements compile unchanged. New syntax is additive 
  1. Record patterns: Requires sealed interfaces or records as switch subjects 
  1. ZGC: Generational mode is a performance improvement, not a behavior change. G1 remains the default GC 

Azul Support for Java 21 

Azul Platform Core provides TCK-certified builds of OpenJDK 21 with extended support beyond the OpenJDK end-of-life date. Features include: 

  • Quarterly critical patch updates across all supported versions 
  • Builds for Linux (x86_64, ARM), Windows, macOS (Intel and Apple Silicon), Alpine, and musl-based containers 
  • FIPS 140-2 compliant builds for regulated environments 
  • Legacy support coverage for Java 6, 7, and 8 workloads on the same subscription 
  • 70% cost reduction compared to Oracle Java SE subscriptions 
Platform Core wide 1x

Contact Us

Contact us to learn more about our migration services, support, modernization services, and more!