© Copyright Azul Systems 2020
© Copyright Azul Systems 2015
@speakjava
JDK 14:
Lots of New Features
Simon Ritter
Deputy CTO, Azul Systems
1
© Copyright Azul Systems 2020
OpenJDK: New Release Model
 A new version of the JDK is released every six months
– March and September
– 2018: JDK 10 and 11, 2019: JDK 12 and 13
– Continuing this year with JDK 14 and JDK 15
 OpenJDK development is more agile
 Features are only included when ready
2
© Copyright Azul Systems 2020
Incubators And Previews
 Add new features to OpenJDK
 Without making it standard
 Time for feedback and changes (or removal)
 Incubator modules (JEP 11)
 API and tool changes
 Started in JDK 9 with HTTP/2
 Preview features (JEP 12)
 Language and VM changes
 Started in JDK 12 with switch expression
3
© Copyright Azul Systems 2020
JDK 14: Big Features
 Language level
– JEP 359: Records (preview)
– JEP 305: Pattern matching for instanceof (preview)
– JEP 368: Text blocks (second preview)
 API Changes
– Record related changes
– Foreign memory access API (incubator module)
4
© Copyright Azul Systems 2020
Simple Java Data Class
5
class Point {
private final double x;
private final double y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
}
© Copyright Azul Systems 2020
Records (Preview)
6
record Point(double x, double y) { }
record Range(double low, double high) {
public Range {
if (low > high)
throw new IllegalArgumentException("Bad values");
}
public String toString() {
return "Point is (" + x + ", " + y + ")";
}
}
© Copyright Azul Systems 2020
Using instanceof
7
if (obj instanceof String) {
String s = (String)obj;
System.out.println(s.length());
}
© Copyright Azul Systems 2020
Pattern Matching instanceof (Preview)
8
if (obj instanceof String s) {
System.out.println(s.length());
} else {
// Use of s not allowed here
}
if (obj instanceof String s && s.length() > 0)
System.out.println(s.length());
// Compiler error
if (obj instanceof String s || s.length() > 0)
System.out.println(s.length());
© Copyright Azul Systems 2020
Pattern Matching instanceof (Preview)
if (!(o instanceof String s))
return;
System.out.println(s.length());
© Copyright Azul Systems 2020
Text Blocks (Second Preview)
 Two new escape sequences
String continuous = """This line will not 
contain a newline in the middle""";
String colours = """Red s
greens
blue s
""";
© Copyright Azul Systems 2020
Switch Expression
 JEP 361: Switch Expressions (standard)
– No more changes from the second preview (JDK 13)
– Now a standard feature in JDK 14
 No --enable-preview flag necessary
 Included in the Java SE specification
11
© Copyright Azul Systems 2020
Helpful NullPointerException
 Who's never had an NullPointerException?
12
a.b.c.i = 99;
Exception in thread "main" java.lang.NullPointerException
at Prog.main(Prog.java:5)
Exception in thread "main" java.lang.NullPointerException:
Cannot read field "c" because "a.b" is null
at Prog.main(Prog.java:5)
© Copyright Azul Systems 2020
Other Feature JEPs
 343: Packaging tool (incubator)
 345: NUMA aware memory allocation for G1
 349: Java Flight Recorder streaming events
 352: Non-volatile mapped byte buffers
 364/365: ZGC on Windows/macOS
13
© Copyright Azul Systems 2020
Deprecation and Removal JEPs
 363: Remove the CMS collector
 362: Deprecate the Solaris and SPARC ports
 366: Deprecate ParallelScavenge + SerialOld GC combo
 367: Remove the Pack200 tools and API
14
© Copyright Azul Systems 2020
API Changes
© Copyright Azul Systems 2020
Foreign-Memory Access API
 Alternative to parts of sun.misc.Unsafe and
MappedByteBuffer
– MemorySegment
– MemoryAddress
– MemoryLayout
16
© Copyright Azul Systems 2020
Record Related APIs
 Class
 isRecord()
 RecordComponent[] getRecordComponents()
 java.lang.Record
 java.lang.annotation.ElementType
 RECORD_TYPE
 java.lang.runtime
 New package for records
 ObjectMethods class with bootstrap()
 javax.lang.mode.util new classes
17
© Copyright Azul Systems 2020
Serial Annotation
 Used for compiler checks of Serializable classes
 Use with these methods
 writeObject
 readObject
 readObjectNoData
 writeReplace
 readResolve
 And these fields
 serialPersistentFields
 serialVersionUID
18
© Copyright Azul Systems 2020
Miscellaneous
 NullPointerException
 Now overrides getMessage() from Throwable
 StrictMath
 New exact methods: incrementExact(), decrementExact(),
negateExact()
 CompactNumberFormat
 pluralRules()
 HashSet
 toArray()
19
© Copyright Azul Systems 2020
Azul's Zulu Java
© Copyright Azul Systems 2020
Zulu Community
 Azul’s FREE binary distribution of OpenJDK
 Passes all TCK tests
 Versions: JDK 6-14 available
 JDK 15 available as Early Access
 Wide platform support:
 Intel 64-bit Windows, Mac, Linux
 Intel 32-bit Windows and Linux
 ARM 32 and 64-bit
 PPC 32 and 64-bit
 Solaris 10/11 on SPARC
21
www.azul.com/downloads/zulu
© Copyright Azul Systems 2020
Zulu Enterprise
 Backporting of bug fixes and security patches from
supported OpenJDK release
 Zulu 8 supported until end of 2030
 Zulu 6 supported until end of 2021
 LTS releases have 8 years active + 2 years passive support
 Medium Term Support releases
– Two interim releases between LTS releases (13, 15...)
– Bridge to LTS releases
– Supported until 18 months after next LTS release
22
© Copyright Azul Systems 2020
Summary
© Copyright Azul Systems 2020
JDK 14: A Great Release
 Powerful new language features
– Records
– Pattern matching for instanceof
 Better NullPointerException messages
 Useful API changes
– Foreign memory access API
 Keeping Java fresh after 25 years!
24
© Copyright Azul Systems 2020
© Copyright Azul Systems 2015
@speakjava
Thank You!
Simon Ritter
Deputy CTO, Azul Systems
25

