19.0.2

Latest release in branch Java SE 19
Released 3 years ago (January 17, 2023)

Software Java/Java SE
Branch Java SE 19
Status
End of life
End of premier support March 2023
First official release version 19
First official release date 3 years ago (September 20, 2022)
Release notes https://www.oracle.com/java/technologies/javase/19-0-2-relnotes.html
Documentation https://docs.oracle.com/javase/19
Download https://www.oracle.com/java/technologies/javase/jdk19-archive-downloads.html
Java/Java SE Java SE 19 Releases View full list

What Is New in Java 19

Java 19 delivers seven JDK Enhancement Proposals (JEPs) focused on performance, stability, and laying the groundwork for future features. This release continues the pattern of introducing preview and incubator APIs for real-world testing.

Category JEP(s) Description
Final Features 405, 422 RISC-V Port and Linux/RISC-V Port
Preview Features 425, 427, 426 Virtual Threads, Pattern Matching, Record Patterns
Incubator Features 424, 426 Foreign Function & Memory API, Vector API

What are the main language preview features?

Java 19 introduces three key preview features that significantly evolve the language's expressiveness and concurrency model. These are not final and require the --enable-preview flag to use.

Virtual Threads (JEP 425)

Virtual threads are lightweight threads that dramatically reduce the effort of writing and maintaining high-throughput concurrent applications. They allow you to model concurrent tasks with simple thread-per-request semantics without the cost of OS threads.

try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
    IntStream.range(0, 10_000).forEach(i -> {
        executor.submit(() -> {
            Thread.sleep(Duration.ofSeconds(1));
            return i;
        });
    });
}

Pattern Matching for switch (JEP 427)

This third preview enhances pattern matching for switch expressions and statements. It allows patterns in case labels, making complex data-oriented queries more concise and safer.

static String formatterPatternSwitch(Object obj) {
    return switch (obj) {
        case Integer i -> String.format("int %d", i);
        case Long l    -> String.format("long %d", l);
        case Double d  -> String.format("double %f", d);
        case String s  -> String.format("String %s", s);
        default        -> obj.toString();
    };
}

Record Patterns (JEP 405)

Record patterns deconstruct record values, enabling you to declaratively navigate and extract data from complex object graphs. This works with nested records and type patterns for powerful, nested data extraction.

record Point(int x, int y) {}
static void printSum(Object obj) {
    if (obj instanceof Point(int x, int y)) {
        System.out.println(x + y);
    }
}

Which APIs are in the incubator stage?

Incubator modules are for testing and feedback before potential final inclusion. Java 19 has two major incubating APIs focused on native interoperability and performance.

Foreign Function & Memory API (JEP 424)

This API allows Java programs to interoperate with code and data outside the JVM, such as native libraries and heap memory. It aims to replace the error-prone JNI with a pure Java, safer, and more performant model.

Vector API (JEP 426)

The Vector API is in its fourth incubator round. It expresses vector computations that reliably compile at runtime to optimal vector instructions on supported CPU architectures, outperforming equivalent scalar computations.

What platform and porting updates are included?

This release includes a major new port and a platform-specific update to improve security and support new hardware architectures.

Linux/RISC-V Port (JEP 422)

JDK 19 adds support for the RISC-V architecture, a free and open-source RISC instruction set architecture. The port supports the RV64GV configuration and will help Java run on a wider range of hardware.

UTF-8 by Default (JDK-8267047)

The platform now uses UTF-8 as the default charset for all locales. This standardizes behavior across environments, eliminating unpredictable outcomes when the default charset wasn't UTF-8.

FAQ

Are virtual threads ready for production use?
No, virtual threads are a preview feature in Java 19. They are available for testing and feedback, but you should not use them in production without the preview flag enabled. The feature is expected to be finalized in a future release.

What is the main benefit of the Foreign Function & Memory API?
It provides a superior alternative to JNI (Java Native Interface). You can call native libraries and manage native memory directly from Java code with better performance, safety, and significantly less boilerplate.

Do I need to change my code because of UTF-8 by default?
Most modern applications already specify UTF-8 explicitly and won't be affected. This change primarily benefits applications that relied on the platform's default charset, making their behavior more consistent across different operating systems.

How is pattern matching for switch different from previous previews?
JEP 427 (Java 19) refines the feature based on feedback. The main change is that the grammar for switch labels is now more rigid, requiring patterns to be qualified by the case label itself, which resolves some parsing ambiguities.

Why is the RISC-V port important?
The RISC-V port future-proofs Java by ensuring it runs on a rapidly growing, open-standard hardware architecture. This is crucial for embedded systems, academia, and areas where open hardware is prioritized.

Releases In Branch Java SE 19

Version Release date
19.0.2 3 years ago
(January 17, 2023)
19.0.1 3 years ago
(October 18, 2022)
19 3 years ago
(September 20, 2022)