SlideShare a Scribd company logo
Beyond
Java 8
M. Dorra
July 17, 2020
How does Java
evolve?
● Java Community Process (JCP)
● Java/JDK Enhancement Proposal (JEP)
● Java Specification Request (JSR)
● JDK is a set of specifications, even JVM
● Many implementations
○ OracleJDK
○ OpenJDK
○ Corretto
○ Azul
○ Many other...
Specifications and Implementations
● More Agile
●
The new Release Cycle
The new Release Cycle
JEPs, JEPs… JEPs
● Modular System – Jigsaw Project
● JShell: the interactive Java REPL TryJShell
● Collection factory methods
● Interface Private Method
Java 9 features
Modular System – Jigsaw Project
● Better separation of concerns
● Stronger encapsulation to Java applications
● Package of Java Packages
module com.billing{
exports com.billing.iface;
}
module com.activity{
requires com.billing;
}
A Module is a group of closely related packages and resources along
with a new module descriptor file.
Collection factory methods
List<Integer> numbers = new ArrayList<>();
numbers.add(1);
numbers.add(2);
numbers.add(3);
Set<String> strings = new HashSet<>();
strings.add(“foo”);
strings.add(“bar”);
strings.add(“baz”);
Set<String> strings = Set.of("foo", "bar", "baz");
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> numbers = List.of(1, 2, 3, 4, 5);
Map<String, Integer> map = Map.of(
“ONE”, 1,
“TWO”, 2,
“THREE”, 3);
public interface Map<K,V>{
/**
* @since 9
*/
static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2){…}
static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3){…}
…
static <K, V> Map<K, V> of(K k1, V v1, … …, K k9, V v9){…}
Collection factory methods
Map<String, Integer> map = new TreeMap<>();
map.put(“ONE”, 1);
map.add(“TWO”, 2);
map.add(“THREE”, 3);
Interface Private Method
public interface BillingService{
default BillingBo calculate(BillingBo billing){
init(billing);
return doCalculate(billing);
}
BillingBo doCalculate(BillingBo billing);
private void init(BillingBo billing){
billing.setExportStatus(NOT_BILLED);
}
}
● Local-Variable Type Inference
● Collectors toUnmodifiable*()
● Optional*.orElseThrow()
● …
Java 10 features
● Limited only to Local Variable with initializer
● Indexes of enhanced for loop or indexes
● Local declared in for loop
● Not applicable to define a lambda
Local-Variable Type Inference
List<Integer> numbers = List.of(1, 2, 3, 4, 5); // Java 9
for (Integer number : numbers) {
System.out.println(number);
}
for (int i = 0; i < numbers.size(); i++) {
System.out.println(numbers.get(i));
}
● Limited only to Local Variable with initializer
● Indexes of enhanced for loop or indexes
● Local declared in for loop
Local-Variable Type Inference
var numbers = List.of(1, 2, 3, 4, 5);
for (var number : numbers) {
System.out.println(number);
}
for (var i = 0; i < numbers.size(); i++) {
System.out.println(numbers.get(i));
}
List<Map<String, String>> cabins = configManager.query(List.class, …)
var cabins = configManager.query(List.class, …)
Collectors toUnmodifiable*()
List<String> mutable = Stream.of("A").collect(Collectors.toList());
mutable.add(“B”);
List<String> immutable =
Stream.of("A").collect(Collectors.toUnmodifiableList());
immutable.add(“B”); // UnsupportedOperationException
Collectors.toUnmodifiableMap(…)
Collectors.toUnmodifiableSet()
Optional*.orElseThrow()
Optional<String> optional = Optional.ofNullable(null);
optional.get(); // NoSuchElementException
optional.orElseThrow();
//default of orElseThrow(Supplier<Exception> supplier)
● Makes more sense of usage
● New String methods
● Local-Variable Syntax for Lambda Parameters
● Implicitly compile and run
● …
Java 11 features
New String methods
org.apache.commons.lang.StringUtils.isEmpty()
org.apache.commons.lang.StringUtils.isBlank()
String myString = “Java 11”;
myString.isBlank();
myString = “Java 11n Java 12”;
myString.lines();
myString = “ Java 11 ”;
myString.strip();  trim()?  unicode
myString.stripLeading();
myString.stripHeading();
Local-Variable Syntax for Lambda
Parameters
var list = List.of(“A”, ”B”);
for(var item: list){…}
BiFunction<K, K, O> sum = (num1, num2) -> num1 + num2;
BiFunction<K, K, O> equals = (@Nonnull var obj1, var obj2) -> obj1 + obj2;
equals(null, new Object());
Some Rules for that:
(var s1, s2) -> s1 + s2 //no skipping allowed
(var s1, String y) -> s1 + y //no mixing allowed
var s1 -> s1 //not allowed. Need parentheses if you use var in
lambda.
Implicitly compile and run
public interface ByeWorld2020 {
public static void main(String … args){
System.out.println(“2020 O_o .. Bye, World!.”);
}
}
$> java ByWorld2020
$> javac ByWorld2020.java
Limited to single file classes :D
$> java ByWorld2020.java
$> 2020 O_o .. Bye, World!.
$>
● Switch Expressions (J12 preview, J14 feature)
● Pattern Matching for instanceof (J12 preview, J14 feature)
● Multi-line texts (J13 preview, J14 feature)
● Switch Expressions with yield
● Records (J14 preview)
● Helpful NullPointerException(s)
Java 12-14 features
Switch Expressions
enum Status {ON, OFF, UNKNOWN}
var status = Status.ON;
String result = “”;
switch(status){
case ON: result = “On”; break;
case OFF: result = “Off”; break;
case UNKNOWN: default: result = “Unknown”; break;
}
Statement vs Expression?
Switch Expressions
enum Status {ON, OFF, UNKNOWN}
var status = Status.ON;
String result = switch(status) {
case ON -> “On”;
case OFF -> “Off”;
case UNKNOWN, default -> “Unknown”;
}
Statement vs Expression?
Pattern Matching for instanceof
interface Flyable { void fly(); }
class Bird implements Flyable { public void fly(){…}
void birdEat();
}
class Eagle implements Flyable { public void fly(){…}
void eagleEat();
}
void runner(Flyable flyable) {
if(flyable instanceof Bird) {
Bird asBird = (Bird) flyable;
asBird.birdEat();
}
}
Pattern Matching for instanceof
interface Flyable { void fly(); }
class Bird implements Flyable { public void fly(){…}
void birdEat();
}
class Eagle implements Flyable { public void fly(){…}
void eagleEat();
}
void runner(Flyable flyable) {
if(flyable instanceof Bird asBird) {
Bird asBird = (Bird) flyable;
asBird.birdEat();
}
}
Pattern Matching for instanceof
interface Flyable { void fly(); }
class Bird implements Flyable { public void fly(){…}
void birdEat();
Boolean isX();
}
class Eagle implements Flyable { public void fly(){…}
void eagleEat();
}
void runner(Flyable flyable) {
if(flyable instanceof Bird asBird && asBird.isX()) {
Bird asBird = (Bird) flyable;
asBird.birdEat();
}
}
Pattern Matching for instanceof
interface Flyable { void fly(); }
class Bird implements Flyable { public void fly(){…}
void birdEat();
Boolean isX();
}
class Eagle implements Flyable { public void fly(){…}
void eagleEat();
}
void runner(Flyable flyable) {
if(flyable instanceof Bird asBird || asBird.isX()){
Bird asBird = (Bird) flyable;
asBird.birdEat();
}
}
Will not work
Pattern Matching for instanceof
trait Flyable
case class Bird (color: String) implements Flyable
case class Eagle implements Flyable
Flyable flyable = Bird(“<string>”)
val someVal = flyable match {
case Bird(“Red”) => …
case Bird(_) => …
case _ => …
}
Scala world
Multi-line texts
myStr = ‘’’
{“name”:”Groovy and Python”}
‘’’
val myStr = “””
{“name”:”Scala”}
“””
Already there in many languages
Multi-line texts
var query = “SELECT * FROM BILLINGS WHERE 1=1 “
+ ” AND OWNER = ‘MAG’ AND status = ‘BILLED’ ”
+ “ AND ACTION = ‘FLIGHT’”;
Already there in many languages
var query = “”” SELECT * FROM BILLINGS WHERE 1=1
AND OWNER = ‘MAG’ AND status = ‘BILLED’
AND ACTION = ‘FLIGHT’
“””;
Switch Expressions with yield
enum Status {ON, OFF, UNKNOWN}
var status = Status.ON;
String result = switch(status) {
case ON -> doSomeLogic();…; yield “On”;
case OFF -> doOtherLogic();…; yield “Off”;
case UNKNOWN -> doAnotherLogic();…; yield “Unknown”;
default -> out.println(“Why am I here?”); yield “Not Required”;
}
Records (data class)
class Bill {
many fields;
many getters;
many setters;
}
@lombok.Data
@lombok.Getter
@lombok.Setter
@lombok.ToString
@lombok. EqualsAndHashCode
class Bill {
many fields;
}
record Bill(fields) {
}
Helpful NullPointerException(s)
1. class NullPointerExample{
2. public static void main(String… args){
3. var b = new B();
4. String name = b.a.method();
5. }
6. }
class A {void method(){…}}
class B {A a;}
//Stacktrace
Exception in thread "main" java.lang.NullPointerException
at NullPointerExample.main(NullPointerExample.java:4)
//Stacktrace
Exception in thread "main" java.lang.NullPointerException 
Cannot invoke “A.method” because the return value of b.a is null
at NullPointerExample.main(NullPointerExample.java:4)
Many Other Enhancements
● Experimental Java-Based JIT Compiler (See
GraalVM)
● Enhanced GC: Parallel Full GC for G1
● HTTP Client with support for HTTP/2 and
websocket
● Reactive subscriber and publisher model (Flow)
● Remove the Java EE and CORBA Modules
● Deprecate the Nashorn JavaScript Engine
● … Tons of features
References
● JCP
● JEPs
● OpenJDK
● OpenJDK 14
● OpenJDK 15
Thank you

More Related Content

PDF
Scala vs Java 8 in a Java 8 World
BTI360
 
PDF
Functional Principles for OO Developers
jessitron
 
PDF
Introduction to Clean Code
Julio Martinez
 
PDF
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
Ruslan Shevchenko
 
PPTX
Use of Apache Commons and Utilities
Pramod Kumar
 
PDF
What You Need to Know about Lambdas
Ryan Knight
 
PDF
Charles Sharp: Java 8 Streams
jessitron
 
PDF
Contracts in-clojure-pete
jessitron
 
Scala vs Java 8 in a Java 8 World
BTI360
 
Functional Principles for OO Developers
jessitron
 
Introduction to Clean Code
Julio Martinez
 
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
Ruslan Shevchenko
 
Use of Apache Commons and Utilities
Pramod Kumar
 
What You Need to Know about Lambdas
Ryan Knight
 
Charles Sharp: Java 8 Streams
jessitron
 
Contracts in-clojure-pete
jessitron
 

What's hot (20)

PDF
Scala coated JVM
Stuart Roebuck
 
PDF
Java Generics - by Example
Ganesh Samarthyam
 
PDF
Scala vs java 8
François Sarradin
 
PDF
Coding Guidelines - Crafting Clean Code
Ganesh Samarthyam
 
PDF
Pragmatic Real-World Scala (short version)
Jonas Bonér
 
PDF
Fundamental JavaScript [UTC, March 2014]
Aaron Gustafson
 
PDF
Starting with Scala : Frontier Developer's Meetup December 2010
Derek Chen-Becker
 
PDF
Some OOP paradigms & SOLID
Julio Martinez
 
PPTX
All about scala
Yardena Meymann
 
PDF
Scala test
Inphina Technologies
 
PPTX
Java Generics
Zülfikar Karakaya
 
PDF
Programming in Scala: Notes
Roberto Casadei
 
PDF
Stepping Up : A Brief Intro to Scala
Derek Chen-Becker
 
PDF
Scala at HUJI PL Seminar 2008
Yardena Meymann
 
PPTX
Intro to Functional Programming in Scala
Shai Yallin
 
PPTX
Scala on Android
Jakub Kahovec
 
PDF
Procedure Typing for Scala
akuklev
 
PPT
Scala in a nutshell by venkat
Venkateswaran Kandasamy
 
PDF
The TclQuadcode Compiler
Donal Fellows
 
PPT
Scala introduction
Yardena Meymann
 
Scala coated JVM
Stuart Roebuck
 
Java Generics - by Example
Ganesh Samarthyam
 
Scala vs java 8
François Sarradin
 
Coding Guidelines - Crafting Clean Code
Ganesh Samarthyam
 
Pragmatic Real-World Scala (short version)
Jonas Bonér
 
Fundamental JavaScript [UTC, March 2014]
Aaron Gustafson
 
Starting with Scala : Frontier Developer's Meetup December 2010
Derek Chen-Becker
 
Some OOP paradigms & SOLID
Julio Martinez
 
