Javatpoint Logo
Javatpoint Logo

Java 12

Java 12 release after the LTS version 11 of Java. JDK 12 is a part of the 6-month release cycle. On 19 March 2019, Java 12 was released, which is a Non-LTS version and would not have long term support.

An open-source reference implementation of Java 12 SE Platform is referred to as Java 12. In JDK 12, production-ready binaries present in the GPL are available from Oracle, and other vendor's binaries will also follow shortly.

In Java JDK 12, there are not so many features of API are added. Internal Java/JVM is the main enhancements in JDK 12. In JDK 12, a new feature, i.e., JEP, is added.

These are the following features included in Java 12 as JEP:

  • JEP 325 (Switch Expressions (preview))
    The switch statement is improved in Java 12 to use it as either an expression or a statement. It allows the switch statement to use the "traditional" or "simplified" scoping and control flow behavior. Everyday coding is simplified by these changes. These changes also provide a way to use pattern matching in the switch. In Java, it is available as a preview language feature.
    In the traditional switch statement, for returning a value we need to assign it to a variable and then we return that variable like this:

We can use case L or break for returning a value from a switch in Java 12.

case L -> syntax

  • JEP 344(Abortable Mixed Collections for G1)
    In case when G1 mixed collection exceeds the pause target, it allows us to make them abortable.
  • JEP 346(Promptly Return Unused Committed Memory from G1)
    The JEP 346 feature is added to promptly return unused committed memory from garbage collector G. In Java 11, the G1 garbage collector was not able to return the Java heap memory to the OS when idle. But in Java 12, the G1 garbage collector is able to do that.
  • JEP 230
    The JEP 230 defines the Microbanchmark Suite. In Java 12, a microbenchmarks suite is added to the JDK source code. It helps the developers to create a new microbenchmark or run an existing one easily.
  • JEP 341(Default Class Data Sharing Archives)
    In order to generate a CDS archive, the JDK build process is enhanced in Java 12. For that, the default class list is used on the 64-bit platform.

Apart from these new features, in Java 12, 4 new string methods are added in which two are mostly used:

indent(int n)

The indent() method is used for adjusting the indentation of each line of the string. The adjustment is based on the argument passed to it.

We can either pass negative or positive int as an argument for reducing the indentation of the string.

Example by passing the positive integer as an argument to the function:


Java 12

Example by passing negative integer as an argument to the function:


Java 12

transform(Function f)

The transform(Function f) is used to apply the specified function to that string. The specified function will accept only a single string value and return the object. Let's take an example to understand this method:


Java 12

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA