Java 10 has Arrived! Check Out the New Features

1
7104

Java 10 was released just over a few months ago and experts are still analysing its salient features. It has come out on schedule, true to the promise of a six-month release cycle that Oracle Corporation made after the release of Java 9. Here’s a quick look at its features.

Hurray! Java 10 is out! Most of us are still not done with exploring Java 9, which was released on September 21, 2017, and exactly six months later, Java 10 has been released by Oracle Corporation. So, what is Java 10 all about? Let’s find out.

An introduction to Java 10

JDK 10, i.e., the Java Development Kit, version 10, is an implementation of the Java SE 10 platform. This release was tracked by JEP 2.0 (Java Enhancement Proposal), which contains features to be developed in the specified release. Java 10 is available to the public and can be downloaded from Oracle’s website. This release of Java is related to JSR 383 (Java Specification Request).

Java 10 was released on March 20, 2018, for general availability. It provides many new features, including local variable types, experimental features, etc. Java 10 was created in close collaboration with the OpenJDK Community — the collaborator for the open source implementation of the Java SE platform.

What are these new features?

Given below are the main new features introduced in Java 10. Let us discuss them in detail.

1. Local-variable type inference: Java 10 has introduced a new way of declaring and initialising local variables with the keyword ‘var’. So, it uses:

var list = new ArrayList<String>(); // infers ArrayList<String>

…instead of:

List<String> list = new ArrayList<String>();

This is restricted to local variables, which are indexes declared in loops. This feature is not available for method, constructor, method return types, fields, catch blocks, or any other kind of variable declaration. The main objective behind introducing this new data type is to enhance the Java language to extend type inference to declarations of local variables.

2. Garbage Collector interface and parallel full GC for G1: The Garbage Collector interface has been introduced to improve the source code isolation of different garbage collectors (GCs), hence providing better modularity for internal GC. It is added as an isolation for GCs at build-time, which helps in performance.

Parallel full GC is implemented to remove the concurrent access of the GC. The normal G1 garbage collector is designed to avoid full collections, but when the concurrent collections can’t access memory that fast, then an error, ‘GC Full’, will occur. Henceforth, in Java 10, parallel threads will be used to execute GC commands.

3. Application class-data sharing: This implementation in Java 10 is also to improve performance by sharing metadata across different Java processes. It extends the existing class-data sharing to allow application classes to be placed in the shared archive, to reduce the footprint and the startup time.

4. Thread-local handshakes: A handshake operation is a callback executed for each thread in Java when that thread is in a safe state (safepoint). The thread-local handshake introduces a way to execute a callback on threads without performing a global VM safepoint, which will make the process for stopping individual threads possible and inexpensive. Currently, this is not feasible for all architectures. Now, it has been implemented only for x64 and SPARC processors.

5. Remove the native-header generation tool: Javah, which is the functionality to write native header files at the time when Java source code is compiled (thereby eliminating the need for a separate tool), has been removed. This has been done because there were no direct JDK dependencies on the Javah tool.

6. Additional Unicode language-tag extensions: This feature adds some more Unicode language tags. It enhances the java.util.Locale package and the related APIs to implement additional Unicode extensions of the ‘BCP (Best Current Practice) 47’ language tags.

7. Heap allocation on alternative memory devices: In this feature, the focus is on heap memory allocation. Sometimes, because of multiple tasks running at the same time, heap memory gets full and leads to an error. To solve that problem, heap memory can now be allocated on other memory devices such as an NV-DIMM.

To allocate the heap in an alternative memory, add the following new option:

XX:AllocateHeapAt=<path>.

This option will map the memory to the path of the file system, and use memory mapping to achieve the desired result of allocating the object heap on the memory device.

8. Experimental Java-based JIT compiler: For experimental purposes, a new JIT (Just in Time) compiler has been introduced — Graal, which is to be used on the Linux/x64 platform. Graal is based on the experimental Ahead-of-Time (AOT) compiler introduced in JDK 9.

9. Time-based release versioning: A version number is a non-empty sequence of elements separated by period characters (U+002E). A version number never has trailing zero elements. This is based on semantic versioning, which defines version numbers and the way they change, conveying meaning about the underlying code and what has been modified from one version to the next.

The versioning format in Java 10 is used like version number, $VNUM, possibly followed by pre-release, build and other optional information, as shown below:

$VNUM(-$PRE)? \+$BUILD(-$OPT)?

$VNUM-$PRE(-$OPT)?

$VNUM(+-$OPT)?

The pros and cons of Java 10

In this new release from Oracle Corporation, many new changes have been made. These changes have been primarily done at the JDK level to boost performance by providing alternative heap memory, the thread-local handshake, etc. They will not have much of an effect at the code level.

When refactoring HotSpot internal code, there is a risk that performance could be harmed, for example if additional virtual calls are introduced. But this risk can be mitigated by continuous performance testing. It will break the work based on the assumption that nothing in the fundamental design of G1 prevents a parallel full GC. The fact that G1 uses regions will most likely lead to more wasted space after a parallel full GC, than for a single threaded one.

What’s in it for developers?

For developers, the main change is the new local data type ‘var’. This new feature will add some syntactic sugar to Java, simplifying it and improving the developer experience. The new syntax will reduce the verbosity associated with writing Java, while maintaining the commitment to static type safety. Developers frequently complain about the degree of boilerplate coding required in Java. Manifest type declarations for locals are often considered unnecessary; hence, using var is much better compared to declaring any other data type. Local variable type inference allows a similar effect in less tightly structured APIs.

Ever since the release of Java 9 last September, the whole platform has changed. Java 9 introduced us to modular Java and many other features, as well as the idea that Java would be switching to a six-month release cycle. Java 10 perhaps doesn’t offer the biggest and most game-breaking changes, but it is the start of a new era of Java that promises a release every six months.

1 COMMENT

  1. Another use case is where many JVM processes are running on the same machine. In this case, it might be good to have processes that require a lower read latency map to DRAM and the remaining processes mapped to NVDIMM.

LEAVE A REPLY

Please enter your comment!
Please enter your name here