Java 19 major language and API improvements
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.
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
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.
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.
var preallocatedElements = 5;
Map map = HashMap.newHashMap(preallocatedElements);
var preallocatedElements = 5;
Set map = HashSet.newHashSet(preallocatedElements);
var preallocatedElements = 5;
Map map = LinkedHashMap.newLinkedHashMap(preallocatedElements);
var preallocatedElements = 5;
Set map = LinkedHashSet.newLinkedHashSet(preallocatedElements);
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..