30
DecemberJava19 Features
Description
OVERVIEW OF JAVA19 FEATURES
Java 19 was released September 20, 2022. Not being a long-term support release mean the Premier Support for this version
will end in March 2023. This release have been noted to be in "Rampdown Phase One," as it does not include any new JDK
Enhancement Proposals (JEPs), only bug fixes and minor improvements.
Let's take a look at what Java 19 brings us and what it leaves behind.
Changes to Preallocated HashMap Creation
Preview and Incubator Features
Deprecations and Removals
Changes to Preallocated HashMap Creation
Before we get into the changes, some background on HashMaps and their flaws for those not familiar. When generating a HashMap with the argument 60, one might think that means that this HashMap offers space for 60 mappings. Here comes the curveball - the HashMap is initialized with a default load factor of 0.75, meaning that as soon as the HashMap is 75% full, it is rebuilt with double the size. Thus the HashMap initialized with the argument 60 can actually hold just 45 mappings. To create a HashMap with 60 mappings you would have to calculate the capacity by dividing the number of mappings by the load factor. In this case that would result in 60/0.75=80
Java 19 resolve this issue by allowing us to replace this code based on our example data
Map
with the following
Map
Virtual Threads
Virtual Threads have been developed in Project Loom for several years and have made their way into the official JDK as JEP 425. Going straight into the Preview Stage, Virtual Threads are a prerequisite for Structured Concurrency. Keep your eyes open as we dive into these exciting features in a blog post coming in the near future!
Structured Concurrency
Still in the incubator stage, JEP 428 introduces an API for "Structured Concurrency", intended to improve the maintainability, reliability, and observability of multithreaded code. As thread leaks and cancellation delays are common risks arising from cancellation and shutdown, Structured Concurrency aims to promote a style of concurrent programming to combat these flaws.