java after 8 - qcon · –java 8 fixed 1,926 bugs in first 17 months –(1,213 between 6 months and...
TRANSCRIPT
© Copyright Azul Systems 2019
© Copyright Azul Systems 2015
@giltene
Java
After 8
Gil Tene
1
© Copyright Azul Systems 2019
© Copyright Azul Systems 2015
@giltene
Keeping Up with Java: Look at All These New Features!
Gil TeneCTO, Azul Systems
2
© Copyright Azul Systems 2019
© Copyright Azul Systems 2015
@giltene
From JDK 9 To 13And Beyond
Gil TeneCTO, Azul Systems
3
© Copyright Azul Systems 2019
© Copyright Azul Systems 2015
@giltene
Java
After 8
Gil Tene
4
© Copyright Azul Systems 2019
© Copyright Azul Systems 2015
@giltene
Java
After 8
Gil TeneCTO, Azul Systems
5
© Copyright Azul Systems 2019
Changes…§ Java 6 2006 (December)
§ Java 7 2011 (July)
§ Java 8 2014 (March)
§ Java 9 2017 (September)
§ Java 10 2018 (18.3)§ Java 11 2018 (18.9)§ Java 12 2019 (19.3)§ Java 13 2019 (19.9)§ Java 14 2020 (20.3) …
6
© Copyright Azul Systems 2019
Java version timeline
7
© Copyright Azul Systems 2019
Coming up to speed§ “Current” Java is 13, or 11
– Depending on who you talk to
§ Consider changes from your “current” version
§ For most of you, that’s Java 8
§ So need to go over Java 9, 10, 11, 12, 13,…
8
© Copyright Azul Systems 2019
Changes…§ Java the language (“Java 13”)
– the syntax, the meaning
§ Java SE the platform (“Java 13”, “JDK 13”, “Java SE 13”)
– specified APIs, packages, behaviour
§ OpenJDK: an implementation (“OpenJDK 13”)– under the hood stuff– garbage collectors, CDS, …
9
© Copyright Azul Systems 2019
JDK 9: Big And Small Changes
10
© Copyright Azul Systems 2019
Java Platform Module System (JPMS)§ The core Java libraries are now a set of modules (JEP 220)
– 75 OpenJDK modules: § 24 Java SE§ 2 aggregator modules§ 1 smartcard (???)§ 48 JDK
§ Most internal APIs now encapsulated (JEP 260)– sun.misc.Unsafe– Some can be used with command line options
11
© Copyright Azul Systems 2019
jlink: The Java Linker (JEP 282)
$ jlink --module-path $JDKMODS:$MYMODS \--addmods com.azul.zapp –-output myimage
$ myimage/bin/java –[email protected]@[email protected]@[email protected]@[email protected]
myimage
…confbin
jlink
lib
© Copyright Azul Systems 2019
JDK 9: The Clean Up Starts§ JDK 9 was a significant change for Java
– Deprecated APIs were removed for the first time§ Six methods and one class§ JDK 10 removed 1 package, 6 classes, 9 methods and 1 field
– Parts of the platform were removed for the first time § The entire java.se.ee aggregator module was “hidden” in JDK 9§ And completely removed in JDK 11
§ JDK 10, 11, 12, 13, 14… continue this work§ More features will be removed in the future
§ CMS GC, Nashorn and Pack200 all deprecated. Others?
13
© Copyright Azul Systems 2019
JDK 9 Onwards And Compatibility
14
"Clean applications that just depend on java.seshould just work" - Oracle
• Note careful spelling of “java.se”
• ”java.se” refers to an aggregator module in JDK 9+
• Java SE 8 parts are absolutely being removed
© Copyright Azul Systems 2019
Platform parts removed– The java.se.ee aggregator-module
§ java.corba§ java.transaction§ java.activation§ java.xml.bind§ java.xml.ws§ java.xml.ws.annotation
15
© Copyright Azul Systems 2019
Compatibility Not Guaranteed§ New versions of Java may include breaking changes
– Anything for removal will be deprecated first– Minimum of one release warning
§ Could be only six months
16
© Copyright Azul Systems 2019
JDK 10
© Copyright Azul Systems 2019
Local Variable Type Inference (JEP 286)§ Java gets var
18
var userList = new ArrayList<String>(); // infers ArrayList<String>var stream = list.stream(); // infers Stream<String>
for (var name : userList) { // infers String...
}
for (var i = 0; i < 10; i++) { // infers int...
}
© Copyright Azul Systems 2019
var: Clearer try-with-resources
19
try (InputStream inputStream = socket.getInputStream();InputStreamReader inputStreamReader = new InputStreamReader(inputStream, UTF_8);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
// Use bufferedReader}
© Copyright Azul Systems 2019
var: Clearer try-with-resources
20
try (var inputStream = socket.getInputStream();var inputStreamReader = new InputStreamReader(inputStream, UTF_8);var bufferedReader = new BufferedReader(inputStreamReader)) {// Use bufferedReader
}
© Copyright Azul Systems 2019
var: Reserved Type (Not Keyword)var var = new ValueAddedReseller();
public class var {public var(String x) {
...}
}
public class Var {public Var(String x) {
...}
}
© Copyright Azul Systems 2019
JDK 10: Selected JEPs§ JEP 286: Local-Variable Type Inference§ JEP 307: Parallel Full GC for G1§ JEP 310: Application Class-Data Sharing§ JEP 317: Experimental Java-based JIT compiler (Graal)§ JEP 316: Heap allocation on alternative devices (Intel)§ JEP 312: Thread-local Handshakes
22
© Copyright Azul Systems 2019
JDK 10: APIs§ 73 New APIs
– List, Set, Map.copyOf(Collection)– Collectors
§ toUnmodifiableList§ toUnmodifiableMap§ toUnmodifiableSet
– Optional.orElseThrow()
23
© Copyright Azul Systems 2019
JDK 11
© Copyright Azul Systems 2019
323: Extend Local-Variable Syntax§ Local-variable syntax for lambda parameters
25
list.stream().map(s -> s.toLowerCase()).collect(Collectors.toList());
list.stream().map((var s) -> s.toLowerCase()).collect(Collectors.toList());
list.stream().map((@Notnull var s) -> s.toLowerCase()).collect(Collectors.toList());
© Copyright Azul Systems 2019
330: Launch Single File Source Code§ JDK 10 has three modes for the Java launcher
– Launch a class file– Launch the main class of a JAR file– Launch the main class of a module
§ JDK 11 adds a forth– Launch a class declared in a source file
26
$ java Factorial.java 4
© Copyright Azul Systems 2019
Single File Source Code Shebang
27
#!$JAVA_HOME/bin/java --source 11public class Factorial {
public static void main(String[] args) {int n = Integer.parseInt(args[0]);int r = (n == 0) ? 0 : 1;for (int i = 1; i <= n; i++)r *= i;
System.out.println("n = " + n + ", n! = " + r);}
}
$ ./Factorial 4n = 4, n! = 24
© Copyright Azul Systems 2019
JDK 11 Selected JEPs§ 181: Nest-based Access Control§ 309: Dynamic Class-file constants§ 321: HTTP client§ 332: Transport Layer Security (TLS) 1.3§ 333: ZGC: Experimental low-latency garbage collector§ 318: Epsilon garbage collector
28
© Copyright Azul Systems 2019
New APIs§ New I/O methods
§ InputStream nullInputStream()§ OutputStream nullOutputStream()§ Reader nullReader()§ Writer nullWriter()
§ Optional§ isEmpty() // Opposite of isPresent
29
© Copyright Azul Systems 2019
New APIs§ New String methods
– isBlank()– Stream lines()– String repeat(int)– String strip()– String stripLeading()– String stripTrailing()
30
© Copyright Azul Systems 2019
New APIs§ Predicate not(Predicate)
31
lines.stream().filter(s -> !s.isBlank())
lines.stream().filter(Predicate.not(String::isBlank))
lines.stream().filter(not(String::isBlank))
© Copyright Azul Systems 2019
JDK 11: Modules Removed– The java.se.ee aggregator-module has been removed
§ java.corba§ java.transaction§ java.activation§ java.xml.bind§ java.xml.ws§ java.xml.ws.annotation
32
© Copyright Azul Systems 2019
JDK 12
© Copyright Azul Systems 2019
Switch Expressions§ First preview feature in the OpenJDK
– Not included in the Java SE standard– Preview features require use of ––enable–preview flag
§ Switch construct was a statement– No concept of generating a result that could be assigned
§ Rather clunky syntax– Every case statement needs to be separated– Must remember break (default is to fall through)– Scope of local variables is not intuitive
34
© Copyright Azul Systems 2019
Old-Style Switch Statement
35
int numLetters;switch (day) {
case MONDAY:case FRIDAY:case SUNDAY:
numLetters = 6;break;
case TUESDAY:numLetters = 7;break;
case THURSDAY:case SATURDAY:
numLetters = 8;break;
case WEDNESDAY:numLetters = 9;break;
default:throw new IllegalStateException("Huh?: " + day); };
© Copyright Azul Systems 2019
New-Style Switch Expression
int numLetters = switch (day) {case MONDAY, FRIDAY, SUNDAY -> 6;case TUESDAY -> 7;case THURSDAY, SATURDAY -> 8;case WEDNESDAY -> 9;default -> throw new IllegalStateException("Huh?: " + day);
};
© Copyright Azul Systems 2019
New Old-Style Switch Expressionint numLetters = switch (day) {case MONDAY:case FRIDAY:case SUNDAY:break 6;
case TUESDAY break 7;
case THURSDAYcase SATURDAYbreak 8;
case WEDNESDAY break 9;
default: throw new IllegalStateException("Huh?: " + day);
};
© Copyright Azul Systems 2019
Switch Expression: Code Blocks
38
int levelResult = switch (level) {case 1 -> {var x = computeFrom(level);logger.info("Level 1 alert");break x;
}case 2 -> {var x = negativeComputeFrom(level);logger.info("Level 2 alert");break x;
}default -> throw new IllegalStateException("What level?: " + level);
};
© Copyright Azul Systems 2019
JDK 12: Selected JEPs§ 189: Shenandoah GC (Experimental)§ G1 GC updates
– 344: Abortable mixed collections– 346: Return unused committed memory
§ 334: JVM constant API§ 341: Default CDS archive
© Copyright Azul Systems 2019
Streams§ New collector, teeing
– teeing(Collector, Collector, BiFunction)§ Collect a stream using two collectors§ Use a BiFunction to merge the two collections
40
Collector 1
Collector 2
BiFunctionStream Result
© Copyright Azul Systems 2019
Streams
41
// AveragingDouble average = Stream.of(1, 4, 5, 2, 1, 7) .collect(teeing(summingDouble(i -> i), counting(),
(sum, n) -> sum / n));
© Copyright Azul Systems 2019
JDK 13
© Copyright Azul Systems 2019
Text BlocksString webPage = """
<html><body>
<p>My web page</p></body>
</html>""";
System.out.println(webPage);
$ java WebPage<html>
<body><p>My web page</p>
</body></html>
$
© Copyright Azul Systems 2019
Switch Expressionint numLetters = switch (day) {case MONDAY:case FRIDAY:case SUNDAY:break 6;
case TUESDAY break 7;
case THURSDAYcase SATURDAYbreak 8;
case WEDNESDAY break 9;
default: throw new IllegalStateException("Huh?: " + day);
};
© Copyright Azul Systems 2019
Switch Expression (still a preview feature)
int numLetters = switch (day) {case MONDAY:case FRIDAY:case SUNDAY:yield 6;
case TUESDAY yield 7;
case THURSDAYcase SATURDAYyield 8;
case WEDNESDAY yield 9;
default: throw new IllegalStateException("Huh?: " + day);
};
© Copyright Azul Systems 2019
Switch Expressions
int numLetters = switch (day) {case MONDAY, FRIDAY, SUNDAY -> 6;case TUESDAY -> 7;case THURSDAY, SATURDAY -> 8;case WEDNESDAY -> 9;default -> throw new IllegalStateException("Huh?: " + day);
};
© Copyright Azul Systems 2019
JDK 13: Selected JEPs§ JEP-354: Switch Expressions (Preview)§ JEP-355: Text Blocks (Preview)§ JEP-350: Dynamic CDS Archives§ JEP-351: ZGC (Experimental): Uncommit Unused Memory§ JEP-353: Reimplement the Legacy Socket API
© Copyright Azul Systems 2019
© Copyright Azul Systems 2019
Zulu Community§ OpenJDK is a source code project§ Any binary you run comes from some sort of distro§ Many distros of OpenJDK out there
– Some are well built and well tested– Other are…. Ahem.. Not so much.– E.g. “Mystery meat OpenJDK builds strike again”– Zulu, Corretto, Dragonwell, Liberica, Adopt, etc. etc. etc.– You have plenty of choice…
© Copyright Azul Systems 2019
Zulu Community
© Copyright Azul Systems 2019
Zulu§ A FREE, 100% OSS community distribution of OpenJDK
– Certified Java SE compliant, TCK tested, etc.§ JDK 6*, 7, 8, 9, 10, 11, 12, 13, …§ Curated distribution
– Wide platform support:§ Intel 64-bit & 32-bit Windows, Mac, Linux§ ARM 64-bit and 32-bit
– JFR (Java Flight Recorder) and TLS 1.3 support in JDK 8– JDK, JRE, JDK+FX, …
51www.zulu.org
© Copyright Azul Systems 2019
Zulu Community
MTS
© Copyright Azul Systems 2019
The need for version overlap§ Major Java releases take time to stabilize post GA
– huge number of bugs are detected via (post-GA) early adopter exposure
– Java 8 fixed 1,926 bugs in first 17 months– (1,213 between 6 months and 18 months past GA)
§ Production use remains on previous version– until newly GA’ed version matures
§ Production version needs updates during overlap period– security updates, critical fixes, etc.
53
© Copyright Azul Systems 2019
Java lifecycle: historic al view
54
© Copyright Azul Systems 2019
Java version timeline
55
© Copyright Azul Systems 2019
Zulu MTSReleases
Zulu LTSReleases
Zulu Roadmap: LTS and MTS
© Copyright Azul Systems 2019
Zulu Enterprise
§ Zulu with commercial support
§ Releases (LTS, MTS, updates) fit for long term production use
§ Timely updates and security fixes (CPU, PSU, etc.)
§ Includes indemnification, non-Contamination, etc.
§ Used widely across multiple industries
57
© Copyright Azul Systems 2019
Select Azul Customers
CONFIDENTIAL | DO NOT DISTRIBUTE 1
© Copyright Azul Systems 2019
Zulu 7, 8, 11, and 13
Azure Spring Cloud
© Copyright Azul Systems 2019
Zulu Enterprise
§ Zulu with commercial support
§ Releases (LTS, MTS, updates) fit for long term production use
§ Timely updates and security fixes (CPU, PSU, etc.)
§ Includes indemnification, non-Contamination, etc.
§ Used widely across multiple industries§ Java 6, 7, 8, 11, 13, …
§ 24x7 support
60
© Copyright Azul Systems 2019
Summary
MTS
LTS8
109
11 12
17
1315..
LTS
LTS
..
© Copyright Azul Systems 2019
© Copyright Azul Systems 2015
@gilteneGil TeneCTO, Azul Systems
62