SlideShare a Scribd company logo
Java 17: Deep Dive
José Paumard
Java Developer Advocate
Java Platform Group
https://twitter.com/JosePaumard
https://github.com/JosePaumard
https://www.youtube.com/c/JosePaumard01
https://www.youtube.com/user/java
https://www.youtube.com/hashtag/jepcafe
https://fr.slideshare.net/jpaumard
https://www.pluralsight.com/authors/jose-paumard
https://jchateau.org
https://twitter.com/JosePaumard
https://github.com/JosePaumard
https://www.youtube.com/c/JosePaumard01
https://www.youtube.com/user/java
https://www.youtube.com/hashtag/jepcafe
https://fr.slideshare.net/jpaumard
https://www.pluralsight.com/authors/jose-paumard
https://dev.java
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
4
Dev.java
Java 8 Java 11
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
5
Java 17 – LTS !
Java 8 Java 11
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
6
OpenJDK?
https://openjdk.java.net
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
7
New Release Cadence!
11
12
13
14
15
16
17
18
19
20
21
22
23
2018 2019 2020 2021 2022 2023 2024 2025
http://jdk.java.net/
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
8
New Release Cadence!
11
12
13
14
15
16
17
18
19
20
21
22
http://jdk.java.net/
23
2018 2019 2020 2021 2022 2023 2024 2025
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
9
New Release Cadence!
11
12
13
14
15
16
17
18
19
20
21
22
https://www.oracle.com/java/
technologies/javase-
downloads.html
23
2018 2019 2020 2021 2022 2023 2024 2025
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
10
New New Release Cadence!
11
12
13
14
15
16
17
18
19
20
21
22
1) LTS: 3 years  2 years
23
2018 2019 2020 2021 2022 2023 2024 2025
https://mreinhold.org/blog/forward-even-faster
https://blogs.oracle.com/java/post/
moving-the-jdk-to-a-two-year-lts-cadence
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
11
New New Release Cadence!
11
12
13
14
15
16
17
18
19
20
21
22
2018 2019 2020 2021 2022 2023 2024 2025
23
1) LTS: 3 years  2 years
https://mreinhold.org/blog/forward-even-faster
https://blogs.oracle.com/java/post/
moving-the-jdk-to-a-two-year-lts-cadence
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
12
New New Release Cadence!
11
12
13
14
15
16
17
18
19
20
21
22
2018 2019 2020 2021 2022 2023 2024 2025
23
1) LTS: 3 years  2 years
2) Free licence (dev + prod)
3) No click-through
https://blogs.oracle.com/java/post/
free-java-license
Sept.
2021
Mars
2014
4
Years
90
80
70
60
50
40
30
20
10
0
56
91
12
17
8
5
16
14
17
14
Mars
2018 3
Years
JDK 8 LTS JDK 9-11 JDK 12-17
JDK 9
JDK 10
JDK 11 LTS
JDK 12
JDK 13
JDK 14
JDK 15
JDK 16
JDK 17 LTS
Features
From 8 to 17
Copyright © 2021, Oracle and/or its affiliates
13
Language
Type inference for locals (var)
Switch expressions
Text blocks
Record classes
Sealed classes
Pattern matching for instanceof
JDK 17: New Features Since the JDK 8
Copyright © 2021, Oracle and/or its affiliates
14
Tools
jshell
jlink
jdeps
jpackage
java source code launcher
javadoc search + API history
JVM
Garbage Collectors: G1, ZGC
AArch64 support: Windows, Mac, Linux
Docker awareness
Class Data Sharing by default
Helpful NullPointerExceptions
Hidden classes
Libraries
HTTP client
Collection factories
Unix-domain sockets
Stack walker
Deserialization filtering
Pseudo-RNG, SHA-3, TLS 1.3
11/2/2021
Copyright © 2021, Oracle and/or its affiliates | Confidential: Internal/Restricted/Highly Restricted
15
Tools
Language
Type inference for locals (var)
Switch expressions
Text blocks
Record classes
Sealed classes
Pattern matching for instanceof
JDK 17: New Features Since the JDK 8
Copyright © 2021, Oracle and/or its affiliates
16
Tools
jshell
jlink
jdeps
jpackage
java source code launcher
javadoc search + API history
JVM
Garbage Collectors: G1, ZGC
AArch64 support: Windows, Mac, Linux
Docker awareness
Class Data Sharing by default
Helpful NullPointerExceptions
Hidden classes
Libraries
HTTP client
Collection factories
Unix-domain sockets
Stack walker
Deserialization filtering
Pseudo-RNG, SHA-3, TLS 1.3
Tools
jshell
jlink
jdeps
jpackage
java source code launcher
javadoc search + API history
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
17
Step 1: Hello World
Launching Single File Source Code
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
$ java HelloWorld.java
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
18
Step 2: Add 3rd party dependencies
Launching Single File Source Code
public class HelloWorld {
public static void main(String[] args) {
System.out.println(RandomUtils.nextInt());
}
}
$ java -cp /path/to/commons-lang3-3.12.0.jar HelloWorld.java
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
19
Step 3: Execute a shebang file
Launching Single File Source Code
#!/path/to/your/bin/java --source 17
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
$ ./HelloWorld
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
20
Create a runtime image
JLink: Creating Custom Runtime Images
$ jlink
--module-path mods
--add-modules org.mycompany.mymodule
--output myapp-image
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
21
Create a runtime image with a launcher
JLink: Creating Custom Runtime Images
# create the image
$ jlink
--module-path mods
--add-modules com.example.main
--launcher app=com.example.app/com.example.app.Main
--output app-image
# launch
$ app-image/bin/app
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
22
The smallest runtime image
JLink: Creating Custom Runtime Images
$ jlink
--add-modules java.base
--output jdk.base
$ du –sh jdk.base jdk-17
40M jdk.base
288M jdk-17
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
23
Supported Installers: MSI, EXE, RPM, DEB, PKG, DMG
JPackage: Creating Custom Installers
$ jpackage
--name my-installer
--app-version 1.0
--win-dir-chooser --win-console --win-shortcut
--module-path mymodules/my-app-1.0.jar
--module org.myapp/org.mycompany.myapp.MainClass
11/2/2021
Copyright © 2021, Oracle and/or its affiliates | Confidential: Internal/Restricted/Highly Restricted
24
API
Language
Type inference for locals (var)
Switch expressions
Text blocks
Record classes
Sealed classes
Pattern matching for instanceof
JDK 17: New Features Since the JDK 8
Copyright © 2021, Oracle and/or its affiliates
25
Tools
jshell
jlink
jdeps
jpackage
java source code launcher
javadoc search + API history
JVM
Garbage Collectors: G1, ZGC
AArch64 support: Windows, Mac, Linux
Docker awareness
Class Data Sharing by default
Helpful NullPointerExceptions
Hidden classes
Libraries
HTTP client
Collection factories
Unix-domain sockets
Stack walker
Deserialization filtering
Pseudo-RNG, SHA-3, TLS 1.3
Libraries
HTTP client
Collection factories
Unix-domain sockets
Stack walker
Deserialization filtering
Pseudo-RNG, SHA-3, TLS 1.3
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
26
Step 1: create a request
HttpClient API
HttpRequest request =
HttpRequest.newBuilder()
.uri(URI.create("https://example.com"))
.header("Accept-Encoding", "gzip")
.header("Accept", "text/xml")
.GET()
.build();
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
27
Step 2: create a client
HttpClient API
HttpClient client =
HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.connectTimeout(Duration.ofSeconds(20))
.build();
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
28
Step 3: send the request
HttpClient API
HttpResponse<InputStream> response =
client.send(request,
HttpResponse.BodyHandlers.ofInputStream());
InputStream inputStream = response.body();
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
29
Step 3: send the request
HttpClient API
HttpResponse<Stream<String>> response =
client.send(request,
HttpResponse.BodyHandlers.ofLines());
Stream<String> lines = response.body();
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
30
Open a web server for serving a single directory hierarchy.
Options:
Simple HttpServer: Command Line Tool & API
$ java -m jdk.httpserver
-b, --bind-address - Address to bind to. Default: 127.0.0.1 or ::1
(loopback).
For all interfaces use "-b 0.0.0.0" or "-b ::".
-d, --directory - Directory to serve. Default: current directory.
-o, --output - Output format. none|info|verbose. Default: info.
-p, --port - Port to listen on. Default: 8000.
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
31
The API version, in JShell
Supports HTTP only, request handling can be customized
Simple HttpServer: Command Line Tool & API
jshell> var server = SimpleFileServer.createFileServer(
> new InetSocketAddress(8080),
> Path.of("/some/path"),
> OutputLevel.VERBOSE);
jshell> server.start()
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
32
Supported on Linux, MacOS and some flavors of Windows
Both on the server and the client
Unix Domain Sockets
Path home = Path.of("/tmp");
Path file = home.resolve("user.socket");
UnixDomainSocketAddress socketAddress =
UnixDomainSocketAddress.of(file);
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
33
On the server:
On the client:
Unix Domain Sockets
ServerSocketChannel channel =
ServerSocketChannel.open(StandardProtocolFamily.UNIX);
SocketChannel socketChannel = channel.bind(socketAddress).accept();
SocketChannel socketChannel =
SocketChannel.open(socketAddress);
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
34
Current status: getting the execution stack is costly, it captures
the entire stack (getStackTrace() on Thread and Throwable)
Sometimes you only need the first elements of the stack
Idea: have a way of lazily explore the stack, based on a
Stream<StackFrame> and a callback
Stack Frame Walker
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
35
Stack Frame Walker
StackWalker walker =
StackWalker.getInstance(
StackWalker.Option.RETAIN_CLASS_REFERENCE);
walker.forEach(
stackFrame -> System.out.println(stackFrame.getClassName()));
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
36
Stack Frame Walker
Set<String> classNames = ...;
Optional<String> className = walker.walk(
stackFrameStream -> stackFrameStream
.map(StackWalker.StackFrame::getClassName)
.filter(classNames::contains)
.findFirst()
);
Language
Type inference for locals (var)
Switch expressions
Text blocks
Record classes
Sealed classes
Pattern matching for instanceof
JDK 17: New Features Since the JDK 8
Copyright © 2021, Oracle and/or its affiliates
37
Tools
jshell
jlink
jdeps
jpackage
java source code launcher
javadoc search + API history
JVM
Garbage Collectors: G1, ZGC
AArch64 support: Windows, Mac, Linux
Docker awareness
Class Data Sharing by default
Helpful NullPointerExceptions
Hidden classes
Libraries
HTTP client
Collection factories
Unix-domain sockets
Stack walker
Deserialization filtering
Pseudo-RNG, SHA-3, TLS 1.3
Language
Type inference for locals (var)
Switch expressions
Text blocks
Record classes
Sealed classes
Pattern matching for instanceof
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
38
Do not override finalize()
Stop doing that!
@Deprecated(since="9")
protected void finalize() throws Throwable {
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
39
Do not call new Integer(...)
Stop doing that!
@Deprecated(since="9", forRemoval = true)
public Integer(int value) {
this.value = value;
}
@IntrinsicCandidate
public static Integer valueOf(int i) {
// some code
return new Integer(i);
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
40
☕ Coffee Break!
Record and Array Pattern Matching
Record
Sealed Classes
Switch Expression
Constant Dynamic
Inner Classes
private in VM
Nestmates
Pattern Matching for instanceof
11
14
16
17 Switch on Patterns
18
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
42
In reference to the Amber by Roger
Zelazny
Project Amber
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
43
A pattern is a combination of a match predicate
that determines if the pattern matches a target,
along with a set of pattern variables
that are conditionally extracted if the pattern
matches the target.
Java 16 : Pattern Match for IntanceOf
Pattern Matching for Java
Gavin Bierman and Brian Goetz, September 2018
https://github.com/openjdk/amber-docs/blob/master/site/design-notes/pattern-matching-for-java.md
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
44
String name = type pattern
String = le nom du pattern
name = binding variable
o = target operand
Type Pattern
if (o instanceof String name) {
// some code
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
45
Un Record is built on components
It has a canonical constructor
It is immutable, it cannot extend any class, it is final
It has accessors, equals(), hashCode(), toString()
Record (JDK 16)
public record Car(Color color) {}
public record Rectangle(int width, int height) {}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
46
Record Deconstruction
if (o instanceof Rectangle rectangle) {
int width = rectangle.width();
int height = rectangle.height();
// do something with width and height
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
47
Un record pourra être « déconstruit »
width et height deviennent des binding variables
Record Deconstruction
if (o instanceof Rectangle(int width, int height)) {
// do something with width and height
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
48
Three type patterns
Three pattern binding variables
One target operand
Patterns Matching for Switch
String formatted =
switch(number) {
case Integer i -> String.format("int %d", i);
case Long l -> String.format("long %d", l);
case Double d -> String.format("double %d", d);
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
49
Deconstruction + Pattern Matching for Switch
record Square(int edge) {}
record Circle(int radius) {}
double area = switch(shape) {
case Square(int edge) -> edge* edge;
case Circle(int radius) -> Math.PI*radius*radius;
default -> ...;
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
50
Sealed Classes (JDK 17)
sealed interface Shape
permits Rectangle, Square, Circle {
}
public final class Rectangle implements Shape {}
public record Circle(Point center) implements Shape {}
public non-sealed abstract class MoreShapes
implements Shape {}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
51
The hierarchy is « sealed »
Sealed Classes (JDK 17)
sealed interface Shape
permits Rectangle, Square, Circle {
}
public final class Rectangle implements Shape {}
public record Circle(Point center) implements Shape {}
public final class Square implements Shape {}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
52
The default case becomes useless = total switch
Pattern Matching for Switch + Sealed Types
double area = switch(shape) {
case Square(int edge) -> edge* edge;
case Circle(int radius) -> Math.PI*radius*radius;
// default -> ...;
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
53
Record Deconstruction (Again)
if (o instanceof Rectangle rectangle) {
int width = rectangle.width();
int height = rectangle.height();
// do something with width and height
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
54
A record can be « deconstructed »
width et height become binding variables
Record Deconstruction (Again)
if (o instanceof Rectangle(int width, int height)) {
// do something with width and height
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
55
Array Pattern Matching
if (o instanceof String[] array && array.length() >= 2) {
// do something with array[0] and array[1]
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
56
Array Pattern Matching
if (o instanceof String[] {String s1, String s2}) {
// do something with s1 and s2
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
57
Array Pattern Matching
if (o instanceof Circle[] {Circle(var r1), Circle(var r3)}) {
// do something with r1 and r2
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
58
Record Pattern Matching for Switch
record Square(int edge) {}
record Circle(int radius) {}
double area = switch(shape) {
case Square(int edge) -> edge* edge;
case Circle(int radius) -> Math.PI*radius*radius;
default -> ...;
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
59
You can use var in patterns
Syntaxic Sugars
if (shape instanceof Circle(var center, var radius)) {
// center and radius are binding variables
}
record Point(int x, int y) {}
record Circle(Point center, int radius) implements Shape {}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
60
You can tell that you do not need a binding variable
Syntaxic Sugars
if (shape instanceof Circle(var center, _)) {
// center and radius are binding variables
}
record Point(int x, int y) {}
record Circle(Point center, int radius) implements Shape {}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
61
You can nest patterns (nested patterns)
Syntaxic Sugars
if (shape instanceof Circle(var center, _) &&
center instanceof Point(int x, int y)) {
// center and radius are binding variables
}
if (shape instanceof Circle(Point(int x, int y), _)) {
// center and radius are binding variables
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
62
The deconstruction uses the canonical constructor of a record
What about:
- factory methods?
- classes that are not records?
Deconstruction
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
63
Deconstruction Using Factory Methods
interface Shape {
static Circle circle(double radius) {
return new Circle(radius);
}
static Square square(double edge) {
return new Square(edge);
}
}
record Circle(double radius) {}
record Square(double edge) {}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
64
Then this code becomes possible:
Deconstruction Using Factory Methods
double area = switch(shape) {
case Shape.circle(double radius) -> Math.PI*radius*radius;
case Shape.square(double edge) -> edge*edge;
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
65
What About Your POJOs?
public class Point {
private int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public deconstructor(int x, int y) {
x = this.x;
y = this.y;
}
}
Binding variables
They are the same!
external state description
Defensive copy
Overloading?
Overloading!
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
66
You saw patterns with instanceof and switch
Let us see match !
Pattern with Match
record Point(int x, int y) {}
record Circle(Point center, int radius) implements Shape {}
Circle circle = ...;
match Circle(var center, var radius) = circle;
// center and radius are binding variables
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
67
If shape is in fact a rectangle…
You can throw an exception
Pattern with Match
Shape shape = ...;
match Circle(var center, var radius) = shape
else
throw new IllegalStateException("Not a circle");
// center and radius are binding variables
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
68
If shape is in fact a rectangle …
Or define default values
Pattern with Match
Shape shape = ...;
match Circle(Point center, int radius) = shape
else {
center = new Point(0, 0); // this is called
radius = 1d; // an anonymous matcher
}
// center and radius are binding variables
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
69
You can use match with more than one pattern…
… or use nested patterns
Pattern with Match
Shape shape = ...;
match Rectangle(var p1, var p2) = shape,
Point(var x0, var y0) = p1,
Point(var x1, var y2) = p2;
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
70
You can create maps with factory methods
This is an extended form of Pattern Matching where you check
the value of a binding variable
More Examples
if (map instanceof Map.withMapping("name", var name) &&
map instanceof Map.withMapping("email", var email)) {
// name and email are binding variables
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
71
Pattern combination
More Examples
if (map instanceof Map.withMapping("name", var name) __AND
map instanceof Map.withMapping("email", var email)) {
// name and email are binding variables
}
__AND = pattern combination
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
72
More Examples
{
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address" : {
"street": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021"
}
}
if (json instanceof
stringKey("firstName", var firstName) __AND
stringKey("lastName", var lastName) __AND
intKey("age", var age) __AND
objectKey("address",
stringKey("stree", var street) __AND
stringKey("city", var city) __AND
stringKey("state", var state)
)) {
// firstName, lastName, age,
// street, city, state, ...
// are binding variables
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
73
If Java Embraces « Map Literals »
Map<String, String> map = {
"firstName": "John",
"lastName": "Smith",
"age": "25"
}
if (map instanceof
{
"firstName": var firstName,
"lastName": var lastName,
"age": Integer.toString(var age)
}) {
// firstName, lastName, age
// are binding variables
}
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
74
• Constant Patterns: checks the operand with a constant value
• Type Patterns: checks if the operand has the right type, casts
it, and creates a binding variable
Patterns at a Glance
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
75
• Patterns + Deconstruction: checks the operand type, casts it,
bind the component to binding variables
• Patterns + Method: uses a factory method or a deconstructor
• Patterns + Var: infers the right type, and creates the binding
variable
• Pattern + _: infers the right type, but does not create the
binding variable
Patterns at a Glance
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
76
« We don’t want to be the first to
include a feature, because every
feature we add will never be
removed »
Brian Goetz,
Java Language Architect
Everything Takes Time!
11/2/2021
Copyright © 2021, Oracle and/or its affiliates |
77
Where are we?
• Pattern Matching for instanceof
• Pattern Matching for Switch
• Record and Array Pattern Matching
• Match
• Literals
Patterns at a Glance

More Related Content

What's hot

Spring boot
Spring bootSpring boot
Spring boot
Pradeep Shanmugam
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
Aaron Schram
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can
 
Spring Boot
Spring BootSpring Boot
Spring Boot
Jiayun Zhou
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
Naphachara Rattanawilai
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
Manav Prasad
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
Scott Leberknight
 
JUnit 5
JUnit 5JUnit 5
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
NexThoughts Technologies
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
Rohit Verma
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
07.pallav
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
Eberhard Wolff
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
Knoldus Inc.
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patterns
José Paumard
 
Introduction to Java 11
Introduction to Java 11 Introduction to Java 11
Introduction to Java 11
Knoldus Inc.
 
Spring boot
Spring bootSpring boot
Spring boot
sdeeg
 
Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1
José Paumard
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
Rasheed Waraich
 
Spring Core
Spring CoreSpring Core
Spring Core
Pushan Bhattacharya
 

What's hot (20)

Spring boot
Spring bootSpring boot
Spring boot
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patterns
 
Introduction to Java 11
Introduction to Java 11 Introduction to Java 11
Introduction to Java 11
 
Spring boot
Spring bootSpring boot
Spring boot
 
Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Spring Core
Spring CoreSpring Core
Spring Core
 

Similar to Deep Dive Java 17 Devoxx UK

Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Vadym Kazulkin
 
eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introduction
vstorm83
 
Java Cloud and Container Ready
Java Cloud and Container ReadyJava Cloud and Container Ready
Java Cloud and Container Ready
CodeOps Technologies LLP
 
Core Android
Core AndroidCore Android
Core Android
Dominik Helleberg
 
How and why to upgrade to java 16 or 17
How and why to upgrade to java 16 or 17How and why to upgrade to java 16 or 17
How and why to upgrade to java 16 or 17
Johan Janssen
 
DockerCon EU 2018 - Dockerfile Best Practices
DockerCon EU 2018 - Dockerfile Best PracticesDockerCon EU 2018 - Dockerfile Best Practices
DockerCon EU 2018 - Dockerfile Best Practices
Tibor Vass
 
DCEU 18: Dockerfile Best Practices
DCEU 18: Dockerfile Best PracticesDCEU 18: Dockerfile Best Practices
DCEU 18: Dockerfile Best Practices
Docker, Inc.
 
Jdbc
JdbcJdbc
Vagrant or docker for java dev environment
Vagrant or docker for java dev environmentVagrant or docker for java dev environment
Vagrant or docker for java dev environment
Orest Ivasiv
 
Taking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the ExtremeTaking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the Extreme
yinonavraham
 
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
Jesse Gallagher
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
hchen1
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
Sadayuki Furuhashi
 
Play Support in Cloud Foundry
Play Support in Cloud FoundryPlay Support in Cloud Foundry
Play Support in Cloud Foundry
rajdeep
 
Play framework
Play frameworkPlay framework
Play framework
Andrew Skiba
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystem
Rafael Winterhalter
 
Docker for Ruby Developers
Docker for Ruby DevelopersDocker for Ruby Developers
Docker for Ruby Developers
Aptible
 
Meetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfMeetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdf
Red Hat
 
Custom Buildpacks and Data Services
Custom Buildpacks and Data ServicesCustom Buildpacks and Data Services
Custom Buildpacks and Data Services
Tom Kranz
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
Haiqi Chen
 

Similar to Deep Dive Java 17 Devoxx UK (20)

Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
 
eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introduction
 
Java Cloud and Container Ready
Java Cloud and Container ReadyJava Cloud and Container Ready
Java Cloud and Container Ready
 
Core Android
Core AndroidCore Android
Core Android
 
How and why to upgrade to java 16 or 17
How and why to upgrade to java 16 or 17How and why to upgrade to java 16 or 17
How and why to upgrade to java 16 or 17
 
DockerCon EU 2018 - Dockerfile Best Practices
DockerCon EU 2018 - Dockerfile Best PracticesDockerCon EU 2018 - Dockerfile Best Practices
DockerCon EU 2018 - Dockerfile Best Practices
 
DCEU 18: Dockerfile Best Practices
DCEU 18: Dockerfile Best PracticesDCEU 18: Dockerfile Best Practices
DCEU 18: Dockerfile Best Practices
 
Jdbc
JdbcJdbc
Jdbc
 
Vagrant or docker for java dev environment
Vagrant or docker for java dev environmentVagrant or docker for java dev environment
Vagrant or docker for java dev environment
 
Taking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the ExtremeTaking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the Extreme
 
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
 
Play Support in Cloud Foundry
Play Support in Cloud FoundryPlay Support in Cloud Foundry
Play Support in Cloud Foundry
 
Play framework
Play frameworkPlay framework
Play framework
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystem
 
Docker for Ruby Developers
Docker for Ruby DevelopersDocker for Ruby Developers
Docker for Ruby Developers
 
Meetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfMeetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdf
 
Custom Buildpacks and Data Services
Custom Buildpacks and Data ServicesCustom Buildpacks and Data Services
Custom Buildpacks and Data Services
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 

More from José Paumard

The Future of Java: Records, Sealed Classes and Pattern Matching
The Future of Java: Records, Sealed Classes and Pattern MatchingThe Future of Java: Records, Sealed Classes and Pattern Matching
The Future of Java: Records, Sealed Classes and Pattern Matching
José Paumard
 
Designing functional and fluent API: application to some GoF patterns
Designing functional and fluent API: application to some GoF patternsDesigning functional and fluent API: application to some GoF patterns
Designing functional and fluent API: application to some GoF patterns
José Paumard
 
The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of Flattery
José Paumard
 
The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of Flattery
José Paumard
 
Designing functional and fluent API: example of the Visitor Pattern
Designing functional and fluent API: example of the Visitor PatternDesigning functional and fluent API: example of the Visitor Pattern
Designing functional and fluent API: example of the Visitor Pattern
José Paumard
 
Construire son JDK en 10 étapes
Construire son JDK en 10 étapesConstruire son JDK en 10 étapes
Construire son JDK en 10 étapes
José Paumard
 
Java Keeps Throttling Up!
Java Keeps Throttling Up!Java Keeps Throttling Up!
Java Keeps Throttling Up!
José Paumard
 
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2
José Paumard
 
Asynchronous Systems with Fn Flow
Asynchronous Systems with Fn FlowAsynchronous Systems with Fn Flow
Asynchronous Systems with Fn Flow
José Paumard
 
Java Full Throttle
Java Full ThrottleJava Full Throttle
Java Full Throttle
José Paumard
 
JAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) Bridge
José Paumard
 
Collectors in the Wild
Collectors in the WildCollectors in the Wild
Collectors in the Wild
José Paumard
 
Streams in the wild
Streams in the wildStreams in the wild
Streams in the wild
José Paumard
 
JAX RS and CDI bike the reactive bridge
JAX RS and CDI bike the reactive bridgeJAX RS and CDI bike the reactive bridge
JAX RS and CDI bike the reactive bridge
José Paumard
 
Free your lambdas
Free your lambdasFree your lambdas
Free your lambdas
José Paumard
 
L'API Collector dans tous ses états
L'API Collector dans tous ses étatsL'API Collector dans tous ses états
L'API Collector dans tous ses états
José Paumard
 
Linked to ArrayList: the full story
Linked to ArrayList: the full storyLinked to ArrayList: the full story
Linked to ArrayList: the full story
José Paumard
 
Free your lambdas
Free your lambdasFree your lambdas
Free your lambdas
José Paumard
 
ArrayList et LinkedList sont dans un bateau
ArrayList et LinkedList sont dans un bateauArrayList et LinkedList sont dans un bateau
ArrayList et LinkedList sont dans un bateau
José Paumard
 
Java SE 8 for Java EE developers
Java SE 8 for Java EE developersJava SE 8 for Java EE developers
Java SE 8 for Java EE developers
José Paumard
 

More from José Paumard (20)

The Future of Java: Records, Sealed Classes and Pattern Matching
The Future of Java: Records, Sealed Classes and Pattern MatchingThe Future of Java: Records, Sealed Classes and Pattern Matching
The Future of Java: Records, Sealed Classes and Pattern Matching
 
Designing functional and fluent API: application to some GoF patterns
Designing functional and fluent API: application to some GoF patternsDesigning functional and fluent API: application to some GoF patterns
Designing functional and fluent API: application to some GoF patterns
 
The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of Flattery
 
The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of Flattery
 
Designing functional and fluent API: example of the Visitor Pattern
Designing functional and fluent API: example of the Visitor PatternDesigning functional and fluent API: example of the Visitor Pattern
Designing functional and fluent API: example of the Visitor Pattern
 
Construire son JDK en 10 étapes
Construire son JDK en 10 étapesConstruire son JDK en 10 étapes
Construire son JDK en 10 étapes
 
Java Keeps Throttling Up!
Java Keeps Throttling Up!Java Keeps Throttling Up!
Java Keeps Throttling Up!
 
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2
 
Asynchronous Systems with Fn Flow
Asynchronous Systems with Fn FlowAsynchronous Systems with Fn Flow
Asynchronous Systems with Fn Flow
 
Java Full Throttle
Java Full ThrottleJava Full Throttle
Java Full Throttle
 
JAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) Bridge
 
Collectors in the Wild
Collectors in the WildCollectors in the Wild
Collectors in the Wild
 
Streams in the wild
Streams in the wildStreams in the wild
Streams in the wild
 
JAX RS and CDI bike the reactive bridge
JAX RS and CDI bike the reactive bridgeJAX RS and CDI bike the reactive bridge
JAX RS and CDI bike the reactive bridge
 
Free your lambdas
Free your lambdasFree your lambdas
Free your lambdas
 
L'API Collector dans tous ses états
L'API Collector dans tous ses étatsL'API Collector dans tous ses états
L'API Collector dans tous ses états
 
Linked to ArrayList: the full story
Linked to ArrayList: the full storyLinked to ArrayList: the full story
Linked to ArrayList: the full story
 
Free your lambdas
Free your lambdasFree your lambdas
Free your lambdas
 
ArrayList et LinkedList sont dans un bateau
ArrayList et LinkedList sont dans un bateauArrayList et LinkedList sont dans un bateau
ArrayList et LinkedList sont dans un bateau
 
Java SE 8 for Java EE developers
Java SE 8 for Java EE developersJava SE 8 for Java EE developers
Java SE 8 for Java EE developers
 

Recently uploaded

math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
Amin Marwan
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 

Recently uploaded (20)

math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 

Deep Dive Java 17 Devoxx UK

  • 1. Java 17: Deep Dive José Paumard Java Developer Advocate Java Platform Group
  • 4. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 4 Dev.java Java 8 Java 11
  • 5. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 5 Java 17 – LTS ! Java 8 Java 11
  • 6. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 6 OpenJDK? https://openjdk.java.net
  • 7. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 7 New Release Cadence! 11 12 13 14 15 16 17 18 19 20 21 22 23 2018 2019 2020 2021 2022 2023 2024 2025 http://jdk.java.net/
  • 8. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 8 New Release Cadence! 11 12 13 14 15 16 17 18 19 20 21 22 http://jdk.java.net/ 23 2018 2019 2020 2021 2022 2023 2024 2025
  • 9. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 9 New Release Cadence! 11 12 13 14 15 16 17 18 19 20 21 22 https://www.oracle.com/java/ technologies/javase- downloads.html 23 2018 2019 2020 2021 2022 2023 2024 2025
  • 10. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 10 New New Release Cadence! 11 12 13 14 15 16 17 18 19 20 21 22 1) LTS: 3 years  2 years 23 2018 2019 2020 2021 2022 2023 2024 2025 https://mreinhold.org/blog/forward-even-faster https://blogs.oracle.com/java/post/ moving-the-jdk-to-a-two-year-lts-cadence
  • 11. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 11 New New Release Cadence! 11 12 13 14 15 16 17 18 19 20 21 22 2018 2019 2020 2021 2022 2023 2024 2025 23 1) LTS: 3 years  2 years https://mreinhold.org/blog/forward-even-faster https://blogs.oracle.com/java/post/ moving-the-jdk-to-a-two-year-lts-cadence
  • 12. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 12 New New Release Cadence! 11 12 13 14 15 16 17 18 19 20 21 22 2018 2019 2020 2021 2022 2023 2024 2025 23 1) LTS: 3 years  2 years 2) Free licence (dev + prod) 3) No click-through https://blogs.oracle.com/java/post/ free-java-license
  • 13. Sept. 2021 Mars 2014 4 Years 90 80 70 60 50 40 30 20 10 0 56 91 12 17 8 5 16 14 17 14 Mars 2018 3 Years JDK 8 LTS JDK 9-11 JDK 12-17 JDK 9 JDK 10 JDK 11 LTS JDK 12 JDK 13 JDK 14 JDK 15 JDK 16 JDK 17 LTS Features From 8 to 17 Copyright © 2021, Oracle and/or its affiliates 13
  • 14. Language Type inference for locals (var) Switch expressions Text blocks Record classes Sealed classes Pattern matching for instanceof JDK 17: New Features Since the JDK 8 Copyright © 2021, Oracle and/or its affiliates 14 Tools jshell jlink jdeps jpackage java source code launcher javadoc search + API history JVM Garbage Collectors: G1, ZGC AArch64 support: Windows, Mac, Linux Docker awareness Class Data Sharing by default Helpful NullPointerExceptions Hidden classes Libraries HTTP client Collection factories Unix-domain sockets Stack walker Deserialization filtering Pseudo-RNG, SHA-3, TLS 1.3
  • 15. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | Confidential: Internal/Restricted/Highly Restricted 15 Tools
  • 16. Language Type inference for locals (var) Switch expressions Text blocks Record classes Sealed classes Pattern matching for instanceof JDK 17: New Features Since the JDK 8 Copyright © 2021, Oracle and/or its affiliates 16 Tools jshell jlink jdeps jpackage java source code launcher javadoc search + API history JVM Garbage Collectors: G1, ZGC AArch64 support: Windows, Mac, Linux Docker awareness Class Data Sharing by default Helpful NullPointerExceptions Hidden classes Libraries HTTP client Collection factories Unix-domain sockets Stack walker Deserialization filtering Pseudo-RNG, SHA-3, TLS 1.3 Tools jshell jlink jdeps jpackage java source code launcher javadoc search + API history
  • 17. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 17 Step 1: Hello World Launching Single File Source Code public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } $ java HelloWorld.java
  • 18. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 18 Step 2: Add 3rd party dependencies Launching Single File Source Code public class HelloWorld { public static void main(String[] args) { System.out.println(RandomUtils.nextInt()); } } $ java -cp /path/to/commons-lang3-3.12.0.jar HelloWorld.java
  • 19. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 19 Step 3: Execute a shebang file Launching Single File Source Code #!/path/to/your/bin/java --source 17 public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } $ ./HelloWorld
  • 20. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 20 Create a runtime image JLink: Creating Custom Runtime Images $ jlink --module-path mods --add-modules org.mycompany.mymodule --output myapp-image
  • 21. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 21 Create a runtime image with a launcher JLink: Creating Custom Runtime Images # create the image $ jlink --module-path mods --add-modules com.example.main --launcher app=com.example.app/com.example.app.Main --output app-image # launch $ app-image/bin/app
  • 22. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 22 The smallest runtime image JLink: Creating Custom Runtime Images $ jlink --add-modules java.base --output jdk.base $ du –sh jdk.base jdk-17 40M jdk.base 288M jdk-17
  • 23. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 23 Supported Installers: MSI, EXE, RPM, DEB, PKG, DMG JPackage: Creating Custom Installers $ jpackage --name my-installer --app-version 1.0 --win-dir-chooser --win-console --win-shortcut --module-path mymodules/my-app-1.0.jar --module org.myapp/org.mycompany.myapp.MainClass
  • 24. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | Confidential: Internal/Restricted/Highly Restricted 24 API
  • 25. Language Type inference for locals (var) Switch expressions Text blocks Record classes Sealed classes Pattern matching for instanceof JDK 17: New Features Since the JDK 8 Copyright © 2021, Oracle and/or its affiliates 25 Tools jshell jlink jdeps jpackage java source code launcher javadoc search + API history JVM Garbage Collectors: G1, ZGC AArch64 support: Windows, Mac, Linux Docker awareness Class Data Sharing by default Helpful NullPointerExceptions Hidden classes Libraries HTTP client Collection factories Unix-domain sockets Stack walker Deserialization filtering Pseudo-RNG, SHA-3, TLS 1.3 Libraries HTTP client Collection factories Unix-domain sockets Stack walker Deserialization filtering Pseudo-RNG, SHA-3, TLS 1.3
  • 26. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 26 Step 1: create a request HttpClient API HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://example.com")) .header("Accept-Encoding", "gzip") .header("Accept", "text/xml") .GET() .build();
  • 27. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 27 Step 2: create a client HttpClient API HttpClient client = HttpClient.newBuilder() .version(HttpClient.Version.HTTP_1_1) .connectTimeout(Duration.ofSeconds(20)) .build();
  • 28. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 28 Step 3: send the request HttpClient API HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream()); InputStream inputStream = response.body();
  • 29. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 29 Step 3: send the request HttpClient API HttpResponse<Stream<String>> response = client.send(request, HttpResponse.BodyHandlers.ofLines()); Stream<String> lines = response.body();
  • 30. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 30 Open a web server for serving a single directory hierarchy. Options: Simple HttpServer: Command Line Tool & API $ java -m jdk.httpserver -b, --bind-address - Address to bind to. Default: 127.0.0.1 or ::1 (loopback). For all interfaces use "-b 0.0.0.0" or "-b ::". -d, --directory - Directory to serve. Default: current directory. -o, --output - Output format. none|info|verbose. Default: info. -p, --port - Port to listen on. Default: 8000.
  • 31. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 31 The API version, in JShell Supports HTTP only, request handling can be customized Simple HttpServer: Command Line Tool & API jshell> var server = SimpleFileServer.createFileServer( > new InetSocketAddress(8080), > Path.of("/some/path"), > OutputLevel.VERBOSE); jshell> server.start()
  • 32. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 32 Supported on Linux, MacOS and some flavors of Windows Both on the server and the client Unix Domain Sockets Path home = Path.of("/tmp"); Path file = home.resolve("user.socket"); UnixDomainSocketAddress socketAddress = UnixDomainSocketAddress.of(file);
  • 33. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 33 On the server: On the client: Unix Domain Sockets ServerSocketChannel channel = ServerSocketChannel.open(StandardProtocolFamily.UNIX); SocketChannel socketChannel = channel.bind(socketAddress).accept(); SocketChannel socketChannel = SocketChannel.open(socketAddress);
  • 34. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 34 Current status: getting the execution stack is costly, it captures the entire stack (getStackTrace() on Thread and Throwable) Sometimes you only need the first elements of the stack Idea: have a way of lazily explore the stack, based on a Stream<StackFrame> and a callback Stack Frame Walker
  • 35. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 35 Stack Frame Walker StackWalker walker = StackWalker.getInstance( StackWalker.Option.RETAIN_CLASS_REFERENCE); walker.forEach( stackFrame -> System.out.println(stackFrame.getClassName()));
  • 36. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 36 Stack Frame Walker Set<String> classNames = ...; Optional<String> className = walker.walk( stackFrameStream -> stackFrameStream .map(StackWalker.StackFrame::getClassName) .filter(classNames::contains) .findFirst() );
  • 37. Language Type inference for locals (var) Switch expressions Text blocks Record classes Sealed classes Pattern matching for instanceof JDK 17: New Features Since the JDK 8 Copyright © 2021, Oracle and/or its affiliates 37 Tools jshell jlink jdeps jpackage java source code launcher javadoc search + API history JVM Garbage Collectors: G1, ZGC AArch64 support: Windows, Mac, Linux Docker awareness Class Data Sharing by default Helpful NullPointerExceptions Hidden classes Libraries HTTP client Collection factories Unix-domain sockets Stack walker Deserialization filtering Pseudo-RNG, SHA-3, TLS 1.3 Language Type inference for locals (var) Switch expressions Text blocks Record classes Sealed classes Pattern matching for instanceof
  • 38. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 38 Do not override finalize() Stop doing that! @Deprecated(since="9") protected void finalize() throws Throwable { }
  • 39. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 39 Do not call new Integer(...) Stop doing that! @Deprecated(since="9", forRemoval = true) public Integer(int value) { this.value = value; } @IntrinsicCandidate public static Integer valueOf(int i) { // some code return new Integer(i); }
  • 40. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 40 ☕ Coffee Break!
  • 41. Record and Array Pattern Matching Record Sealed Classes Switch Expression Constant Dynamic Inner Classes private in VM Nestmates Pattern Matching for instanceof 11 14 16 17 Switch on Patterns 18
  • 42. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 42 In reference to the Amber by Roger Zelazny Project Amber
  • 43. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 43 A pattern is a combination of a match predicate that determines if the pattern matches a target, along with a set of pattern variables that are conditionally extracted if the pattern matches the target. Java 16 : Pattern Match for IntanceOf Pattern Matching for Java Gavin Bierman and Brian Goetz, September 2018 https://github.com/openjdk/amber-docs/blob/master/site/design-notes/pattern-matching-for-java.md
  • 44. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 44 String name = type pattern String = le nom du pattern name = binding variable o = target operand Type Pattern if (o instanceof String name) { // some code }
  • 45. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 45 Un Record is built on components It has a canonical constructor It is immutable, it cannot extend any class, it is final It has accessors, equals(), hashCode(), toString() Record (JDK 16) public record Car(Color color) {} public record Rectangle(int width, int height) {}
  • 46. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 46 Record Deconstruction if (o instanceof Rectangle rectangle) { int width = rectangle.width(); int height = rectangle.height(); // do something with width and height }
  • 47. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 47 Un record pourra être « déconstruit » width et height deviennent des binding variables Record Deconstruction if (o instanceof Rectangle(int width, int height)) { // do something with width and height }
  • 48. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 48 Three type patterns Three pattern binding variables One target operand Patterns Matching for Switch String formatted = switch(number) { case Integer i -> String.format("int %d", i); case Long l -> String.format("long %d", l); case Double d -> String.format("double %d", d); }
  • 49. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 49 Deconstruction + Pattern Matching for Switch record Square(int edge) {} record Circle(int radius) {} double area = switch(shape) { case Square(int edge) -> edge* edge; case Circle(int radius) -> Math.PI*radius*radius; default -> ...; }
  • 50. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 50 Sealed Classes (JDK 17) sealed interface Shape permits Rectangle, Square, Circle { } public final class Rectangle implements Shape {} public record Circle(Point center) implements Shape {} public non-sealed abstract class MoreShapes implements Shape {}
  • 51. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 51 The hierarchy is « sealed » Sealed Classes (JDK 17) sealed interface Shape permits Rectangle, Square, Circle { } public final class Rectangle implements Shape {} public record Circle(Point center) implements Shape {} public final class Square implements Shape {}
  • 52. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 52 The default case becomes useless = total switch Pattern Matching for Switch + Sealed Types double area = switch(shape) { case Square(int edge) -> edge* edge; case Circle(int radius) -> Math.PI*radius*radius; // default -> ...; }
  • 53. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 53 Record Deconstruction (Again) if (o instanceof Rectangle rectangle) { int width = rectangle.width(); int height = rectangle.height(); // do something with width and height }
  • 54. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 54 A record can be « deconstructed » width et height become binding variables Record Deconstruction (Again) if (o instanceof Rectangle(int width, int height)) { // do something with width and height }
  • 55. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 55 Array Pattern Matching if (o instanceof String[] array && array.length() >= 2) { // do something with array[0] and array[1] }
  • 56. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 56 Array Pattern Matching if (o instanceof String[] {String s1, String s2}) { // do something with s1 and s2 }
  • 57. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 57 Array Pattern Matching if (o instanceof Circle[] {Circle(var r1), Circle(var r3)}) { // do something with r1 and r2 }
  • 58. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 58 Record Pattern Matching for Switch record Square(int edge) {} record Circle(int radius) {} double area = switch(shape) { case Square(int edge) -> edge* edge; case Circle(int radius) -> Math.PI*radius*radius; default -> ...; }
  • 59. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 59 You can use var in patterns Syntaxic Sugars if (shape instanceof Circle(var center, var radius)) { // center and radius are binding variables } record Point(int x, int y) {} record Circle(Point center, int radius) implements Shape {}
  • 60. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 60 You can tell that you do not need a binding variable Syntaxic Sugars if (shape instanceof Circle(var center, _)) { // center and radius are binding variables } record Point(int x, int y) {} record Circle(Point center, int radius) implements Shape {}
  • 61. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 61 You can nest patterns (nested patterns) Syntaxic Sugars if (shape instanceof Circle(var center, _) && center instanceof Point(int x, int y)) { // center and radius are binding variables } if (shape instanceof Circle(Point(int x, int y), _)) { // center and radius are binding variables }
  • 62. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 62 The deconstruction uses the canonical constructor of a record What about: - factory methods? - classes that are not records? Deconstruction
  • 63. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 63 Deconstruction Using Factory Methods interface Shape { static Circle circle(double radius) { return new Circle(radius); } static Square square(double edge) { return new Square(edge); } } record Circle(double radius) {} record Square(double edge) {}
  • 64. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 64 Then this code becomes possible: Deconstruction Using Factory Methods double area = switch(shape) { case Shape.circle(double radius) -> Math.PI*radius*radius; case Shape.square(double edge) -> edge*edge; }
  • 65. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 65 What About Your POJOs? public class Point { private int x, y; public Point(int x, int y) { this.x = x; this.y = y; } public deconstructor(int x, int y) { x = this.x; y = this.y; } } Binding variables They are the same! external state description Defensive copy Overloading? Overloading!
  • 66. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 66 You saw patterns with instanceof and switch Let us see match ! Pattern with Match record Point(int x, int y) {} record Circle(Point center, int radius) implements Shape {} Circle circle = ...; match Circle(var center, var radius) = circle; // center and radius are binding variables
  • 67. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 67 If shape is in fact a rectangle… You can throw an exception Pattern with Match Shape shape = ...; match Circle(var center, var radius) = shape else throw new IllegalStateException("Not a circle"); // center and radius are binding variables
  • 68. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 68 If shape is in fact a rectangle … Or define default values Pattern with Match Shape shape = ...; match Circle(Point center, int radius) = shape else { center = new Point(0, 0); // this is called radius = 1d; // an anonymous matcher } // center and radius are binding variables
  • 69. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 69 You can use match with more than one pattern… … or use nested patterns Pattern with Match Shape shape = ...; match Rectangle(var p1, var p2) = shape, Point(var x0, var y0) = p1, Point(var x1, var y2) = p2;
  • 70. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 70 You can create maps with factory methods This is an extended form of Pattern Matching where you check the value of a binding variable More Examples if (map instanceof Map.withMapping("name", var name) && map instanceof Map.withMapping("email", var email)) { // name and email are binding variables }
  • 71. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 71 Pattern combination More Examples if (map instanceof Map.withMapping("name", var name) __AND map instanceof Map.withMapping("email", var email)) { // name and email are binding variables } __AND = pattern combination
  • 72. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 72 More Examples { "firstName": "John", "lastName": "Smith", "age": 25, "address" : { "street": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021" } } if (json instanceof stringKey("firstName", var firstName) __AND stringKey("lastName", var lastName) __AND intKey("age", var age) __AND objectKey("address", stringKey("stree", var street) __AND stringKey("city", var city) __AND stringKey("state", var state) )) { // firstName, lastName, age, // street, city, state, ... // are binding variables }
  • 73. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 73 If Java Embraces « Map Literals » Map<String, String> map = { "firstName": "John", "lastName": "Smith", "age": "25" } if (map instanceof { "firstName": var firstName, "lastName": var lastName, "age": Integer.toString(var age) }) { // firstName, lastName, age // are binding variables }
  • 74. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 74 • Constant Patterns: checks the operand with a constant value • Type Patterns: checks if the operand has the right type, casts it, and creates a binding variable Patterns at a Glance
  • 75. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 75 • Patterns + Deconstruction: checks the operand type, casts it, bind the component to binding variables • Patterns + Method: uses a factory method or a deconstructor • Patterns + Var: infers the right type, and creates the binding variable • Pattern + _: infers the right type, but does not create the binding variable Patterns at a Glance
  • 76. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 76 « We don’t want to be the first to include a feature, because every feature we add will never be removed » Brian Goetz, Java Language Architect Everything Takes Time!
  • 77. 11/2/2021 Copyright © 2021, Oracle and/or its affiliates | 77 Where are we? • Pattern Matching for instanceof • Pattern Matching for Switch • Record and Array Pattern Matching • Match • Literals Patterns at a Glance