So Java SE 10 (JDK 10) was released 20th March 2018. JDK 10 is a production-ready implementation of the Java SE 10 Platform Specification, as specified by JSR 383.
Java SE 10 provides a number of new features, including
- Local variable types,
- Parallel full GC for G1,
- Experimental features such as the Java-Based JIT Compiler.
- etc
So this blog can be divided into following categories:
- What’s New in JDK 10 – New Features and Enhancements
- Removed Features and Options
- Deprecated Features and Options
What’s New in JDK 10 – New Features and Enhancements
- Local-Variable Type Inference
Now the LOCAL variables can also be declared without declaring their type
i.e
var list = new ArrayList(); // infers ArrayList
var stream = list.stream(); // infers Stream
- Optional.orElseThrow() Method
A new method orElseThrow
has been added to the Optional
class. It is synonymous with and is now the preferred alternative to the existing get
method.
Optional opEmp = employees
.stream()
.max(new Comparator() {
Override public int compare(Employee e1, Employee e2) {
if (e1.getSalary() > e2.getSalary()) {
return 1;
} else if (e1.getSalary() < e2.getSalary()) {
return -1;
}
return 0;
}
});
System.out.println(opEmp.get());
So the above code will give us the Employee who has highest Salary. But the same can also be done with
System.out.println(opEmp.orElseThrow());
- APIs for Creating Unmodifiable Collections
Several new APIs have been added that facilitate the creation of unmodifiable collections. The List.copyOf
, Set.copyOf
, and Map.copyOf
methods create new collection instances from existing instances. New methods toUnmodifiableList
, toUnmodifiableSet
, and toUnmodifiableMap
have been added to the Collectors
class in the Stream package. These allow the elements of a Stream to be collected into an unmodifiable collection.
- JEP 307 Parallel Full GC for G1
Improves G1 worst-case latencies by making the full GC parallel. The G1 garbage collector is designed to avoid full collections, but when the concurrent collections can’t reclaim memory fast enough a fall back full GC will occur. The old implementation of the full GC for G1 used a single threaded mark-sweep-compact algorithm. With JEP 307 the full GC has been parallelized and now use the same amount of parallel worker threads as the young and mixed collections.
- Bytecode Generation for Enhanced for Loop
Bytecode generation has been improved for enhanced for loops, providing an improvement in the translation approach for them. For example:
List data = new ArrayList(); for (String b : data);
The following is the code generated after the enhancement:
{ /*synthetic*/ Iterator i$ = data.iterator(); for (; i$.hasNext(); ) { String b = (String)i$.next(); } b = null; i$ = null; }
Declaring the iterator variable outside of the for loop allows a null to be assigned to it as soon as it is no longer used. This makes it accessible to the GC, which can then get rid of the unused memory. Something similar is done for the case when the expression in the enhanced for loop is an array.
Removed Features and Options
- Removal of Runtime.getLocalizedInputStream and getLocalizedOutputStream Methods
- Removal of RMI Server-Side Multiplex Protocol Support
- Removal of Common DOM APIs
- Removal of FlatProfiler
- Removal of Obsolete -X Options
- Removal of HostServicesgetWebContext Method
- Removal of Deprecated VP6/FXM/FLV Code From JavaFX
- Removal of policytool
- Removal of Deprecated Classes in com.sun.security.auth.**
The following deprecated classes that were marked for removal in JDK 9 have been removed:
com.sun.security.auth.PolicyFile
com.sun.security.auth.SolarisNumericGroupPrincipal
com.sun.security.auth.SolarisNumericUserPrincipal
com.sun.security.auth.SolarisPrincipal
com.sun.security.auth.X500Principal
com.sun.security.auth.module.SolarisLoginModule
com.sun.security.auth.module.SolarisSystem
Removal of Old (JDK 6, JDK 7, and JDK 8 Era) Standard Doclet
JEP 313 Remove the Native-Header Generation Tool (javah)
Removal of Java Launcher’s Data Model Options -d32 and -d64
Deprecated Features and Options:-
- Deprecated API page (API specification) – Identifies all deprecated APIs including those deprecated in Java SE 10.
Hope this clears your doubts!!
Resources: