Most Common Features of Java 12
Switch expressions (JEP 325)
Java 12 has enhanced Switch expressions for Pattern matching. It extends the switch statement so that it can be used as either a statement or an expression. These Forms can be used either as a “traditional” or “simplified” scoping control flow behavior. Thus the benefits are, these changes are used for simplification of everyday coding, for preparing the way, use of pattern matching (JEP 305) in the switch.
Default CDS archives (JEP 341)
Developers enhance the JDK for the building process to generate a class data-sharing (CDS) archive, using the default class list, on 64-bit platforms. CDS helps to reduce the start-up time of a Java application and its memory footprint.
JEP 189: Shenandoah
Add a new garbage collection (GC) algorithm named Shenandoah, which reduces GC pause times by doing evacuation work concurrently with the running Java threads. Pause times with Shenandoah are independent of the heap size, meaning you will have the same consistent pause times whether your heap is 200 MB or 200 GB.
JEP 334: JVM constants API
The purpose of this new API (JEP 344) is to make it easier for programs that manipulate class files to model bytecode instructions, which have to handle loadable constants. This is a very technical change, so it is more about helping the developers of Java to make it better than giving general developers a specific new feature.
JEP 230: Microbenchmark suite
It’s a new feature of Java 12. The goals of JEP 230 are: to provide stable and tuned benchmarks, including an initial set of approximately 100 benchmarks and adding a basic suite of microbenchmarks to the JDK source code, and make it easy for developers to run existing microbenchmarks and create new ones.
JEP 344: Abortable mixed collections for G1
Make G1 combined groups abortable if they might exceed the pause target.
JEP 346: Promptly return unused committed memory from G1
Enhance the G1 garbage collector to automatically return Java heap memory to the operating system when idle.
One AArch64 port, not two (JEP 340)
Instead of two ports, Java 12 will only have one port for the ARM 64-bit processors (aarch64). The objective is to delete all arm64 port-related sources while keeping the 32-bit ARM port and 64-bit aarch64 port.
Benefits of Java 12 over Java 11
- It makes the coding process easier by extending the switch statement and enabling it to be used as a statement or expression.
- By maintaining two-port, it eliminates any duplicate work.
- Add a suite of microbenchmarks into the JDK build source code, streamlining the running of existing benchmarks and the creation of new ones.
- It helps to make aborting the garbage collection process much more efficient by breaking up the mixed collection group into mandatory and optional parts.
- It boosts the JDK build process by creating a class data-sharing archive through a default class list on the 64-bit platform.
- Upgrade the G1 garbage collector to instantly return unused Java heap memory to the operating system when idle.
- It reduces the garbage collection pause times by processing evacuation work while running the Java threads, which means that pause times are consistent regardless of the heap size etc.
Which one is better to use Java 12 or Java 11
Well, Java 11 is a Long Term Support version for commercial use. Amazon and RedHat are offering Java 11 until June 2023. If you are building an application that you are expecting to deploy, need to maintain hundreds of enterprise applications, with minimal impacts, it will be highly appreciated to stick with JDK 11. But if you are just experimenting or using it as a learning aid or opportunities, u can use JDK 12.