Java 10

In this post, we will talk about Java 10. We will see what is new in Java 10.

 

Introduction

They released Java 10 or JDK on March 2018. It is one of the major Java updates with a lot of new changes for the developers.  New changes and new APIs added to the JDK, also few APIs got removed and importantly one new release process is introduced.  Now, we can get a new Java release every 6 months.  Not only short term, but we will also get one new LTS release every three years. In this post, we will learn the major changes in Java 10,  newly introduced features and also the removed features and APIs. Let’s have a look:

 

1. JEP 286: Local Variable Type Inference:

Before Java 10, we need to use specify the type of a variable while initializing it. For example, if you want to declare an ArrayList, do it like below for Java 9 and all other prior versions:

ArrayList<String> students = new ArrayList<String>();

Starting from Java 10, we can initialize it using ‘var’ keyword :

var students = new ArrayList<String>();

The compiler will check the right-hand side of the declaration and infers the type. It can use a local variable type inference to initialize local variables as indices in the enhanced for-loops and for local declared in the traditional for loops. ‘var‘ is not a keyword. It is a reserved type name, i.e. we can use it as a package name, method name or as a variable name but we can not use it as an interface or class name.

 

2. JEP 296: Merge the JDK Forest into a Single Repository:

Previously, the code base of JDK was into different repositories. For example, they broke Java 9 into  repositories: root, corba, hotspot, jaxp, jaxws, jdk, langtools, and nashorn. Maintaining different repositories looks like a good practice, but it caused several problems. For example, it was not possible to commit code in an atomic manner on all repositories.

Maintaining 9 repositories requires 9 times more effort than a single repo! To simplify the development process and to overcome these types of problems, JEP 296 was implemented and they combine all repositories into a single repository starting Java 10.

 

3. JEP 304: Garbage-Collector Interface

This JEP is for improving the garbage collection process. The garbage collector was scattered in different places. Implementing a new GC was difficult, and it required a knowledge of all various places. Also, it was difficult to exclude a specific GC at build time. JEP 304 introduced a clean garbage collector interface with the aim to improve the source code isolation of different garbage collectors.

 

4. JEP 307: Parallel Full GC for G1

Before JDK 9, the parallel collector was the default Garbage Collector. Starting JDK 9, G1 is the default GC. One of the main problems of G1 was that it takes occasionally a long time to perform full GC. Full GC collects every region in a heap. The main cause of this problem was that Full GC ran in a single thread until Java 10. This JEP was to improve the performance of full GC by allowing full GCs to run on multiple threads in parallel.

 

5. JEP 310: Application Class-Data Sharing

During start time, JVM loads all the classes to the memory. The boot time will increase if there is a lot of jars to load. Application class-data sharing feature allows us to create a shared environment for sharing data between multiple Java virtual machines. If enabled, JVMs will use the shared memory to read and store different properties like loaded classes, file indexes, AOT compiled code, etc. It improves the startup time of a JVM and also reduces the memory usages.

 

6. JEP 312: Thread-Local Handshakes

This improvement is not for developers and it is an improvement of the VM. It allows the JVM to stop individual thread without stopping all by introducing a new way to execute a callback on threads without performing a global VM safe point.

 

7. JEP 313: Remove the Native-Header Generation Tool

javah used to generate native header files while compiling the code. Java 8, brough this feature in to JDK. They used this JEP to remove the javah completely. javah is a separate tool, and it makes no sense of using it if javac can do the same.

 

8. JEP 314: Additional Unicode Language-Tag Extensions

Java SE 7 introduced language tags. As of Java SE 9, the only  supported language-tag extensions are ‘ca’ and ’nu’. This changes enhanced java.util.Local and a few others APIs and added four new language-tag extensions:

  1. cu (currency type)
  2. fw (first day of the week)
  3. rg ( region override)
  4. tz (time zone)

Following APIs got changed for this JEP:

