Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

JDK 14 Lots of New Features

390 views

Published on

JDK 14 is full of great new features for developers. In this presentation, we'll take you through what they are and how to use them.

Published in: Software
  • Be the first to comment

JDK 14 Lots of New Features

  1. 1. © Copyright Azul Systems 2020 © Copyright Azul Systems 2015 @speakjava JDK 14: Lots of New Features Simon Ritter Deputy CTO, Azul Systems 1
  2. 2. © 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
  3. 3. © 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
  4. 4. © 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
  5. 5. © 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; } }
  6. 6. © 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 + ")"; } }
  7. 7. © Copyright Azul Systems 2020 Using instanceof 7 if (obj instanceof String) { String s = (String)obj; System.out.println(s.length()); }
  8. 8. © 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());
  9. 9. © Copyright Azul Systems 2020 Pattern Matching instanceof (Preview) if (!(o instanceof String s)) return; System.out.println(s.length());
  10. 10. © 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 """;
  11. 11. © 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
  12. 12. © 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)
  13. 13. © 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
  14. 14. © 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
  15. 15. © Copyright Azul Systems 2020 API Changes
  16. 16. © Copyright Azul Systems 2020 Foreign-Memory Access API  Alternative to parts of sun.misc.Unsafe and MappedByteBuffer – MemorySegment – MemoryAddress – MemoryLayout 16
  17. 17. © 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
  18. 18. © 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
  19. 19. © Copyright Azul Systems 2020 Miscellaneous  NullPointerException  Now overrides getMessage() from Throwable  StrictMath  New exact methods: incrementExact(), decrementExact(), negateExact()  CompactNumberFormat  pluralRules()  HashSet  toArray() 19
  20. 20. © Copyright Azul Systems 2020 Azul's Zulu Java
  21. 21. © 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
  22. 22. © 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
  23. 23. © Copyright Azul Systems 2020 Summary
  24. 24. © 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
  25. 25. © Copyright Azul Systems 2020 © Copyright Azul Systems 2015 @speakjava Thank You! Simon Ritter Deputy CTO, Azul Systems 25

×