What's New in Java 10
Java 10, developed under JSR 383, was officially released on March 20, 2018. Oracle provides production-ready binaries under the GPL. This release includes twelve new features.
Local-Variable Type Inference
To improve developer experience while maintaining Java’s commitment to static type safety, JDK 10 allows developers to omit unnecessary local variable type declarations. For example:
1 | var list = new ArrayList<String>(); // infers ArrayList<String> |
In the examples above, the identifier var is not a keyword but a reserved type name, so using var as a variable, method, or package name is unaffected.
Local variable type inference is limited to local variables with initializers, indexes in enhanced
for-loopstatements, and local variables declared in traditionalforloops. It cannot be used for method parameters, constructor parameters, method return types, fields,catchclauses, or any other type of variable declaration.
Consolidate the JDK Forest into a Single Repository
This Java 10 feature is about internal housekeeping – consolidating the many JDK repositories into a single repository.
Garbage-Collector Interface
JDK 10 improves code isolation between different garbage collectors and introduces a clean interface. This makes it easier to exclude a GC from JDK builds and to add new GCs without affecting the codebase. For details on G1 garbage collection and how G1 differs from CMS, see Java Memory Management.
Parallel Full GC for G1
Another interesting feature in JDK 10 improves G1’s worst-case latency through parallel full GC. Recall that in Java 9, G1 was made the default GC to avoid full GC. However, when concurrent collection cannot reclaim memory fast enough, it falls back to a full GC, which is a problem. This change parallelizes the full GC algorithm so that in the unlikely event of a G1 full GC, the same number of threads used for concurrent collection can improve overall performance.
Application Class-Data Sharing
Class-data sharing was introduced back in Java 5. It allows a set of classes to be pre-processed into a shared archive file, which is then memory-mapped at runtime to reduce startup time. When multiple JVMs share the same archive file, it also reduces dynamic memory usage.
Thread-Local Handshakes
Thread-local handshakes lay the foundation for improved VM performance by enabling callbacks on application threads without a global VM safepoint. This means the JVM can stop individual threads rather than all threads at once.
Remove the Native-Header Generation Tool (javah)
javah, the tool for generating header files when compiling JNI code, was removed in Java 10 and replaced by javac.
Additional Unicode Language-Tag Extensions
Java SE 9 supported the BCP 47 Unicode language tag extensions ca and nu. Java 10 adds support for these additional extensions:
- cu (currency type)
- fw (first day of week)
- rg (region override)
- tz (time zone)
To support these extensions, Java 10 modified the following APIs:
java.text.DateFormat::get*Instancereturns instances based onca,rg,tzextensionsjava.text.DateFormatSymbols::getInstancereturns instances based onrgextensionjava.text.DecimalFormatSymbols::getInstancereturns instances based onrgextensionjava.text.NumberFormat::get*Instancereturns instances based onnu,rgextensionsjava.time.format.DateTimeFormatter::localizedByreturns instances based onca,rg,tzextensionsjava.time.format.DateTimeFormatterBuilder::getLocalizedDateTimePatternreturns pattern strings based onrgextensionjava.time.format.DecimalStyle::ofreturnsDecimalStyleinstances based onnu,rgextensionsjava.time.temporal.WeekFields::ofreturnsWeekFieldsinstances based onfw,rgextensionsjava.util.Calendar::{getFirstDayOfWeek,getMinimalDaysInWeek}returns values based onfw,rgextensionsjava.util.Currency::getInstancereturnsCurrencyinstances based oncu,rgextensionsjava.util.Locale::getDisplayNamereturns a string containing thedisplay nameof these Unicode extensionsjava.util.spi.LocaleNameProviderhas new SPIs for these Unicode extension keys and types
Heap Allocation on Alternative Memory Devices
This is a pretty cool feature that allows the HotSpot VM to allocate the Java object heap on a user-specified alternative memory device. In multi-JVM environments, this enables directing lower-priority processes to use NV-DIMM memory while allocating DRAM to higher-priority processes.
Experimental Java-Based JIT Compiler
Graal, a Java-based JIT compiler, was the experimental AOT (Ahead-of-Time) compiler introduced in Java 9 using the JVM compiler interface. As an experimental JIT compiler, Graal is primarily used for testing and debugging. It can be enabled with the following JVM flags:
1 | -XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler |
Root Certificates
Another important change in Java 10: it provides a default set of root CA certificates, making OpenJDK more attractive to developers. It also aims to reduce differences between OpenJDK and Oracle JDK. Critical security components like TLS will work by default in OpenJDK.
Time-Based Release Versioning
With JDK 10, Java adopted a new release cadence – every six months. There has been much debate about whether this is a viable approach. Many say new features every six months is great, though others complain that it leaves too little time for JDK adoption.
For more details, see: https://www.oracle.com/java/technologies/javase/10-relnote-issues.html#NewFeature
- Blog Link: https://johnsonlee.io/2021/05/07/java-10-new-features.en/
- Copyright Declaration: 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
