Java 12: What's new in the latest version of the programming language?

The latest release of the language promises a few notable improvements and is available to download from Oracle.

The best programming languages to learn in 2019: Top coding skills that pay you the most

Java 12 is out, bringing with it a few language changes and tweaks under the hood that should improve application performance.

Special Report

Riding the DevOps revolution

You can download all of the articles in this special report in one PDF (free registration required).

While many developers may still be using Java 8, the latest release of the language does promise a few notable improvements and is available to download from Oracle here.

If you're interested in how to upgrade to a newer version of Java or how organizations can keep using an older version without having to pay for support, check out advice from the experts.

Meanwhile, with new versions of Java coming out every six months, there's plenty of interesting features in earlier versions of Java that many developers might not have tried, as you can see in this guide.

SEE: Job description: Java developer (Tech Pro Research)

In the meantime, here are some of the biggest new features in Java 12.

The Shenandoah garbage collector

Garbage collection is the process by which a programming language frees up memory that is no longer required by the application.

The process will pause the application while the memory is located and released, and in extreme cases, or where a user is interacting with an application in realtime, those pauses can be noticeable to the user.

Java 12 introduces Shenandoah, which is described as a "low pause time garbage collector that reduces GC pause times by performing more garbage collection work concurrently with the running Java program".

Due to carrying out more garbage collection concurrently, pause times are no longer directly proportional to how much memory is set aside for an application at runtime in a portion of memory known as 'the heap'.

"Garbage collecting a 200 GB heap or a 2 GB heap should have the same predictable pause behavior," according to OpenJDK docs.

As an experimental feature, Shenandoah will require typing XX:+UnlockExperimentalVMOptions in the command line.

Improvements to the existing G1 garbage collector

Java has a choice of garbage collectors (GCs) and Java 12 brings improvements for the existing G1 GC.

Abortable Mixed Collections for G1 aims to reduce the instances where the GC pauses the application for a longer period than its target time, due to working on too large a section of memory. The update aims to provide the ability for less important parts of the garbage collection process to be carried out incrementally, as a series of steps where the next step can be aborted depending on the remaining time.

The Promptly Return Unused Committed Memory feature is designed to allow the G1 GC to return as much memory as possible to the operating system when it is not being used by the application. This is achieved by the GC periodically analyzing how much of the overall Java heap memory is being used by the application and automatically returning the unused portion of the heap back to the OS.

According to the proposals for the new feature, the change should benefit developers running Java and the G1 GC in pay-per-use containers, as the G1 GC would previously retain an unnecessarily large amount of memory for Java applications, resulting in developers paying over the odds.

Switch expressions

Switch expressions allow developers to use simpler syntax when using switch statements to specify different responses based on the input.

For example, rather than using the following syntax for each case within the switch statement:

switch (port) {

case 20:

type = PortType.FTP;



each case could instead be expressed in the following, more concise manner:

Switch (port) {

case 20 -> PortType.FTP;


In Java 12, Switch Expressions are available as a preview feature, meaning the command-line switch --enable-preview must be passed to the javac compiler.

Other notable changes in the new Java release include: JEP 230 - Microbenchmark Suite, JEP 334 - JVM Constants API , JEP 340 - One AArch64 Port, Not Two, JEP 341 - Default CDS Archives, JEP 344 - Abortable Mixed Collections for G1, JEP 346 - Promptly Return Unused Committed Memory from G1.

Also see