JDK 14 Lots of New Features

  • 1.
    © Copyright AzulSystems 2020 © Copyright Azul Systems 2015 @speakjava JDK 14: Lots of New Features Simon Ritter Deputy CTO, Azul Systems 1
  • 2.
    © Copyright AzulSystems 2020 OpenJDK: New Release Model  A new version of the JDK is released every six months – March and September – 2018: JDK 10 and 11, 2019: JDK 12 and 13 – Continuing this year with JDK 14 and JDK 15  OpenJDK development is more agile  Features are only included when ready 2
  • 3.
    © Copyright AzulSystems 2020 Incubators And Previews  Add new features to OpenJDK  Without making it standard  Time for feedback and changes (or removal)  Incubator modules (JEP 11)  API and tool changes  Started in JDK 9 with HTTP/2  Preview features (JEP 12)  Language and VM changes  Started in JDK 12 with switch expression 3
  • 4.
    © Copyright AzulSystems 2020 JDK 14: Big Features  Language level – JEP 359: Records (preview) – JEP 305: Pattern matching for instanceof (preview) – JEP 368: Text blocks (second preview)  API Changes – Record related changes – Foreign memory access API (incubator module) 4
  • 5.
    © Copyright AzulSystems 2020 Simple Java Data Class 5 class Point { private final double x; private final double y; public Point(double x, double y) { this.x = x; this.y = y; } public double getX() { return x; } public double getY() { return y; } }
  • 6.
    © Copyright AzulSystems 2020 Records (Preview) 6 record Point(double x, double y) { } record Range(double low, double high) { public Range { if (low > high) throw new IllegalArgumentException("Bad values"); } public String toString() { return "Point is (" + x + ", " + y + ")"; } }
  • 7.
    © Copyright AzulSystems 2020 Using instanceof 7 if (obj instanceof String) { String s = (String)obj; System.out.println(s.length()); }
  • 8.
    © Copyright AzulSystems 2020 Pattern Matching instanceof (Preview) 8 if (obj instanceof String s) { System.out.println(s.length()); } else { // Use of s not allowed here } if (obj instanceof String s && s.length() > 0) System.out.println(s.length()); // Compiler error if (obj instanceof String s || s.length() > 0) System.out.println(s.length());
  • 9.
    © Copyright AzulSystems 2020 Pattern Matching instanceof (Preview) if (!(o instanceof String s)) return; System.out.println(s.length());
  • 10.
    © Copyright AzulSystems 2020 Text Blocks (Second Preview)  Two new escape sequences String continuous = """This line will not contain a newline in the middle"""; String colours = """Red s greens blue s """;
  • 11.
    © Copyright AzulSystems 2020 Switch Expression  JEP 361: Switch Expressions (standard) – No more changes from the second preview (JDK 13) – Now a standard feature in JDK 14  No --enable-preview flag necessary  Included in the Java SE specification 11
  • 12.
    © Copyright AzulSystems 2020 Helpful NullPointerException  Who's never had an NullPointerException? 12 a.b.c.i = 99; Exception in thread "main" java.lang.NullPointerException at Prog.main(Prog.java:5) Exception in thread "main" java.lang.NullPointerException: Cannot read field "c" because "a.b" is null at Prog.main(Prog.java:5)
  • 13.
    © Copyright AzulSystems 2020 Other Feature JEPs  343: Packaging tool (incubator)  345: NUMA aware memory allocation for G1  349: Java Flight Recorder streaming events  352: Non-volatile mapped byte buffers  364/365: ZGC on Windows/macOS 13
  • 14.
    © Copyright AzulSystems 2020 Deprecation and Removal JEPs  363: Remove the CMS collector  362: Deprecate the Solaris and SPARC ports  366: Deprecate ParallelScavenge + SerialOld GC combo  367: Remove the Pack200 tools and API 14
  • 15.
    © Copyright AzulSystems 2020 API Changes
  • 16.
    © Copyright AzulSystems 2020 Foreign-Memory Access API  Alternative to parts of sun.misc.Unsafe and MappedByteBuffer – MemorySegment – MemoryAddress – MemoryLayout 16
  • 17.
    © Copyright AzulSystems 2020 Record Related APIs  Class  isRecord()  RecordComponent[] getRecordComponents()  java.lang.Record  java.lang.annotation.ElementType  RECORD_TYPE  java.lang.runtime  New package for records  ObjectMethods class with bootstrap()  javax.lang.mode.util new classes 17
  • 18.
    © Copyright AzulSystems 2020 Serial Annotation  Used for compiler checks of Serializable classes  Use with these methods  writeObject  readObject  readObjectNoData  writeReplace  readResolve  And these fields  serialPersistentFields  serialVersionUID 18
  • 19.
    © Copyright AzulSystems 2020 Miscellaneous  NullPointerException  Now overrides getMessage() from Throwable  StrictMath  New exact methods: incrementExact(), decrementExact(), negateExact()  CompactNumberFormat  pluralRules()  HashSet  toArray() 19
  • 20.
    © Copyright AzulSystems 2020 Azul's Zulu Java
  • 21.
    © Copyright AzulSystems 2020 Zulu Community  Azul’s FREE binary distribution of OpenJDK  Passes all TCK tests  Versions: JDK 6-14 available  JDK 15 available as Early Access  Wide platform support:  Intel 64-bit Windows, Mac, Linux  Intel 32-bit Windows and Linux  ARM 32 and 64-bit  PPC 32 and 64-bit  Solaris 10/11 on SPARC 21 www.azul.com/downloads/zulu
  • 22.
    © Copyright AzulSystems 2020 Zulu Enterprise  Backporting of bug fixes and security patches from supported OpenJDK release  Zulu 8 supported until end of 2030  Zulu 6 supported until end of 2021  LTS releases have 8 years active + 2 years passive support  Medium Term Support releases – Two interim releases between LTS releases (13, 15...) – Bridge to LTS releases – Supported until 18 months after next LTS release 22
  • 23.
    © Copyright AzulSystems 2020 Summary
  • 24.
    © Copyright AzulSystems 2020 JDK 14: A Great Release  Powerful new language features – Records – Pattern matching for instanceof  Better NullPointerException messages  Useful API changes – Foreign memory access API  Keeping Java fresh after 25 years! 24
  • 25.
    © Copyright AzulSystems 2020 © Copyright Azul Systems 2015 @speakjava Thank You! Simon Ritter Deputy CTO, Azul Systems 25