Slide 1

Slide 1 text

@rodrigograciano @nehasardana09 Java 9 to Java 16: A review of recent changes to the language Rodrigo Graciano & Neha Sardana speakerdeck.com/graciano

Slide 2

Slide 2 text

@rodrigograciano @nehasardana09 Did you know? uJava 8 released in March 2014 u85% still uses 8 or older version * uAnyone using Java 9+ in PROD? u https://www.jetbrains.com/lp/devecosystem-2020/java/

Slide 3

Slide 3 text

@rodrigograciano @nehasardana09 Release Schedule 8

Slide 4

Slide 4 text

@rodrigograciano @nehasardana09 About me u Professional with 10+ years u Principal Software Engineer - NY u NYJavaSIG Leader u graciano.dev u Twitter: @rodrigograciano

Slide 5

Slide 5 text

@rodrigograciano @nehasardana09 About me u Software Developer with 10+ years experience u Senior Specialist Developer – NY u JUG Leader, Garden State JUG (gsjug.org) u Twitter: @nehasardana09

Slide 6

Slide 6 text

@rodrigograciano @nehasardana09 What we’ll see today? Main changes after Java 8 Not all? 8 versions – Java 16 – March 2021 100+ JEP’s on Java 9 alone

Slide 7

Slide 7 text

@rodrigograciano @nehasardana09 Java 9 9 September 2017 Initially scheduled to September 2016 - delayed 3 years after Java 8 Huge number of changes – 100+

Slide 8

Slide 8 text

@rodrigograciano @nehasardana09 Jigsaw - JPMS u Scheduled to Java 7 u 11 Java Enhancement Proposals (JEP’s) u Aims to reduce packages size u Split the JDK in parts – Modules u More control over packages u Eliminates the “Jar Hell” u Main module (Root) is java.base u It’s Java – 100% backwards compatible 9

Slide 9

Slide 9 text

@rodrigograciano @nehasardana09 Garbage First Collector - G1 u Default choice starting at Java 9 u Substitute Concurrent Mark Swap (CMS) – Stop the world u Smaller pause time u Memory is split in regions - 1-32MB u Goal is to have 2048 regions (Heap) 9

Slide 10

Slide 10 text

