What Features Would You Want to See in Java 12?
What Features Would You Want to See in Java 12?
Want to learn more about the proposed features coming to Java 12? Click here to learn more about changes to switch expressions and raw string literals.
Join the DZone community and get the full member experience.Join For Free
One of the main reasons Java is so popular is because of its platform independence, which simply means that a Java program can run on many different types of computers. This language was designed for flexibility, allowing developers to write code that could run on any machine — no matter what the architecture or platform it is. In addition, it is very easy to understand.
JDK 11 is now available for general use, and Java is planning to launch its JDK 12 very soon. Now, it's a good time to start looking more closely at JDK 12.
So, in this article, we are discussing the expected features coming to Java 12. Although Java 11 arrived last month, Java 12 is still in its release process and is expected on March 19, 2019. Let's get into it!
Java 12 is expected to arrive with updated switch expressions. The capability of beta switch expressions would simplify coding by extending the switch statement so it can be used as either a statement or an expression. It will enable both forms to use traditional or simplified scoping over the control behavior. These changes will simplify the code, and now, pattern matching of a switch can also be used.
Java developers are building pattern matching so that the existing problems of the switch statement can be fixed. It also includes the default control flow behavior of switch blocks, default scoping of switch blocks, in which the block is treated as one single scope, and switch working only as a statement. In the current Java switch statement, it follows languages such as C++ and, by default, supports semantics. This control flow has been beneficial for writing low-level code. But as a switch is used in higher-level context, its error-prone nature begins to outweigh its flexibility.
Raw Strings Literals
It appears that raw string literals are coming to Java development India. It is believed that Java remains one of the small groups of contemporary programming languages that do not provide language-level support for raw strings. The JEP 326 summary provides an overview of the proposed Java string literals.
The beta raw strings literals would span multiple lines of source code while not interpreting escape sequences. This time Java builders have multiple goals for this new version of Java 12, like:
- The main feature to express the same strings as traditional string literals.
- Library support to copy the current Java string-literal interpretation of escaped and manage left-margin trimming.
- Making it easier to express a sequence of characters in a readable form, without Java simplification in supplying strings targeted for grammars other than Java.
Multi-line string literals have been long desired in java from a long time. In JEP 326 we can see, there are several examples of how raw string literals would make it easier to implement common things in Java and these example uses include multilevel strings, operating system file paths and SQL statements.
You must know that JDK 326 is still a candidate and is not associated with a particular release of Java. We will see multi-line Java strings literals coming to Java in a future release.
Improved CDS, Garbage Collection, and Startup
In the latest Java update, they are planning to call for enhancing the JDK build process to create a default class data-sharing (CDS) archive using the default class list on the 64-bit platform. The main goal is to include out-of-the-box startup time and remove the need to run-xshare: dump to benefit from the CDS.
For better garbage collection, additional command-line options may be included. Users with more advancement requirements, such as a custom class list that include application classes and several garbage-collection configurations, still will be able to create a custom CDS archive.
Some Other JDK 12 Preview Features
JDK 12 JEP (Enhancement Proposals) Candidates
To create a new tool based on the JavaFX Java packager tool for packaging self-contained Java applications.
Limit Speculative Execution
This is also an important preview feature of Java. To help developers and deployers to defend against speculative-execution vulnerabilities, this is done by providing a means to limit speculative execution and not a complete defense against all forms of speculative execution.
One AArch64 Port
Java 12 will have just one port instead of two for ARM processors. The plan is to remove all arm64 port-related sources while retaining the 32-bit ARM port and the 64-bit AARCH port. This will help focus on a single 64-bit ARM implementation and eliminate duplicate work to hold two ports. In the current version, two 64-but ARM ports are in the JDK.
Java has one of few contemporary languages without language-level support for raw strings. The new proposal would not introduce any new string operators. For now, the switch expressions proposal is the only technology listed as targeting JDK 12. Thanks for reading!
Opinions expressed by DZone contributors are their own.