java.text.DateFormat::get*Instance              
java.text.DateFormatSymbols::getInstance
java.text.DecimalFormatSymbols::getInstance
java.text.NumberFormat::get*Instance
java.time.format.DateTimeFormatter::localizedBy
java.time.format.DateTimeFormatterBuilder::getLocalizedDateTimePattern
java.time.format.DecimalStyle::of
java.time.temporal.WeekFields::of
java.util.Calendar::{getFirstDayOfWeek,getMinimalDaysInWeek}
java.util.Currency::getInstance
java.util.Locale::getDisplayName
java.util.spi.LocaleNameProvider

 

9. JEP 316: Heap Allocation on Alternative Memory Devices

This JEP is to enable the HotSpot VM to allocate the Java object heap on an alternative memory device. The user can specify the memory device like NV-DIMM. The main advantage of this method is to allow low priority processes to use cheap memories. This will allow high memory applications such as big data to use cheap and large capacity memories like NV-DIMM instead of DRAM.

 

10. JEP 317: Experimental Java-Based JIT Compiler

Java 9 has introduced one new Ahead of time (AOT) compiler to the open JDK for improving the startup time of the java applications. This JEP allows us to enable Graal JIT compiler or just-in-time compiler that uses the AOT compilation and interpretation on Linux/x64 platform. Note that Graal is an experimental feature, and I do not recommend it to use in production. We can use the following arguments to enable it .

-XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler

 

11. JEP 319: Root Certificates

To make OpenJDK build more appealing to the developers, this JEP provided a default set of root Certificate Authority (CA) certificates in the JDK. This also makes the Open JDK build and Oracle JDK build looks same. Previously, critical security components like TLS didn’t work by default in the OpenJDK builds. It was required to configure a few root certificates manually. The default root CA certificates eliminated this problem in the new JDK build.

 

12. Time-Based Release Versioning

It starts a new version-string naming scheme from Java 10. The version number of the new scheme looks like as below:

$FEATURE.$INTERIM.$UPDATE.$PATCH
  1. $FEATURE: It is the feature release counter. Increment for every feature release.
  2. $INTERIM : It is the interim-release counter. Incremented for non-feature release that contains only compatible bug fix and enhancements.
  3. $UPDATE : Update release counter,  used mainly for updates with a security issue fixing, regressions, and bug fix in newer features.
  4. $PATCH : This number incremented only for emergency critical issue release.

 

13. Newly added APIs:

Java 10 has introduced few new APIs. You can check here for the details. Following are few notable new additions:

  • A new method orElseThrow is added to the Optional class that can be used instead of get method.
  • They introduce few new APIs to create an Unmodifiable collection
    • copyOf ( added to List, Set and Map)
    • toUnmodifiableList ( added to Collectors class in the Stream package)
    • toUnmodifiableSet ( added to Collectors class in the Stream package)
    • toUnmodifiableMap ( added to Collectors class in the Stream package)
  • A new option added for the use of multiple stylesheets in the generated JavaDoc. ‘v–add-stylesheet’ is the command line option for that.
  • One more option ‘--overridden-methods=value’ is also added to the Javadoc. If a class overrides inherited methods without changing any specification, I can use this option to group these methods with other inherited methods, instead of document them with other methods in the class.

 

14. Removed Features and options

Following are a few striking features that got removed in Java 10:

  • Removed support for old LookAndFeel.
  • Runtime.getLocalizedInputStream and Runtime.getLocalizedInputStream have been removed.
  • Common DOM APIs com.sun.java.browser.plugin2.DOM, and sun.plugin.dom.DOMObject is removed.
  • FlatProfiler deprecated in Java 9 and removed in Java 10.
  • policytool security tool got removed

You can find the full list and details of all removed APIs here

 

Summary

We have checked different new features added in Java 10 and also an overview of the newly added APIs and removed features. If you want to add anything to this post, drop a comment below.

Java Development Journal

Hello!! Welcome to the Java Development Journal. We love to share our knowledge with our readers and love to build a thriving community.

follow me on:

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of