@rodrigograciano @nehasardana09 Collections – Factory Methods u Reduce the “boilerplate” u Return Immutable collections u List numbers = List.of(1,2,3); u Set cities = Set.of(”New York City", ”Boston”); u Map m2 = Map.ofEntries( Map.entry("A",1), Map.entry("B",2) ); 9

Slide 11

Slide 11 text

@rodrigograciano @nehasardana09 JShell 9 u Easy to use u Useful to teach Java language u Read-Eval-Print-Loop

Slide 12

Slide 12 text

@rodrigograciano @nehasardana09 Others u Interfaces can now have private methods (static and non-static) u Reactive Streams API u Improvements to Optional, try-with resources, streams and Javadoc (HTML 5) u HTTP2 9

Slide 13

Slide 13 text

@rodrigograciano @nehasardana09 Java 10 10 March 2018 First release using the new release cadency – Every 6 months Feature Release – It’s not LTS 12 JEP’s

Slide 14

Slide 14 text

@rodrigograciano @nehasardana09 Local Variable Type Inference (var) 10 var is a variable type Cannot be a class attribute No relation with var/val from Scala/Kotlin String name = “Java”; var name = “Java”; var myMap = new HashMap(); //Map() Must be initialized – var age; //Not valid var var = “var”;

Slide 15

Slide 15 text

@rodrigograciano @nehasardana09 Others u Experimental JIT Compiler – Graal Ahead-of-Time (AOT) u Parallel G1 GC to improve full GC performance u AppCDS to improve start-up time u New API’s to create collections u List.copyOf(), Set.copyOf(), and Map.copyOf() u Stream API can collect data in an immutable collection u toUnmodifiableList(), toUnmodifiableSet(), and toUnmodifiableMap() 10

Slide 16

Slide 16 text

@rodrigograciano @nehasardana09 Java 11 11 September 2018 LTS – Next LTS will be Java 17 Java EE -> Jakarta EE Java EE source code was separated from the repository

Slide 17

Slide 17 text

@rodrigograciano @nehasardana09 GC’s u Epsilon GC – no-op collector. Perfect for benchmarking u Z GC – Experimental low-latency uWorks with all sizes of heaps – From small to Terabytes uPause time must not exceed 10ms 11

Slide 18

Slide 18 text

@rodrigograciano @nehasardana09 Others 11 u Flight Recorder u Single file source code programs

Slide 19

Slide 19 text

@rodrigograciano @nehasardana09 Java 12 12 March 2019 Feature Release Preview Features Small Release - 8 JEP's

Slide 20

Slide 20 text

@rodrigograciano @nehasardana09 Switch Expressions 12

Slide 21

Slide 21 text

@rodrigograciano @nehasardana09 Others u Shenandoah GC – Constant pause time - Experimental u Microbenchmark Suite - based on JMH u Default CDS Archives – Enhance JDK process to generate a CDS archive u Enhance to G1. Automatically return Java heap memory to the operating system when idle 12

Slide 22

Slide 22 text

@rodrigograciano @nehasardana09 Java 13 13 September 2019 Feature Release Preview Features Just 5 JEP's

Slide 23

Slide 23 text

@rodrigograciano @nehasardana09 Text Blocks 13 u Before Text Blocks u With Text Blocks

Slide 24

Slide 24 text

@rodrigograciano @nehasardana09 Others u Switch Expression – 2nd preview u Improvements to ZGC u Dynamic CDS archives u Reimplement the Legacy Socket API 13

Slide 25

Slide 25 text

@rodrigograciano @nehasardana09 Java 14 14 March 2020 Feature Release Preview and Final Features 16 JEP's

Slide 26

Slide 26 text

@rodrigograciano @nehasardana09 Records 14

Slide 27

Slide 27 text

@rodrigograciano @nehasardana09 Records (2) u Immutable u Reduce the boilerplate 14

Slide 28

Slide 28 text

@rodrigograciano @nehasardana09 Records (3) 14

Slide 29

Slide 29 text

@rodrigograciano @nehasardana09 Helpful NPE u Clearer NPE messages u Possible to know which object is null list.get(0).getName().trim(); u Where’s the null object? The list? Name? Cannot invoke "String.trim()" because the return value of "dev.graciano.Person.getName()" is null 14

Slide 30

Slide 30 text

@rodrigograciano @nehasardana09 Pattern Matching for instanceOf u Don’t need to explicitly cast after the instanceOf if (p instanceOf People people) { people.getName(); } 14

Slide 31

Slide 31 text

@rodrigograciano @nehasardana09 Others u JFR Streaming u Switch Expression – Final version u Text Blocks – 2nd Preview u ZGC on Windows and MacOS u Remove Concurrent Market Sweep GC (CMS) 14

Slide 32

Slide 32 text

@rodrigograciano @nehasardana09 Java 15 15 September 2020 Feature Release Preview and Final Features 14 JEP's

Slide 33

Slide 33 text

@rodrigograciano @nehasardana09 Sealed Classes u Permits to control who can extends/implements a class/interface public abstract sealed class Shape permits Circle, Square, Triangle {…} 15

Slide 34

Slide 34 text

@rodrigograciano @nehasardana09 Others u ZGC and Shenandoah not experimental anymore u Text Blocks not a Preview Feature u Hidden classes u 2nd Preview of Records u 2nd Preview of Pattern Matching for instanceOf 15

Slide 35

Slide 35 text

@rodrigograciano @nehasardana09 Java 16 16 March 2021 Feature Release 17 JEP’s

Slide 36

Slide 36 text

@rodrigograciano @nehasardana09 What’s new? 16 u OpenJDK migrated from Mercurial to Git (GitHub) u Enhance the ZGC u Vector API u Final version of Records u Final version of Pattern Matching for instanceOf u 2nd Preview of Sealed Classes u Strongly Encapsulated JDK Internals

Slide 37

Slide 37 text

@rodrigograciano @nehasardana09 Java 17 17 September 2021 LT Release 13 JEP’s so far

Slide 38

Slide 38 text

@rodrigograciano @nehasardana09 What’s new? 17 u Sealed Classes u Remove Experimental AOT & JIT Compiler u Vector API (2nd Incubator) u Pattern Matching for switch (Preview) u Strongly Encapsulated JDK Internals u Deprecate Security Manager for Removal u Enhanced Pseudo-Random Number Generators

Slide 39

Slide 39 text

@rodrigograciano @nehasardana09 More from Java 10/11 import java.nio.charset.*; public class Unicode { public static void main(String... args) { System.out.print(”Have a \uD83C\uDF7A"); System.out.println(" or a \uD83E\uDD64 "); } } 10/11 Slide extracted from https://speakerdeck.com/boyarsky

Slide 40

Slide 40 text

@rodrigograciano @nehasardana09 End u graciano.dev u Twitter: @rodrigograciano u neha-nsit.medium.com u Twitter: @nehasardana09