All about scala
Yardena Meymann
 
Java Generics
Zülfikar Karakaya
 
Programming in Scala: Notes
Roberto Casadei
 
Stepping Up : A Brief Intro to Scala
Derek Chen-Becker
 
Scala at HUJI PL Seminar 2008
Yardena Meymann
 
Intro to Functional Programming in Scala
Shai Yallin
 
Scala on Android
Jakub Kahovec
 
Procedure Typing for Scala
akuklev
 
Scala in a nutshell by venkat
Venkateswaran Kandasamy
 
The TclQuadcode Compiler
Donal Fellows
 
Scala introduction
Yardena Meymann
 
Ad

Similar to Beyond java8 (20)

PPT
Java Intro
backdoor
 
PPTX
Intro to scala
Joe Zulli
 
PDF
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
PDF
An Introduction to Scala for Java Developers
Miles Sabin
 
ODP
Scala ntnu
Alf Kristian Støyle
 
PDF
Scala + WattzOn, sitting in a tree....
Raffi Krikorian
 
PPTX
05 pig user defined functions (udfs)
Subhas Kumar Ghosh
 
PDF
Workshop Scala
Bert Van Vreckem
 
PDF
Scala in Places API
Łukasz Bałamut
 
PPT
Scala uma poderosa linguagem para a jvm
Isaias Barroso
 
PPTX
A Brief Intro to Scala
Tim Underwood
 
PDF
FP in Java - Project Lambda and beyond
Mario Fusco
 
PDF
Querydsl fin jug - june 2012
Timo Westkämper
 
PDF
The Future of JVM Languages
VictorSzoltysek
 
PPTX
Java fundamentals
HCMUTE
 
PPT
Java tut1
Sumit Tambe
 
PPT
Javatut1
desaigeeta
 
PPT
Java tut1 Coderdojo Cahersiveen
Graham Royce
 
PPT
Java tut1
Sumit Tambe
 
PPT
Java_Tutorial_Introduction_to_Core_java.ppt
Govind Samleti
 
Java Intro
backdoor
 
Intro to scala
Joe Zulli
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
An Introduction to Scala for Java Developers
Miles Sabin
 
Scala + WattzOn, sitting in a tree....
Raffi Krikorian
 
05 pig user defined functions (udfs)
Subhas Kumar Ghosh
 
Workshop Scala
Bert Van Vreckem
 
Scala in Places API
Łukasz Bałamut
 
Scala uma poderosa linguagem para a jvm
Isaias Barroso
 
A Brief Intro to Scala
Tim Underwood
 
FP in Java - Project Lambda and beyond
Mario Fusco
 
Querydsl fin jug - june 2012
Timo Westkämper
 
The Future of JVM Languages
VictorSzoltysek
 
Java fundamentals
HCMUTE
 
Java tut1
Sumit Tambe
 
Javatut1
desaigeeta
 
Java tut1 Coderdojo Cahersiveen
Graham Royce
 
Java tut1
Sumit Tambe
 
Java_Tutorial_Introduction_to_Core_java.ppt
Govind Samleti
 
Ad

Recently uploaded (20)

PDF
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PDF
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PPTX
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PDF
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
Exploring AI Agents in Process Industries
amoreira6
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 

