logo

What's new in Java 21

Java 21 was released in 2023. (Unlike C++'s convention, "21" is not referring to the release year). This page summarizes changes in Java 18, 19, 20 and 21.

Spec / Language

Pattern Matching for switch

  • JEP 420: Second Preview (JDK 18)
  • JEP 427: Third Preview (JDK 19)
  • JEP 433: Fourth Preview (JDK 20)

String Templates

  • JEP 430: Preview (JDK 21)

Core Java Library

Project Panama: Vector API and Foreign Function & Memory API

The following updates are part of Project Panama, which improves connections between JVM and foreign / non-Java APIs.

  • Vector API
    • JEP 417: Third Incubator (JDK 18)
    • JEP 426: Fourth Incubator (JDK 19)
    • JEP 438: Fifth Incubator (JDK 20)
  • Foreign Function & Memory API
    • JEP 419: Second Incubator (JDK 18)
    • JEP 424: Preview (JDK 19)
    • JEP 434: Second Preview (JDK 20)

Project Loom

The following updates are part of Project Loom, which aims to bring fibers (lightweight threads) to Java.

  • Virtual Threads
    • JEP 425: Preview (JDK 19)
    • JEP 436: Second Preview (JDK 20)
  • Structured Concurrency
    • JEP 428: Incubator (JDK 19)
    • JEP 437: Second Incubator (JDK 20)
  • Scoped Values
    • JEP 429: Incubator (JDK 20)

Project Amber

The following updates are part of Project Amber, which adds smaller, productivity-oriented Java language features.

  • Record Patterns
    • JEP 405: Preview (JDK 19)
    • JEP 432: Second Preview (JDK 20)

Others

  • JEP 400: UTF-8 by Default (java.nio.charsets) (JDK 18)
  • JEP 408: Simple Web Server (java.net) (JDK 18)
  • JEP 416: Reimplement Core Reflection with Method Handles (java.lang.reflect) (JDK 18)
  • JEP 418: Internet-Address Resolution SPI (java.net) (JDK 18)
  • JEP 421: Deprecate Finalization for Removal (java.lang) (JDK 18)

Tools

  • JEP 413: Code Snippets in Java API Documentation (JDK 18)

Hotspot / Compiler

  • JEP 422: Linux/RISC-V Port (JDK 19)

Extended support

Oracle will offer long term support for Java 21 for at least eight years.

Official Website for Changes

https://docs.oracle.com/en/java/javase/21/language/java-language-changes.html