Oracle is released New version of Java 12 on 19th March 2019. This new version has a lot of new features.\
What are those new Java 12 features?
These features include Allow pattern matching, Microbenchmark Suite, Switch statement to simplify coding, and also raw string literals to introduce multiline expression, One ARM 64 bit, creating security patches in critical scenarios and bug fixes.
The main aim of this version to make or simplify the code by the Java developers using java ecosystem
Let us discuss the new features and improvements of New version JAVA 12, one-by-one.
(Note: JEP stands for JDK Enhancement Proposal and JDK stands for Java Development Kit)
Continue the switch statement so therefore it could be used as either an expression or a statement. And the similarly both forms can use either a “simplified” or “inherited” control flow behavior and scoping. These type of coding will manage to make easier to code in everyday work. Also, prepare the way of use pattern matching in the switch (JEP 305).
Developers in Java are improving the Java programming language to use pattern matching to solve several problems with the current switch statement available in the previous version of Java Programme.
In Java 11 previous version, the switch statement tracks C and C++ programming languages and they were almost the same. And also by default, it uses the fall-through semantics.
While the traditional control flow is helpful when creating low-level codes, the capability of making error will soon exceed its workability as the switch is embraced in higher-level circumstances.
Example explanation:
Java 11 Version Switch statement example is mentioned below
int numberOfLetters; switch (month){ case January: case october: numberOfLetters=7; break; case March: case April: numberOfLetters=5; break; case June: case July: numberOfLetters=4; break; default: throw new IllegalStateException("Wut" + month); }
In this new version of JDK, a new form of switch label, written in the form of “case L ->” Code is written next right of the label, it will only execute when the label is matched with cast mentioned in the code. For clearly understanding, the previously mentioned code will be written as follows.
int numberOfLetters= switch(month){ case January, october -> 7; case March,April -> 5; case June, July -> 4; }
In the above-mentioned example, you can see, there are multiple labels assigned for every single case, separated by a comma.
This is one of the main Java 12 features makes the Garbage First( G1), abort the garbage collection method more accurately by dividing the mixed collection set into optional and mandatory parts.
Which has the highest priority?
Using the garbage collection process, the mandatory set is prioritized.
G1 finished collecting the mandatory part after that G1 starts collecting the optional part at the comminuted level, if and only if time is left.
Will G1 replace Concurrent Mark Sweep (CMS) garbage collector?
As you already know the G1 is a garbage collector designed especially for multi-processing type machines with vast amounts of memory. Due to its enhanced performance, the G1 garbage collector will ultimately replace the Concurrent Mark Sweep (CMS) garbage, collector.
How does G1 Garbage Collector Work?
An important goal of the Garbage Collector (G1) is to reach a user-supplied stop time target for the collection stops. An analysis engine is adopted by G1 and process the workload during a collection. The final outcome of this adoption process is a set of precincts known as collection set.
The collection set is installed and then the collection process has started, so G1(Garbage collector) will collect all the live objects and parameters in collection sets without stopping the process.
In the case G1 finds the collection set selection selects the wrong number of regions more often, it will change to a gradual method for processing mixed collections set by dividing the collection of to be garbage collected regions into two parts called as optional and mandatory parts.
At that point stop and seize the optional parts garbage collection, if the pause time target is not reached.
A low-pause-time garbage collector reduces GC pause times by doing expulsion work simultaneously with the running Java threads.
The JDK’s Enhanced Proposal text adds,
Shenandoah is a suitable algorithm for applications which value predictable and responsiveness in short pauses.
Shenandoah pause times are independent of stack size. It means that you will experience the same consonant pause times irrespective of your stack sizes i.e. 200 MB or 200 GB.
Technology is enhancing like a super rocket, as we already knew that the modern machines work super fast using more memory and excessive processors than ever before.
SLA (Service Level Agreement) applications ensure response time in between 10-500ms.
In order to meet this criterion at the lower end, we have to need garbage collection algorithms works super fast and allow programs to run and execute in available memory, and also never interrupt a running program.
In order to meet the lower end of that goal, we need garbage collection algorithms which are proficient enough to allow programs to run in the available memory but also optimized to never interrupt the running program for more than between available milliseconds.
(Note: Please take a not of this. This feature is only for the experimental purpose and it is not a part of original Oracle’s JDK.)
Introduce an API to model formal descriptions of run-time artifacts and key class-file, in specific constants that are loadable from the constant pool.
JDK’s Enhanced Proposal 334 explains, an API modeling the runtime artifacts and key class-file, such as fixed pool. This API will include different types of classes named, MethodTypeDesc, ClassDesc, and DynamicConstantDesc.
This JEP can be useful for tools that manage different types of methods and classes.
Rather than using two ports, the new version of Java 12 will only have one major port for the (aarch64) ARM 64-bit processors.
The main objective of this proposal is to remove all ARM 64-bit port-related sources while managing the 64-bit aarch64 port and 32bit ARM port.
This process will tend to shift the overall basis to a single 64 bit ARM execution and eliminate duplicate work required to maintain two ports.
How many ARM ports are available in the latest Java version?
There are two 64 bit ARM ports in Java 11 version, but in the latest version, there is only one 64 bit ARM port.
A suite of Microbenchmarks added to the JDK Source code and interprets both the creation of new ones and running the previous microbenchmarks. It is purely based on JMH (Java Microbench Harness) and supports updates of JMH.
Microbenchmarks feature makes easier for the developers who are willing to run current microbenchmarks and also add the new one to the JDK Source code. This code was easily tested by JMH (Java Microbench Harness). It will also support JMH updates.
The end goal of this new version is to enhance the JDK build process by creating the class data sharing( CDS) registers with the aid of the normal class list on the 64-bit core platform and completely eliminating the need to execute
java-Xshare: dump
The main goals of this feature are mentioned below.
The new version Java 12 has very useful features, all are discussed above. These features are useful for the Java developers to write code simple manner using switch statements, to reduce the processing time using advanced garbage collectors, and also increase the processing speed for Java applications.
If you have any specific point to discuss, please write your query in the comment.
To become one of the most productive developers, keep wrestling your Java coding skills with new Java 12 features.