10 new features that you need to know about Java 10

Ameya Pandilwar
TechnoWriter
Published in
4 min readMar 24, 2018

1. Local Variable Type Inference (JEP 286)

Similar to JavaScript, Kotlin, and Scala, now Java will also have a var keyword that allows you to declare a local variable without specifying its type. The type will be inferred from context. For example, when you say var name = "Java", the compiler will already know the type is String.

I don’t know how useful this will be, as I am quite used to seeing int i = 5 or String name = "Java", and I liked the type information present in the variable declaration line, but it looks like Java is going the way Scala and Kotlin are and trying to incorporate changes from there.

Also note that the var keyword can only be used for local variables, i.e. variables inside methods or code blocks — you cannot use it for member variable declaration inside the class body.

And, finally, it doesn’t make Java a dynamically typed language like Python. Java is still a statically typed language, and once the type is assigned, you cannot change it. For example, var name = "Java" is OK, but then name = 3; is not OK.

This is one of the most eye-catching features of Java 10. It reduces the amount of boilerplate code needed to declare local variables in Java.

It’s not so obvious from this simple example, but consider where a method returns a complex list type that requires a lot of angle brackets and generics to declare the type. This really saves time in those cases:

var list = List.of(1, 2.0, "3")

Here, the list will be inferred as List<? extends Serializable & Comparable<..>>, which is an intersection type.

2. Time-Based Release Versioning (JEP 322)

With the JDK 10 release, Java has adopted a new release cadence — every six months. There is a lot of debate over whether this is a practical approach. Many are saying that it’s good to get new features every six months, though many complain that it’s too little a time to adopt a JDK.

Anyway, this will be the way forward, with an LTS release every three years considered a major release. Also, the Update element will increment one month after the Feature element is incremented, so the April 2018 Java release will be JDK 10.0.1, the July 2018 release will be named JDK 10.0.2, and so on.

3. Garbage-Collector Interface (JEP 304)

This is one of the more interesting and useful Java 10 features. It increases code isolation of different garbage collectors and introduces a clean interface for them. This means it is easier to exclude a GC from a JDK build while also making it easier to add a new GC without it affecting the code base.

4. Parallel Full GC for G1 (JEP 307)

Here is another interesting feature that improves G1 worst-case latencies by making the full GC parallel.

In Java 9’s release, G1 was made the default GC for the JVM, which was designed to avoid full GC. But when the concurrent collections couldn’t reclaim memory quickly enough, it would end up falling back on a full GC, and that creates a problem. This change will parallelize the full GC algorithm so that in the unlikely event of a G1 Full GC, the same number of threads can be used as in the concurrent collections to improve overall performance.

5. Heap Allocation on Alternative Memory Devices (JEP 316)

This sounds like a really cool feature. It enables the HotSpot VM to allocate the Java object heap on an alternative memory device, specified by the user.

For example, this feature makes it possible to assign lower priority processes to use the NV-DIMM memory, and instead only allocate the higher priority processes to the DRAM in a multi-JVM environment.

6. Consolidate the JDK Forest Into a Single Repository (JEP 296)

This new Java 10 feature is all about housekeeping. It will combine the numerous repositories of the JDK forest into a single repository.

7. Root Certificates (JEP 319)

This is another important change Java 10 is bringing. If you remember, JDK 10 was created with the close collaboration with OpenJDK, and this is evident from this feature. It will provide a default set of root Certification Authorities, making OpenJDK builds more appealing to developers.

It also aims to reduce the difference between the OpenJDK and Oracle JDK builds. Critical security components such as TLS will now work by default in OpenJDK builds

8. Experimental Java-Based JIT Compiler (JEP 317)

This is another interesting feature that enables the Java-based JIT compiler, Graal, to be used as an experimental JIT compiler on the Linux/x64 platform. Graal was already added back in Java 9, but now you can enable it with the following JVM arguments:

-XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler

If you don’t know Graal, it is a new Java-based JIT compiler, which is the basis of an experimental Ahead-of-Time (AOT) compiler. However, this is in an experimental stage, and you should probably not use it in production.

9. Thread-Local Handshakes (JEP 312)

This feature lays the groundwork for improved VM performance by making it possible to execute a callback on application threads without performing a global VM savepoint. This would mean that the JVM could stop individual threads and not just all of them.

There are several small improvements done as part of this feature or JEP 312 to improve VM performance, e.g. some memory barriers have been removed from the JVM and biased locking is improved by only stopping individual threads for revoking biases.

10. Remove the Native-Header Generation Tool (JEP 313)

This is another feature that focuses on housekeeping. It will remove the javah tool from the JDK, a separate tool to generate header files when compiling JNI code, as this can be done through javac.

Let us know in the comments below about which features are you excited about and also the ones you are looking forward to.

--

--

Ameya Pandilwar
TechnoWriter

εɴɢiɴεεʀ • appʀεɴευʀ • ғʀεεlaɴᴄεʀ