On March 17, 2020, Oracle announced the availability of Java 14 as part of its endeavour to enhance innovation by delivering new enhancements to developers and enterprises globally with a new feature release every six months. Oracle JDK (Java Development Kit) 14 represents more than two years of on-time six-month feature releases, bringing innovation and predictability to developers.

oracle-java-14-featuresIt boasts of new features to enhance new APIs for continuous monitoring of JDK Flight Recorder data, and extended availability of the low-latency Z Garbage Collector to macOS and Windows to name a few. Additionally, it also improves developer productivity.

Here are the top features of the recently launched Oracle Java14 that will bring innovation and predictability to developers.

Pattern Matching for instance of: Available in preview mode, this new feature aims to improve Java by providing users pattern matching for the instance of operator. Already available in other languages, pattern matching makes it possible to express the logic of a program in a much secured and concise way. Pattern matching in instance of will significantly minimize the overall number of explicit cases in Java. A point worth mentioning is that instance Of will only match when the object is not null and is only assigned to str.

Switch Expression: Oracle Java14 offers an extended switch statement, which can be used as an expression with the help of the arrow (->), and also allows you to yield/return the value.

Packaging Tool (Incubator): This refers to a packaging feature designed to simplify the installation process, which depends on numerous dependencies. Often it may not be enough to provide a single JAR file; it must provide an installable kit appropriate for the local/native. A packaging tool can also help to fill the gaps left by other technologies.

The jpackage tool bundles a Java application into a platform-specific package containing all the dependencies required. As a set of ordinary JAR files or as a collection of modules. The supported platform-specific package formats are:

  • Linux: deb and rpm
  • macOS: pkg and dmg
  • Windows: msi and exe

Enhanced Mapped Byte Buffer: An enhanced Mapped Byte Buffers will allow developers to load the portion of file data in Non-Volatile Memory (NVM). Non-Volatile Memory or Non-Volatile storage is a computer memory, where data would still remain even if the power is turned off. The only API change that is required is a new enumeration employed by File Channel clients to request mapping of a file located on an NVM-backed file system rather than a conventional, file storage system.

Helpful Null Pointer Exceptions: Java14 features a much improved Null Pointer Exceptions exception message generated by JVM. This will provide developers and support staff critical about the premature termination of a program. Since NPEs can occur frequently and across a program, noticing it and recovering it can be a complex task. As a result, developers rely on the JVM to pinpoint the source of an NPE when it occurs.

NUMA-Aware Memory Allocation for G1: Non-Uniform Memory Access (NUMA) is a way of configuring cluster of micro-processor into a multiprocessing system. This facilitates the sharing of memory locally and enhancing performance. Java 14 features NUMA-aware memory allocation feature to improve G1 performance on large machines. G1’s heap is organized as a collection of fixed-size regions.

JFR Event Streaming: Java 14 includes an API, by which the data collected by the JDK Flight Recorder (JFR) will continuously monitor in-process and out-of-process applications. Developers can also record the same set of events as in the non-streaming way, with overhead less than 1% if possible. Therefore, event streaming would be performed at the same time as non-streaming.

Records (Preview): The preview language offered by JDK14 is used to compact the class declaration syntax with record. This will remove the burden of writing several low-value, repetitive code for a simple data carrier class responsibly: constructors, accessors, equals(), hashCode(), toString(), etc.

Deprecated the Solaris and SPARC Ports: Java14 has deprecated Solaris / SPARC, Solaris / x64, and Linux / SPARC ports in order to remove them in the future. This will allow contributors in the OpenJDK community to accelerate the development of new features to move the platform forward.

Removal of Concurrent Mark Sweep (CMS) Garbage Collector: Java 14 has removed the CMS Garbage Collector. Subsequently, this update will deactivate CMS compilation, remove content of the gc / cms directory from the source tree, and remove CMS-only options.

Updated JEP 364 – ZGC on macOS: JEP (Java Enhancements Proposals) 364 is similar to JEP 365 with an additional feature that it offers the Z Garbage Collector (ZGC) for MacOS. It ports the ZGC garbage collector to macOS. Part of the JEP is also the collector’s functionality for freeing unused device memory, as stated in JEP 351, this has been since Java 13. The macOS implementation of ZGC contains two parts:

  • Support for multi-mapping memory on macOS.
  • Support in ZGC for discontiguous memory reservations.

JEP 365 – ZGC garbage collector on Windows: EP 365 offers the ZGC for Windows. Most of the ZGC code base is platform independent and does not require Windows-specific changes. Alternatively, implementing ZGC on Windows requires the support of multi-mapping memory, mapping paging-file backed memory into a reserved address space, mapping and unmapping arbitrary parts of the heap, and committing and uncommitting arbitrary parts of the heap.

JEP 366 – Deprecate the ParallelScavenge + SerialOld GC Combination: JEP 366’s garbage collector seeks to deprecate the combination of the Parallel Scavenge and serial old garbage collection algorithms. Besides depreciating the combination -XX:+UseParallelGC-XX :- UseParallelOldGC, the -XX: UseParallelOld GC option is also deprecated as it is used to deselect the old-generation parallel GC; subsequently enabling the serial old generation GC. As a result, any intentional use of the option UseParallelOldGC will reflect the deprecation warning.

Updated Text Blocks: As part of its offering to the end users, Java 14 includes an updated Text Blocks which is offered as a preview feature again in Java 14 with the aim of Text Blocks becoming standard in all future JDK releases. Text Blocks simplify the process to express strings that span several lines of source code. It enhances the readability of strings in Java programs that denote code written in non-Java languages. Furthermore, it supports the migration from string literals. This is possible by preconditioning that any new construct can express the same set of strings as a string literal, interpret the same escape sequences, manipulate the same ways as in the case of a string literal.

Foreign-Memory Access API (Incubator): Many popular Java libraries and programs have access to foreign memory, such as Ignite, MapDB, Memcached, and Netty’s ByteBuf API. This will allow developers to avoid the cost and unpredictability associated with garbage collection (especially when maintaining large caches), share memory across multiple processes, and serialize and deserialize memory content by mapping files into memory (via, e.g., mmap). Additionally, an effective Java API is to be introduced in the Java 14 JDK, which enables Java applications to safely and efficiently access foreign memory stored outside the Java heap. The foreign-memory access API introduces three main abstractions: MemorySegment, MemoryAddress and MemoryLayout.

Conclusion: Java 14 offers developers access to features that they would otherwise be waiting years to get their hands on. It features several enhancements that will significantly improve developer productivity. It also includes the first major content to come from projects like Project Panama, with a Foreign-Memory Access API enhancement (JEP 370), and continuing improvements from Project Amber, with Pattern Matching (JEP 305) and Records (JEP 359).

Share this post
Recent Posts

Leave a Comment

Start typing and press Enter to search