-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
365 lines (281 loc) · 8.29 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Java 17</title>
<link rel="stylesheet" href="../../reveal.js/dist/reset.css">
<link rel="stylesheet" href="../../reveal.js/dist/reveal.css">
<link rel="stylesheet" href="../../reveal.js/dist/theme/black.css" id="theme">
<!-- Theme used for syntax highlighted code -->
<link rel="stylesheet" href="../../reveal.js/plugin/highlight/monokai.css" id="highlight-theme">
</head>
<body>
<div class="reveal">
<div class="slides">
<!-- Slides are separated by newline + three dashes + newline, vertical slides identical but two dashes -->
<section data-markdown data-separator="^\n---\n$" data-separator-vertical="^\n--\n$">
<textarea data-template>
<!-- ## Java 17 -->
![Java logo](images/java_small.png)
## New features in Java 17
--
## Who am I
Joost van Gils
Java Developer
Payments Gladiators
Notes:
* 50 years old, father of 3 sons, Almere
* Java since 2001 (Java 1.3), also Scala + functional programming style
* At AA since November 2022
* Hobbies: tech, music (midi), home automation
---
## A little history
--
## Java almost 27 years old
| version | release date | support ends |
| ------------ |:---------------:| ---------------:|
| 1.0 | 23-01-1996 | ? |
| SE 5 | 29-09-2009 | April 2015 |
| SE 8 (LTS) | 18-03-2014 | December 2030 |
| SE 11 (LTS) | 25-09-2018 | September 2026 |
| SE 17 (LTS) | 14-09-2021 | September 2029 |
Notes:
Oracle. Azul, Red Hat, etc dates differ
--
## Features
| version | features |
| --- |:----------------------------------------:|
| 5 | generics, annotations, enums, autoboxing, vararg, static imports |
| 8 | lambdas, stream API, java.nio (7), default methods |
| 11 | var keyword (10), http client, EE removed |
| 17 | wait for it... |
Notes:
* The unmentioned versions mainly introduced improvements to APIs
* Actually: 17, 16, 15, 14, 13, 12
---
## Records
(Java 16)
Notes:
* Introduced in Java 16
--
```java
public record Point(long x, long y) {
// nothing to see here
}
```
--
* Similar to Lombok's `@Value`
* Implicit
* all-args contructor
* getters for all fields
* `equals` and `hashcode` methods
* `toString` method
* Very efficient on JVM
--
```java
var p = new Point(10, 20);
var q = new Point(10, 20);
```
```java
System.out.println( p );
System.out.println( p.x() );
System.out.println( p.equals(q) );
```
```sh
Point[x=10, y=20]
10
true
```
---
## Pattern matching for instanceOf
(Java 16)
--
Java 11
```java
if (obj instanceof String) {
String s = (String) obj;
System.out.println(s.length());
}
```
Java 17
```java
if (obj instanceof String s) {
System.out.println(s.length());
}
```
---
## Text blocks
(Java 15)
--
Java 11
```java
String html =
"<html>\n" +
" <body>\n" +
" <em>Cool LTS Java 17 Features</em>\n" +
" </body>\n" +
"</html>\n";
```
Java 17
```java
String html = """
<html>
<body>
<em>Cool LTS Java 17 Features</em>
</body>
</html>
""";
```
---
## Helpful NullPointerExceptions
(Java 14)
--
Java 11
```java
var street = customer.getAddress().getStreet();
```
```sh
Exception in thread "main" java.lang.NullPointerException
at com.abnamro/com.abnamro.App.main(App.java:17)
```
--
Java 17
```java
var street = customer.address().street();
```
```sh
Exception in thread "main" java.lang.NullPointerException:
Cannot invoke "com.abnamro.Address.street()" because the
return value of "com.abnamro.Customer.address()" is null
at com.abnamro.Application.main(App.java:21)
```
---
## Switch expression
(Java 14)
--
```java
int numDays = switch(month) {
case JAN, MAR, MAY, JUL, AUG, OCT, DEC -> 31;
case APR, JUN, SEP, NOV -> 30;
case FEB -> {
if (year % 400 == 0) yield 29;
else if (year % 100 == 0) yield 28;
else if (year % 4 == 0) yield 29;
else yield 28; }
};
```
* an *expression*, not a *statement*
* no error-prone fall-through (`break`)
* pattern matching
---
## Sealed classes
(Java 17)
--
```java
public abstract sealed class Animal
permits Dog, Cat {
}
public final class Dog extends Animal {
}
public final class Cat extends Animal {
}
```
--
Useful for
* `switch` without `default` case
* compiler can check exhaustiveness of `if/then/else` statements
* Algebraic data types (with `records`)
---
## Improved streams API
(Java 16)
--
For example, instead of
```java
var list = stream.collect(Collectors.toList())
```
simply do
```java
var list = stream.toList();
```
Beware: `toList()` returns an immutable List
---
## Why (not) use Java 17
--
## Cons
* Requires new skills, also for future maintainers
* Infra might not be up to date (IDE, SonarQube, build agents, live environments)
* Existing projects: not enough benefit to migrate
* Libraries that do not work on a Java 17 JVM
* It might be scary to do things differently
--
## Pros
* Many bug fixes and security improvements
* Premier support for Java 11 ends Sept 2023
* Instant performance boost
Java 17 is about 8.5% faster than Java 11 on G1 GC and 6.5% on parallel GC ([source](https://www.optaplanner.org/blog/2021/09/15/HowMuchFasterIsJava17.html)).
* Spring Boot 3+ requires it
* No need to use new features immediately
* It's fun to use new things!
---
## Java 17 @ ABN AMRO
--
![Support](images/support.png)
([source: Hitchhiker's Guide](https://confluence.int.abnamro.com/display/GRIDAD/Standard+Programming+Languages))
--
* Use `master-pom` 4.1.0 as parent pom for your project
```xml
<parent>
<groupId>com.abnamro.coesd</groupId>
<artifactId>master-pom</artifactId>
<version>4.1.0</version>
</parent>
```
* Set java source & target to `17` (as 11 is still default)
```xml
<java.source>17</java.source>
<java.target>17</java.target>
```
([source: Hitchhiker's Guide](https://confluence.int.abnamro.com/pages/viewpage.action?pageId=435333723))
--
* Set version to `1.17` in Pita's `java-maven` template
```yml
resources:
repositories:
- repository: templates
type: git
name: GRD0001045/pita-pipeline-templates
stages:
- stage: CI
jobs:
- template: flows/java-maven.yml@templates
parameters:
java_version: '1.17'
```
--
ABN AMRO and Azure support it completely
It makes sense to use it for new projects on Azure
---
## Thank you!
joost.van.gils@nl.abnamro.com
</textarea>
</section>
</div>
</div>
<script src="../../reveal.js/dist/reveal.js"></script>
<script src="../../reveal.js/plugin/notes/notes.js"></script>
<script src="../../reveal.js/plugin/markdown/markdown.js"></script>
<script src="../../reveal.js/plugin/highlight/highlight.js"></script>
<script>
// More info about initialization & config:
// - https://revealjs.com/initialization/
// - https://revealjs.com/config/
Reveal.initialize({
hash: true,
navigationMode: 'linear',
// Learn about plugins: https://revealjs.com/plugins/
plugins: [ RevealMarkdown, RevealHighlight, RevealNotes ]
});
</script>
</body>
</html>