Home  >  Core Java

What are New Features in Java 12

By Arvind Rai, June 20, 2021
Find the new features and enhancements introduced in Java 12 point-by-point.
1. JDK 12 supports Unicode 11 that includes 684 new characters, 11 new blocks and 7 new scripts.

2. On Linux platform, now we can assign POSIX_SPAWN to following Java property.
jdk.lang.Process.launchMechanism = POSIX_SPAWN 
The POSIX_SPAWN is used for spawning child processes. The default launch mechanism on Linux is unchanged i.e. VFORK.

3. In JDK 12, a new package java.lang.invoke.constant has been added that introduces an API to model nominal descriptions of class file and run-time artifacts.

4. In JDK 12, the NumberFormat has been added with new support to format numbers in its compact format. Compact number formatting is the representation of a number in short or human readable form. For example, for the Locale.UK, the compact format for 1000 is 1k and for 1000000, it is 1M.
NumberFormat fmt = NumberFormat.getCompactNumberInstance(Locale.UK, NumberFormat.Style.SHORT);
String result = fmt.format(1000); //1K
System.out.println(result);	
result = fmt.format(1000000); //1M
System.out.println(result);	




5. JDK 12 supports square character for Japanese new era that begins from May, 2019. The Unicode Consortium has reserved the code point as U+32FF for that square character.

6. In JDK 12, Z Garbage Collector supports class unloading concurrently. This feature is enabled by default but can be disabled using command line option -XX:-ClassUnloading .

7. Now old generation of Java Heap can be allocated on alternate memory devices such as NVDIMM memory. NVDIMM is a RAM for computers. It is a non-volatile dual in-line memory module (NVDIMM) that retains its contents even when electrical power is removed. To enable this feature i.e. allocation of old generation of Java Heap on NVDIMM, use the command -XX:AllocateOldGenAt=<path>. Once enabled, the young generation objects are placed in DRAM only and old generation objects are stored in NVDIMM. DRAM is Dynamic RAM. At any point the size of heap specified by -Xmx will be greater than the total memory committed in DRAM and NVDIMM.

8. A fix is done for OS detection to identify Windows Server 2019 correctly. Prior to this, fix Windows Server 2019 was recognized as Windows Server 2016 and hence we get incorrect values in os.name property and hs_err_pid file.

9. A command line flag -XX:+ExtensiveErrorReports has been added to produce extensive report related to crash as reported in the hs_err<pid>.log file.

10. Now we can provide "disallow" and "allow" token options to the java.security.manager system property. When we assign "disallow" at the start of JVM, security manager is not set and we cannot use System.setSecurityManager. This will increase the run-time performance for the applications that never set a security manager.

11. A new -groupname option has been added to keytool -genkeypair so that a user can specify a named group when generating a key pair.

12. 4 new Java Flight Recorder (JFR) security events have been added to the security library area. That are jdk.SecurityPropertyModification, jdk.TLSHandshake, jdk.X509Validation and jdk.X509Certificate .

13. New system and security properties have been added to enable users to customize the generation of PKCS #12 keystores.

14. New TLS cipher suites using the ChaCha20-Poly1305 algorithm have been added to JSSE. These cipher suites are enabled by default.

15. The dns_canonicalize_hostname flag in the krb5.conf configuration file is now supported by the JDK Kerberos implementation.

16. In Java 12, switch statement has been enhanced to use as expression as preview feature. Now we can use switch as statement as well as expression.
Find the sample code to use switch as expression.
int day = 2;
switch (day) {
  case 1 -> System.out.println("Monday");
  case 2 -> System.out.println("Tuesday");
  case 3 -> System.out.println("Wednesday");
} 
Output is Tuesday .

Reference

JDK 12 Release Notes
POSTED BY
ARVIND RAI
ARVIND RAI











©2021 concretepage.com | Privacy Policy | Contact Us