Java 11 is the new Java release and, differently from Java 9 and Java 10, it is a "Long Term Support" release - we will see what that means exactly.
This presentation details the main new features of Java 11, starting from licensing (where there are important changes - in particular the Oracle JDK may only be used in production if you have a support contract with Oracle), to arrive to the new Java 11 features, with a quick peek back at what was introduced in Java 9 and Java 10.
The main Java 11 arguments are:
• Two new garbage collectors: EpsilonGC e ZGC
• Support for TLS 1.3
• Possibility to execute a single source file
• New HTTP client based on the Flow API
• Removal of modules (CORBA, JTA, @Inject, ecc.)
• Bytecode news (nest-mates, dynamic constants)
5. sbordet@webtide.com
Java 11
● What does LTS really mean?
● During the 6 months of “life” of a Java 11:
○ OpenJDK Binary -> GPL
○ AdoptOpenJDK -> GPL
○ Azul Zulu -> GPL
○ Oracle JDK Binary -> Oracle License
■ MUST PAY Oracle for production use
9. sbordet@webtide.com
Java 9
● Java 9 introduced the Java Module System
● Along with it, a number of breaking changes
○ Upgrading from 8 to 9/10/11 is NOT simple
○ Many runtime behavior changes
○ Needs very thorough testing
11. sbordet@webtide.com
Java 9
● Class loading implementation changed
○ Different behavior to support modules
ClassLoader sysCL = ClassLoader.getSystemClassLoader();
// Throws ClassCastException now!
URLClassLoader urlCL = (URLClassLoader)sysCL;
12. sbordet@webtide.com
Java 9
● Loading resources
URL resource = sysCL.getResource("java/lang/String.class");
// Not a file:/ nor a jar:/ URL!
resource = jrt:/java.base/java/lang/String.class
URL resource = sysCL.getResource("/com/foo/bar.properties");
// It’s there, but it won’t find it!
resource = null;
13. sbordet@webtide.com
Java 9
● New version string scheme
○ 1.8.0_181 -> 9.0.1
○ Broke many Maven Plugins, Jetty, etc.
● JDK 9’s java.lang.Runtime.Version class
○ Cannot parse JDK 8 version string
○ Must implement custom parsing to support both
21. sbordet@webtide.com
Java 9
● G1 is the default Garbage Collector
● Much improved from 8 and even better in 11
○ Adaptive start of concurrent mark
○ Made internal data structures more concurrent
○ More phases parallelized
○ Reduced contention
○ Reduced memory consumption
22. sbordet@webtide.com
Java 9
● Unified GC logging
○ Not compatible with previous GC logs
● Every GC logs differently
● Example
○ -
Xlog:gc*,ergo*=trace,ref*=debug:file=log
s/gc.log:time,level,tags
23. sbordet@webtide.com
Java 9
● JVM options changes
○ 50 options removed - JVM refuses to start
○ 18 options ignored - 12 options deprecated
● Must review your command line!
○ Especially if you had custom GC tuning options
25. sbordet@webtide.com
Java 10
● Local variable type inference (a.k.a. var)
○ http://openjdk.java.net/projects/amber/LVTIstyle.html
// Infers ArrayList<String>
var list = new ArrayList<String>();
// infers Stream<String>
var stream = list.stream();
26. sbordet@webtide.com
Java 10
● var is not a keyword, it is a reserved type name
○ It’s a valid identifier, unless used in places where the
compiler expects a type name
int var = 13;
27. sbordet@webtide.com
Java 10
● Good var usage
var message = "warning, too many features";
var anon = new Object() {
int count = 0;
}
anon.count++; // Compiles!
29. sbordet@webtide.com
Java 10
● Experimental Graal JIT
○ https://www.graalvm.org/
● -XX:+UnlockExperimentalVMOptions -XX:
+UseJVMCICompiler
● Not yet recommended in production
○ Twitter uses it in production, you may too (YMMV)
30. sbordet@webtide.com
Java 10
● Docker awareness
○ On by default
○ https://blog.docker.com/2018/04/improved-docker-containe
-XX:-UseContainerSupport
-XX:ActiveProcessorCount=n
-XX:MinRAMPercentage=p
-XX:InitialRAMPercentage=p
-XX:MaxRAMPercentage=p
33. sbordet@webtide.com
● ZGC
○ 5 years of closed source development @ Oracle
○ XX:+UnlockExperimentalVMOptions XX:+UseZGC
○ Single Generation, Region Based
○ Concurrent Marking
○ Concurrent Compaction
○ Very low STW pause times
Java 11
36. sbordet@webtide.com
Java 11
● Java Flight Recorder
○ Open Sourced by Oracle, included in OpenJDK 11
○ java -XX:StartFlightRecording ...
● Java Mission Control
○ Open Sourced by Oracle
○ Downloads at https://jdk.java.net/jmc/
○ JMC 7 scheduled for January 2019
37. sbordet@webtide.com
Java 11
● TLS 1.3
○ More secure and recent version of TLS
○ Removed vulnerable/weak ciphers
○ Added new ciphers and algorithms
● Using SSLEngine? Verify it works!
39. sbordet@webtide.com
Java 11
● HTTP client
○ Supports both HTTP/1.1 and HTTP/2
○ Based on the j.u.c.Flow APIs
HttpClient c = HttpClient.newBuilder().build();
HttpRequest r = HttpRequest.newBuilder()
.uri(...).build();
CompletableFuture<String> f = c.sendAsync(r,
BodyHandlers.ofString());
40. sbordet@webtide.com
Java 11
● Nest Mates
○ Inner (nested) classes introduced in Java 1.1
○ Outer class can access inner class
■ Via compiler tricks - bridge methods
java.lang.UnsupportedOperationException
at NestExample.init(NestExample.java)
at NestExample.access$000(NestExample.java)
at NestExample$Inner.(NestExample.java)
at NestExample.main(NestExample.java)
41. sbordet@webtide.com
Java 11
● Nest Mates
○ Now specified in the JVM Specification
○ New class file attribute
○ New reflection APIs: Class.getNestMembers(), ...
○ New JVM access controls at runtime
● Do you play with bytecode?
○ Use ASM 7+
43. sbordet@webtide.com
Conclusions
● Upgrade from Java 8 takes time
○ Lots of runtime changes
● Java 8 will be soon unmaintained / unavailable
○ Skip Java 9 and Java 10 - go straight to Java 11
● Lots of good stuff and more coming
○ And coming every 6 months now!