Overview of New features in Java 10

Java 10 has been released on 20th March 2018. With this release Java has now moved to a 6 month release cadence. I.e. every six months there will be a new Java release containing all the features which have been planned for that release and were completed in time1 for that release. Let's take a look at the important new features introduced in Java 10. Where a feature has a detailed tutorial, the link to it is given along with the feature. Prominent new features in Java 10
  1. Local Variable Type Inference - This is one of the most significant and widely awaited changes in JDK 10. Java now supports local variable declaration using the keyword var. The type of this variable, instead of being declared explicitly, will instead be inferred from the value assigned to the variable. Read the tutorial on the var keywordClick to read tutorial: Java var Keyword: Local Variable Type Inference.
  2. Garbage Collector Interface - This change defines a garbage collector interface to improve the source code isolation of existing garbage collectors.
  3. Parallel Full GC for G1 - G1 garbage collector was made the default from JDK 9. This feature has been added to improve worst-case latencies of G1 by making full GC parallel.
  4. Consolidation of the JDK Forest into a Single Repository - This change is more relevant to open source contributors who work with the actual code running the JDK implementation. Until JDK 10, there were 8 Mercurial repositories holding JDK code viz.root, corba, hotspot, jaxp, jaxws, jdk, langtools, and nashorn. A commit across multiple repositories cannot be done in an atomic manner. JDK 10 solves this issue by bringing all these repositories' code in a single consolidated code repository to allow atomic commits across entire code.
  5. Application Class-Data Sharing - This feature extends the existing Class Data Sharing (CDS) to allow application classes to be stored in a shared archive. This change provides the benefits such as lower memory footprint and reduced startup times. Read the AppCDS tutorialClick to read tutorial: Java 10 Application Class-Data Sharing (AppCDS) Tutorial.
  6. Remove the Native-Header Generation Tool (javah) - The javah tool, which generated C header files for classes with native methods, has been removed. From JDK 8, the same headers can be generated by passing the -h option to the javac command, which writes them while compiling the classes. Read how to generate JNI headers with javac -hClick to read tutorial: Java 10 Removed javah: Generate JNI Headers with javac -h.
  7. Additional Unicode Language-Tag Extensions - This feature adds additional Unicode extensions of BCP 47 to java.util.Locale and related APIs - cu (currency), fw (first day of week), rg (region override) and tz (time zone). Read the tutorial on Unicode locale extensionsClick to read tutorial: Java 10 Unicode Locale Extensions: Currency, Week, Region.
  8. Heap Allocation on Alternative Memory Devices - With newer and cheaper memory type NV-DIMM, upcoming system designs can have multiple memory types onboard. This features enables the HotSpot VM to allow Java object heap on user specified memory devices like the NV-DIMM.
  9. Experimental Java-Based JIT Compiler - With this new feature, Graal(Java-based JIT Compiler) can be used as an experimental JIT compiler on Linux/x64 systems.
  10. Root Certificates - JDK's security certificates are stored in cacerts keystore. Before JDK 10, the default cacert keystore used to be empty. With this feature a default set of root Certification Authority certificates will be provided in the JDK. This will in turn allow critical security components(like TLS) to work out of the box in JDK builds.
  11. Time-Based Release Versioning - With six-month release cadence being adopted for JDK releases from JDK 10 onwards, this JEP(Java Enhancement Proposal) defines specific version numbering scheme to correctly specify the JDK 6-monthly feature release version along with various interim, update and patch release which may take place under that feature release. Read the tutorial on time-based release versioningClick to read tutorial: Java 10 Time-Based Release Versioning and Runtime.Version.
  12. Thread-Local Handshakes - With this feature JDK 10 allows executing a callback on a thread without performing a global VM safepoint. It allows stopping of individual threads in a cost effective manner instead of having to stop all threads.
Other important changes in Java 10 Besides the JEPs listed above, Java 10 also brought the following changes, which do not have JEPs of their own -
  1. API additions - New methods List.copyOf(), Set.copyOf() and Map.copyOf() create unmodifiable copies of collections, the collectors Collectors.toUnmodifiableList(), toUnmodifiableSet() and toUnmodifiableMap() collect streams into unmodifiable collections, and Optional.orElseThrow() was added as a clearer alternative to get(). Read the tutorial on Java 10 API additionsClick to read tutorial: Java 10 API Additions: copyOf, toUnmodifiableList & More.
  2. Docker container awareness - On Linux, the JVM now recognizes the CPU and memory limits set on a Docker container, and sizes its heap and thread pools according to the container's limits instead of the whole machine's. It can be turned off with -XX:-UseContainerSupport. The new options -XX:InitialRAMPercentage, -XX:MaxRAMPercentage and -XX:MinRAMPercentage set the heap size as a percentage of the available memory. This change was later backported to Java 8 (update 191).
  3. DateTimeFormatter.localizedBy() - A new method which applies a locale, including its Unicode extensions such as the time zone, to a date-time formatter. It is explained in the tutorial on Unicode locale extensions linked above.

1. https://mreinhold.org/blog/forward-faster