Beyond java8

  • 3. ● Java Community Process (JCP) ● Java/JDK Enhancement Proposal (JEP) ● Java Specification Request (JSR) ● JDK is a set of specifications, even JVM ● Many implementations ○ OracleJDK ○ OpenJDK ○ Corretto ○ Azul ○ Many other... Specifications and Implementations
  • 4. ● More Agile ● The new Release Cycle
  • 7. ● Modular System – Jigsaw Project ● JShell: the interactive Java REPL TryJShell ● Collection factory methods ● Interface Private Method Java 9 features
  • 8. Modular System – Jigsaw Project ● Better separation of concerns ● Stronger encapsulation to Java applications ● Package of Java Packages module com.billing{ exports com.billing.iface; } module com.activity{ requires com.billing; } A Module is a group of closely related packages and resources along with a new module descriptor file.
  • 9. Collection factory methods List<Integer> numbers = new ArrayList<>(); numbers.add(1); numbers.add(2); numbers.add(3); Set<String> strings = new HashSet<>(); strings.add(“foo”); strings.add(“bar”); strings.add(“baz”); Set<String> strings = Set.of("foo", "bar", "baz"); List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5); List<Integer> numbers = List.of(1, 2, 3, 4, 5);
  • 10. Map<String, Integer> map = Map.of( “ONE”, 1, “TWO”, 2, “THREE”, 3); public interface Map<K,V>{ /** * @since 9 */ static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2){…} static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3){…} … static <K, V> Map<K, V> of(K k1, V v1, … …, K k9, V v9){…} Collection factory methods Map<String, Integer> map = new TreeMap<>(); map.put(“ONE”, 1); map.add(“TWO”, 2); map.add(“THREE”, 3);
  • 11. Interface Private Method public interface BillingService{ default BillingBo calculate(BillingBo billing){ init(billing); return doCalculate(billing); } BillingBo doCalculate(BillingBo billing); private void init(BillingBo billing){ billing.setExportStatus(NOT_BILLED); } }
  • 12. ● Local-Variable Type Inference ● Collectors toUnmodifiable*() ● Optional*.orElseThrow() ● … Java 10 features
  • 13. ● Limited only to Local Variable with initializer ● Indexes of enhanced for loop or indexes ● Local declared in for loop ● Not applicable to define a lambda Local-Variable Type Inference List<Integer> numbers = List.of(1, 2, 3, 4, 5); // Java 9 for (Integer number : numbers) { System.out.println(number); } for (int i = 0; i < numbers.size(); i++) { System.out.println(numbers.get(i)); }
  • 14. ● Limited only to Local Variable with initializer ● Indexes of enhanced for loop or indexes ● Local declared in for loop Local-Variable Type Inference var numbers = List.of(1, 2, 3, 4, 5); for (var number : numbers) { System.out.println(number); } for (var i = 0; i < numbers.size(); i++) { System.out.println(numbers.get(i)); } List<Map<String, String>> cabins = configManager.query(List.class, …) var cabins = configManager.query(List.class, …)
  • 15. Collectors toUnmodifiable*() List<String> mutable = Stream.of("A").collect(Collectors.toList()); mutable.add(“B”); List<String> immutable = Stream.of("A").collect(Collectors.toUnmodifiableList()); immutable.add(“B”); // UnsupportedOperationException Collectors.toUnmodifiableMap(…) Collectors.toUnmodifiableSet()
  • 16. Optional*.orElseThrow() Optional<String> optional = Optional.ofNullable(null); optional.get(); // NoSuchElementException optional.orElseThrow(); //default of orElseThrow(Supplier<Exception> supplier) ● Makes more sense of usage
  • 17. ● New String methods ● Local-Variable Syntax for Lambda Parameters ● Implicitly compile and run ● … Java 11 features
  • 18. New String methods org.apache.commons.lang.StringUtils.isEmpty() org.apache.commons.lang.StringUtils.isBlank() String myString = “Java 11”; myString.isBlank(); myString = “Java 11n Java 12”; myString.lines(); myString = “ Java 11 ”; myString.strip();  trim()?  unicode myString.stripLeading(); myString.stripHeading();
  • 19. Local-Variable Syntax for Lambda Parameters var list = List.of(“A”, ”B”); for(var item: list){…} BiFunction<K, K, O> sum = (num1, num2) -> num1 + num2; BiFunction<K, K, O> equals = (@Nonnull var obj1, var obj2) -> obj1 + obj2; equals(null, new Object()); Some Rules for that: (var s1, s2) -> s1 + s2 //no skipping allowed (var s1, String y) -> s1 + y //no mixing allowed var s1 -> s1 //not allowed. Need parentheses if you use var in lambda.
  • 20. Implicitly compile and run public interface ByeWorld2020 { public static void main(String … args){ System.out.println(“2020 O_o .. Bye, World!.”); } } $> java ByWorld2020 $> javac ByWorld2020.java Limited to single file classes :D $> java ByWorld2020.java $> 2020 O_o .. Bye, World!. $>
  • 21. ● Switch Expressions (J12 preview, J14 feature) ● Pattern Matching for instanceof (J12 preview, J14 feature) ● Multi-line texts (J13 preview, J14 feature) ● Switch Expressions with yield ● Records (J14 preview) ● Helpful NullPointerException(s) Java 12-14 features
  • 22. Switch Expressions enum Status {ON, OFF, UNKNOWN} var status = Status.ON; String result = “”; switch(status){ case ON: result = “On”; break; case OFF: result = “Off”; break; case UNKNOWN: default: result = “Unknown”; break; } Statement vs Expression?
  • 23. Switch Expressions enum Status {ON, OFF, UNKNOWN} var status = Status.ON; String result = switch(status) { case ON -> “On”; case OFF -> “Off”; case UNKNOWN, default -> “Unknown”; } Statement vs Expression?
  • 24. Pattern Matching for instanceof interface Flyable { void fly(); } class Bird implements Flyable { public void fly(){…} void birdEat(); } class Eagle implements Flyable { public void fly(){…} void eagleEat(); } void runner(Flyable flyable) { if(flyable instanceof Bird) { Bird asBird = (Bird) flyable; asBird.birdEat(); } }
  • 25. Pattern Matching for instanceof interface Flyable { void fly(); } class Bird implements Flyable { public void fly(){…} void birdEat(); } class Eagle implements Flyable { public void fly(){…} void eagleEat(); } void runner(Flyable flyable) { if(flyable instanceof Bird asBird) { Bird asBird = (Bird) flyable; asBird.birdEat(); } }
  • 26. Pattern Matching for instanceof interface Flyable { void fly(); } class Bird implements Flyable { public void fly(){…} void birdEat(); Boolean isX(); } class Eagle implements Flyable { public void fly(){…} void eagleEat(); } void runner(Flyable flyable) { if(flyable instanceof Bird asBird && asBird.isX()) { Bird asBird = (Bird) flyable; asBird.birdEat(); } }
  • 27. Pattern Matching for instanceof interface Flyable { void fly(); } class Bird implements Flyable { public void fly(){…} void birdEat(); Boolean isX(); } class Eagle implements Flyable { public void fly(){…} void eagleEat(); } void runner(Flyable flyable) { if(flyable instanceof Bird asBird || asBird.isX()){ Bird asBird = (Bird) flyable; asBird.birdEat(); } } Will not work
  • 28. Pattern Matching for instanceof trait Flyable case class Bird (color: String) implements Flyable case class Eagle implements Flyable Flyable flyable = Bird(“<string>”) val someVal = flyable match { case Bird(“Red”) => … case Bird(_) => … case _ => … } Scala world
  • 29. Multi-line texts myStr = ‘’’ {“name”:”Groovy and Python”} ‘’’ val myStr = “”” {“name”:”Scala”} “”” Already there in many languages
  • 30. Multi-line texts var query = “SELECT * FROM BILLINGS WHERE 1=1 “ + ” AND OWNER = ‘MAG’ AND status = ‘BILLED’ ” + “ AND ACTION = ‘FLIGHT’”; Already there in many languages var query = “”” SELECT * FROM BILLINGS WHERE 1=1 AND OWNER = ‘MAG’ AND status = ‘BILLED’ AND ACTION = ‘FLIGHT’ “””;
  • 31. Switch Expressions with yield enum Status {ON, OFF, UNKNOWN} var status = Status.ON; String result = switch(status) { case ON -> doSomeLogic();…; yield “On”; case OFF -> doOtherLogic();…; yield “Off”; case UNKNOWN -> doAnotherLogic();…; yield “Unknown”; default -> out.println(“Why am I here?”); yield “Not Required”; }
  • 32. Records (data class) class Bill { many fields; many getters; many setters; } @lombok.Data @lombok.Getter @lombok.Setter @lombok.ToString @lombok. EqualsAndHashCode class Bill { many fields; } record Bill(fields) { }
  • 33. Helpful NullPointerException(s) 1. class NullPointerExample{ 2. public static void main(String… args){ 3. var b = new B(); 4. String name = b.a.method(); 5. } 6. } class A {void method(){…}} class B {A a;} //Stacktrace Exception in thread "main" java.lang.NullPointerException at NullPointerExample.main(NullPointerExample.java:4) //Stacktrace Exception in thread "main" java.lang.NullPointerException Cannot invoke “A.method” because the return value of b.a is null at NullPointerExample.main(NullPointerExample.java:4)
  • 34. Many Other Enhancements ● Experimental Java-Based JIT Compiler (See GraalVM) ● Enhanced GC: Parallel Full GC for G1 ● HTTP Client with support for HTTP/2 and websocket ● Reactive subscriber and publisher model (Flow) ● Remove the Java EE and CORBA Modules ● Deprecate the Nashorn JavaScript Engine ● … Tons of features
  • 35. References ● JCP ● JEPs ● OpenJDK ● OpenJDK 14 ● OpenJDK 15