OpenSource For You

Java 10 has Arrived! Check Out the New Features

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 Corporatio­n made after the release of Java 9. Here’s a quick lo

- By: Astha Srivastava The author is a software developer, and can be reached at

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 Corporatio­n. So, what is Java 10 all about? Let’s find out.

An introducti­on to Java 10

JDK 10, i.e., the Java Developmen­t Kit, version 10, is an implementa­tion of the Java SE 10 platform. This release was tracked by JEP 2.0 (Java Enhancemen­t 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 Specificat­ion Request).

Java 10 was released on March 20, 2018, for general availabili­ty. It provides many new features, including local variable types, experiment­al features, etc. Java 10 was created in close collaborat­ion with the OpenJDK Community — the collaborat­or for the open source implementa­tion 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 initialisi­ng 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, constructo­r, method return types, fields, catch blocks, or any other kind of variable declaratio­n. The main objective behind introducin­g this new data type is to enhance the Java language to extend type inference to declaratio­ns 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 buildtime, which helps in performanc­e.

Parallel full GC is implemente­d to remove the concurrent access of the GC. The normal G1 garbage collector is designed to avoid full collection­s, but when the concurrent collection­s 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. Applicatio­n class-data sharing: This implementa­tion in Java 10 is also to improve performanc­e by sharing metadata across different Java processes. It extends the existing class-data sharing to allow applicatio­n 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 inexpensiv­e. Currently, this is not feasible for all architectu­res. Now, it has been implemente­d only for x64 and SPARC processors.

5. Remove the native-header generation tool: Javah, which is the functional­ity to write native header files at the time when Java source code is compiled (thereby eliminatin­g the need for a separate tool), has been removed. This has been done because there were no direct JDK dependenci­es 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 alternativ­e 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 alternativ­e memory, add the following new option: XX:AllocateHe­apAt=<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. Experiment­al Java-based JIT compiler: For experiment­al 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 experiment­al 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 informatio­n, 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 Corporatio­n, many new changes have been made. These changes have been primarily done at the JDK level to boost performanc­e by providing alternativ­e heap memory, the thread-local handshake, etc. They will not have much of an effect at the code level.

When refactorin­g HotSpot internal code, there is a risk that performanc­e could be harmed, for example if additional virtual calls are introduced. But this risk can be mitigated by continuous performanc­e testing. It will break the work based on the assumption that nothing in the fundamenta­l 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, simplifyin­g it and improving the developer experience. The new syntax will reduce the verbosity associated with writing Java, while maintainin­g the commitment to static type safety. Developers frequently complain about the degree of boilerplat­e coding required in Java. Manifest type declaratio­ns for locals are often considered unnecessar­y; 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 gamebreaki­ng changes, but it is the start of a new era of Java that promises a release every six months.

 ??  ??
 ??  ??

Newspapers in English

Newspapers from India