Martin Ahrer

Thinking outside the box

Java 19 major language and API improvements

2024-09-02 2 min read Martin

Java 19 has been released in September 2022.

The following content is summarizing the most important changes to the Java API, the Java language, and the JVM introduced with Java 19.

For a more complete overview follow the links in the following sections referring to the official Oracle release documents.

Java 19 Language improvements

The following describes selected improvements of the Java language. See the Java 19 release notes. See Java Language Updates for Java SE 19.

Java 19 is introducing the following language enhancements as developer preview.

  • JEP 405 is starting with Record Patterns as developer preview

  • JEP 420 is continuing with Pattern Matching for switch.

  • JEP 425 is starting with Virtual Threads.

  • JEP 428 is starting with Structured Concurrency.

We are not diving into the details of these preview features and defer that until they are moving from preview for general availability.

Java 19 API improvements

The following describes selected improvements of the Java API. See the Java 19 release notes.

Date Time Formatter Api

Of Localized Pattern
LocalDate releaseDate = LocalDate.of(2022, Month.SEPTEMBER, 20);

String formatted=DateTimeFormatter
    .ofLocalizedPattern("yMMM")
    .localizedBy(Locale.ENGLISH)
    .format(releaseDate);

The formatted value is Sep 2022. Read more about the pattern template in the API documentation.

Append Localized
LocalDate releaseDate = LocalDate.of(2022, Month.SEPTEMBER, 20);

String formatted=new DateTimeFormatterBuilder()
    .appendLocalized("yMMM")
    .toFormatter(Locale.ENGLISH)
    .format(releaseDate);

The formatted value is Sep 2022. Read more about the pattern template in the API documentation.

Collection Api

It is now possible to create pre allocated hash maps and hash sets through a set of new factory methods on Set and Map implementations.

New Hash Map
var preallocatedElements = 5;
Map map = HashMap.newHashMap(preallocatedElements);
New Hash Set
var preallocatedElements = 5;
Set map = HashSet.newHashSet(preallocatedElements);
New Linked Hash Map
var preallocatedElements = 5;
Map map = LinkedHashMap.newLinkedHashMap(preallocatedElements);
New Linked Hash Set
var preallocatedElements = 5;
Set map = LinkedHashSet.newLinkedHashSet(preallocatedElements);
New Weak Hash Map
var preallocatedElements = 5;
Map map = WeakHashMap.newWeakHashMap(preallocatedElements);

JVM improvements

The following describes selected improvements of the Java JVM. See the Java 19 release notes.

Class data sharing (CDS) now has an option -XX:+AutoCreateSharedArchive to automatically create or update a CDS archive for an application..