Java 9 - Java 15: Features and Enhancements - Aug 2020
This session shares notable changes in the Java ecosystem starting from Java 8 all the way until Java 15. No vendor-specific changes or enhancements are covered.
Mar. 2014 •150 new features and enhancements •One of the largest upgrades to Java •https://openjdk.java.net/projects/jdk9/ •https://speakerdeck.com/cguntur/java-9-new-features 3
targeted for Java 8 •JVM now uses a Metaspace instead of PermGen •GC focusses on garbage-heavy regions •JEP 248 - Make G1 the default collector: http://openjdk.java.net/jeps/248 •https://speakerdeck.com/cguntur/java-garbage-collection-basics 7 Java 9 https://docs.oracle.com/javase/9/gctuning/garbage-first-garbage-collector.htm
growing java package size •Also aims to remove/deprecate vestigial packages •Allows splitting the JDK in smaller units (modules) •Root module called java.base •Dependencies packaged as .jmod files •Module path to replace classpath 10 Java 9
is a modular system • Restructures JDK and JRE runtime images - as modules • No more rt.jar and tools.jar in libs • Enables Compact Profiles: http://openjdk.java.net/jeps/161 • jlink responsible for assembly and optimizing modules • jlink produces custom runtime images 12 Java 9
- new methods added •java.util.concurrent.* - reactive and futures •Compact Strings - major fixes to compressed strings •Deprecation - added forRemoval & since attributes •Compiler - new flags to compile (--release) 14 Java 9
a variable type •Examples: ✤ var list = new ArrayList<String>(); // infers ArrayList<String> ✤ var stream = list.stream(); // infers Stream<String> •Requires initialization of the variable •JEP 286 - Local-variable Type Inference: http://openjdk.java.net/jeps/286 17 Java 10
// cannot infer type for local ✤var f = () -> { }; // cannot infer type for local ✤var g = null; // cannot infer type for local ✤var k = { 1 , 2 }; // cannot infer type for local ✤(var x, var y) -> x.process(y) // not supported 18 Java 10 https://openjdk.java.net/projects/amber/LVTIstyle.html
added a java.version.date System property • Make it easy for a developer to figure out how old a release is • JEP 322 - Time-Based Release Versioning: http://openjdk.java.net/jeps/322 21 Java 10
usage in lambda parameters •Great addition for annotating params in lambdas •Examples: ✤ (var x, var y) -> x.process(y) // Works in Java 11 ✤ (@Nonnull var x, @Nullable var y) -> x.process(y) •JEP 323 - Local-Variable Syntax for Lambda Parameters: http://openjdk.java.net/jeps/323 25 Java 11
Java program •Automatically compiles and runs Java file •Example: java HelloWorld.java (no need for javac) •Great tool for students and new beginners •JEP 330 - Launch Single-File Source-Code Programs: http://openjdk.java.net/jeps/330 26 Java 11
EE & CORBA modules deprecated in Java 9 •Source code deleted from OpenJDK repository •Binaries do not include these deleted modules •Related to the separation of Java SE and Jakarta EE •JEP 320 - Remove the Java EE and CORBA Modules: http://openjdk.java.net/jeps/320 27 Java 11
•Main features: ✤ Guaranteed pause times (10ms) ✤ Handles range of small (few MB) to very large memory (TBs) ✤ Foundation for future GC features and optimizations ✤ Concurrent, single-generation, region-based, NUMA-aware, compacting collector •JEP 333 - ZGC: A Scalable Low-Latency Garbage Collector: http://openjdk.java.net/jeps/333 29 Java 11 E
and Poly1305 Cryptographic Algorithms •JEP-331: Low-Overhead Heap Profiling •JEP-332: Transport Layer Security (TLS) 1.3 •JEP-335: Deprecate the Nashorn JavaScript Engine •JEP-336: Deprecate the Pack200 Tools and API 31 Java 11
collector •Main features: ✤ Adds an indirection pointer to every Java object ✤ Concurrent marking and compacting ✤ Optimized to never interrupt the running program ✤ Pause Java threads only to scan thread stacks to find & update object graph • JEP 189 - Shenandoah: A Low-Pause-Time Garbage Collector: http://openjdk.java.net/jeps/189 36 Java 12 E
•Eases the addition, build and running of new benchmarks •Targeted for continuous performance testing •JEP 230 - Microbenchmark Suite: http://openjdk.java.net/jeps/230 37 Java 12
exit •Further speeds up startup times •CDS and AppCDS were static, Dynamic CDS is an addition •Use -XX:ArchiveClassesAtExit=my.jsa - to enable Use -XX:SharedArchiveFile=my.jsa - to load •JEP 350 - Dynamic CDS Archives: http://openjdk.java.net/jeps/350 41 Java 13
cast once instance is confirmed •Example: if (obj instanceof String s) { // can use s here } else { // can't use s here } •JEP 305 - Pattern matching for instanceof (Preview): http://openjdk.java.net/jeps/305 47 Java 14 P
termination of a program • Example: a.b.c.i = 99; • Results in: Exception in thread “main" java.lang.NullPointerException: Cannot read field "c" because "a.b" is null at Prog.main(Prog.java:5) • JEP 358 - Helpful NullPointerExceptions: http://openjdk.java.net/jeps/358 48 Java 14 P
data types into Java, with records • Immutable data objects with built in constructors and accessors record Range(int lo, int hi) { public Range { if (lo > hi) /* referring here to the implicit constructor parameters */ throw new IllegalArgumentException(String.format("(%d,%d)", lo, hi)); } } • JEP 359 - Records (Preview): https://openjdk.java.net/jeps/359 49 Java 14 P
ZGC on Windows • JEP-366: Deprecate the ParallelScavenge + SerialOld GC Combination •JEP-367: Remove the Pack200 Tools and API •JEP-370: Foreign-Memory Access API (Incubator) •JEP-343: Packaging Tool (Incubator) 51 Java 14
extendability to types •Adds new modifiers of sealed and non-sealed •The final modifier indicates a strong sealed type •Requires a new permits clause to allow limited hierarchy •JEP 360 - Sealed classes (Preview): http://openjdk.java.net/jeps/360 54 Java 15 P * *
the first preview of records •Adds ability to create in-method local records •Clarifies the usage of annotations on records •JEP 384 - Records (Second Preview): http://openjdk.java.net/jeps/384 55 Java 15 P * *
•Supports aggressive unloading of such classes in JVM •Great for dynamic proxies and runtime generated classes •Not to be confused with anonymous classes •JEP 371 - Hidden classes: http://openjdk.java.net/jeps/371 56 Java 15 * *
product feature •G1 GC still remains default GC •Great for larger heap sizes, may not be great for smaller ones •No longer needs -XX:+UnlockExperimentalVMOptions for -XX:+UseZGC •JEP 377 - ZGC: A Scalable Low-Latency Garbage Collector: http://openjdk.java.net/jeps/377 57 Java 15 * *
API •JEP-374: Disable and Deprecate Biased Locking •JEP-381: Remove the Solaris and SPARC Ports •JEP-383: Foreign-Memory Access API (Second Incubator) 60 Java 15 * *