Java 10 is out !!!
As we, all know oracle has switched from a feature-driven release model to a time-based release model in which new version of JDK will be released every 6 months. Java 9 was released on 21st of September last year and 6 months later on March 20th 2018 Java 10 was released.
The major features are local type inference, Application CDS, and Root Certificates included in jdk. With these root certificate oracle aiming towards making open jdk to have enterprise features.
We have attempted to list the new features in Java 10 in brief.
- Local Variable Type Inference (JEP 286)
String customerStripeId = “cust_233424se342”;
Most important feature in JDK 10 is local variable type inference. Now you don’t need to specify the type of the variable as shown above. Compiler will detect the type automatically and generate it by looking at the right hand side statements. Which means you can use a reserved type var instead of the type as below.
var customerStripeId = “cust_233424se342”;
There is some constraint to use var, as the name says it is Local Variable Type Inference, which means you can use var only for local variables and for loop indexes.
- Application Class-data Sharing (JEP 310)
With application class data, sharing now we can reduce application start time and memory needed to store java objects and java classes. Class data sharing feature was introduced in java 5. It allowed some set of classes to a archive to preprocess it. When application was started, it was taking those classes from this archive, which led to faster startup of applications and less memory consumption. However, CDS was allowing archived classes to be loaded only by bootstrap loader.
Application class data sharing feature extends CDS and allows system class loader, platform class loader and custom class loaders to load archived classes. Which means now we can add more classes to shared archive and can reduce memory footprints of the application.
- Time Based Release versioning (JEP 322)
As java adopts to time based release model its version, number needs to be changed according to six-month release cycle. The new java version number format is like this.
$FEATURE :- it will be incremented every six month , in September 2017 Java 9 was released, after 6 month new version of JDK is released so its $FEATURE number is 10 in March 2018.
$INTERIM: – This will always be zero. This is reserved for future revision to release model.
$UPDATE: – This will be incremented after one month when $FEATURE is incremented. After that, it will be incremented every 3 months. March 2018 release is 10.0.0 after one month April 2018 release is 10.0.1 after 3 month July 2018 release will be 10.0.3 and so on.
- Garbage Collector Interface (JEP 304)
In earlier JDKs, implementing a new Garbage Collector was difficult, as they need to know where to find required source code. However, with the new clean Interface, it will be easier to implement new garbage collectors and it is easier to exclude a garbage collector from a build.
- Parallel Full GC for G1 (JEP 307)
Before Java 9 Parallel Garbage Collector was used as default collector. In Java 9 Garbage Collector First (GC1) was made default GC to avoid full garbage collection. Since it was stopping application while garbage collection, If GC1 is not able to release memory fast enough it will do a full Garbage collection with a single thread mark sweep compact algorithm. To avoid experiencing full garbage collection, GC1 full garbage collection is parallelized in Java 10.
- Remove native header generator tool (JEP 313)
Javah is now integrated with javac, which write native header files at compile time.as a result Javah tool is removed from the jdk.
- Heap allocation on alternative memory devices (JEP 316)
Hotspot vm can now allocate heap memory on alternative memory devices like nonvolatile dual inline memory module for low priority processes and DRAM memory for high priority processes.
- Experimental java based JIT compiler (JEP 317)
With this release java including graal a dynamic compiler written in java into jdk. It planning to use graal as an experimental JIT compiler on Linux/x64 platform.
To use graal as the compiler use these arguments
– XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler
- Root certificates (JEP 319)
With the JDK 10, a root certificate (Certification Authority) will be provided in included, which will be open sourced to reduce the difference between oracle jdk and open jdk. Cacerts keystore contains the root certificates that will establish trust in various security protocols. As of now, this Cacerts keystore is empty so some security components like TLS will not work unless you populate Cacerts root certificates.
- Combining JDK forest into single repository (JEP 296)
JDK 9 has many repositories like jaxws, jdk, langtools, root, corba, hotspot, jaxp and nashorn. Many of the classes in these repository are dependent on each other which makes it difficult manage source code, to solve this problem in jdk 10 all these repositories are combined into a single repository
- Improved bytecode generation for enhanced loop
Bytecode generation for enhanced for loop is enhanced by declaring the iterator outside of the for loop which allows null to be assigned when iterator is not required anymore. Since it is declared outside once it is assigned null, it is garbage collected. Example
List<String> studentList = new ArrayList<>();
- Comment tag (@summary) for summary of an API description
Java 10 introduced @summary document tag with which now we can specify which comment appears as document summary. Earlier summary ending was determined by period and space in the comment. Now we can explicitly specify which part should be used as summary. Example:-