-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
1729 lines (1550 loc) · 85.6 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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Effective Java SE 9-19 APIs & Language features, makes your life easier</title>
<meta name="description" content="A short summary & overview of the new features & the hidden treasures of Java SE 19">
<meta name="author" content="Mohamed Mahmoud Taman">
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui"/>
<link rel="stylesheet" href="css/reset.css"/>
<link rel="stylesheet" href="css/reveal.css"/>
<link rel="stylesheet" href="css/theme/black.css" id="theme"/>
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- <link rel="stylesheet" href="lib/css/monokai.css"> -->
<!-- Custom, overriding CSS -->
<link rel="stylesheet" href="css/custom.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<!--
=== Logos ===============================================================================
-->
<div style="position: absolute; top: 5px; z-index: 6; right: 0; margin-right: 10px">
<img src="media/img/logos/O-Groundbreakers-Logo.png" width="220" height="60" alt="Oracle Groundbreakers Ambassador" />
<img src="media/img/logos/Java Champoins.jpeg" width="60" height="60" alt="Java Champions" />
</div>
<div style="position: absolute; top: 5px; z-index: 6; left: 0; margin-left: 10px">
<img src="media/img/logos/Nlogo_white.png" width="200" height="50" alt="Nortal Logo"/>
<!-- <img src="media/img/logos/ananas-logo.svg" alt="Ananas Logo" />-->
<br/>
</div>
<!-- Slides -->
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<!--
=== Slide 1- Presentation title & about me =================================================
-->
<section>
<!-- Slide 1.1 - Cover page -->
<section>
<div style="width: 80%; margin: 0 auto">
<h3 style="text-align: center;margin: 00px 0 80px 0">Effective <span style="color: orange">Java SE 9</span> through <span style="color: orange">19</span> APIs & Language features, that make your life easier.</h3>
</div>
<div class="profile" style="position: absolute; top: 200px; left: 300px">
<div class="profile-sidebar" style="border-radius: 15px 15px 0 0">
<div class="profile-userpic">
<img data-src="media/img/logos/TamanFace.jpg" class="img-responsive" alt="">
</div>
<div class="profile-usertitle">
<div class="profile-usertitle-name">
Mohamed Taman
</div>
<div class="profile-usertitle-job">
Solutions Architect @Nortal MEA,<br> Java Champion, Belgrade, Serbia.
</div>
</div>
</div>
<div class="profile-content" style="border-radius:0 0 10px 10px">
<table>
<tr>
<td style="text-align: right; vertical-align: middle; padding: 0"><img data-src="media/img/twitter.png" style="background-color: transparent; border-color: transparent; width: 30%;margin: 0px 0px;"/></td>
<td style="text-align: left; vertical-align: middle; padding: 0"><a href="https://twitter.com/_tamanm"> @_tamanm</a></td>
</tr>
</table>
</div>
</div>
</section>
<!-- Slide 1.1.1 - Intro Video -->
<section>
<iframe width="1150" height="650" src="https://www.youtube.com/embed/zg79C7XM1Xs" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</section>
<!--
=== Slide 1.2 - Me, I, and Myself ===================================================================
-->
<section>
<h3>Me, I, and Myself <img src="media/img/logos/TamanFace.jpg" style="width: 65px; border-radius: 50%"></h3>
<br/>
<div class="container" style="font-size: .70em;">
<ul>
<li class="fragment fade-down"><strong>Chief Solutions Architect</strong><br/>
Works for Nortal Serbia & Consultant @Ananas.rs.<br/> International Speaker & Author.
Egyptian, and lives in Belgrade, Serbia.
<br/><br/>
</li>
<li class="fragment fade-down">
A <strong> Java Champion</strong>, <strong>Oracle ACE</strong>, and <strong>Jakarta EE Ambassador</strong>. Web / Cloud / Spring / Mobile / Big Data / IoT / Blockchain / DevOps, JCP, <u>2013 - 2015</u> Duke Award winner 3 times, <u>2013</u> JCP award winner.<br/><br/>
</li>
</ul>
<table class="fragment fade-down" style="width: 75%; height: 75%">
<tr>
<td style="vertical-align: middle; padding-right: 5"><img data-src="media/img/JavaMag.jpg" style="background-color: transparent; border-color: transparent; width: 400px;margin: 0 0;" alt=""/></td>
<td style="vertical-align: middle; padding-right: 5"><img data-src="media/img/OracleMag.jpg" style="background-color: transparent; border-color: transparent; width: 400px;margin: 0 0;"/></td>
<td style="vertical-align: middle; padding-right: 5"><img data-src="media/img/infoQ.jpg" style="background-color: transparent; border-color: transparent; width: 400px;margin: 0px 0px;"/></td>
<td style="vertical-align: middle; padding-right: 5"><img data-src="media/img/IBM Developer.jpeg" style="background-color: transparent; border-color: transparent; width: 400px;margin: 0px 0px;"/></td>
<td style="vertical-align: middle; padding-right: 5"><img data-src="media/img/B03998_JavaFX 8 Essentials.jpg" style="background-color: transparent; border-color: transparent; width: 600px;margin: 0px 0px;"/></td>
<td style="vertical-align: middle; padding-right: 5"><img data-src="media/img/V06608_low.png" style="background-color: transparent; border-color: transparent; width: 600px;margin: 0px 0px;"/></td>
<td style="vertical-align: middle; padding-right: 5"><img data-src="media/img/V06153_low.png" style="background-color: transparent; border-color: transparent; width: 600px;margin: 0px 0px;"/></td>
</tr>
</table>
</div>
</section>
<!--
=== Slide 1.3 - reach me ============================================================================
-->
<section>
<h3>You can catch me (🤝) <br/><br/><span class="fragment">here 👇</span></h3>
<ul style="width: 90%" class="fragment">
<li><strong>@_tamanm</strong><br/></li>
<li><a href="https://eg.linkedin.com/in/mohamedtaman">https://eg.linkedin.com/in/mohamedtaman</a><br/></li>
<li><a href="https://www.instagram.com/m.m.taman">https://www.instagram.com/m.m.taman</a><br/></li>
<li><a href="https://github.com/mohamed-taman">https://github.com/mohamed-taman</a><br/></li>
<li><a href="https://www.slideshare.net/tamanm">https://www.slideshare.net/tamanm</a><br/></li>
<li><a href="http://tamanmohamed.blogspot.com">http://tamanmohamed.blogspot.com</a><br/></li>
<li><a href="https://www.facebook.com/public/Mohamed-Mahmoud-Taman">https://www.facebook.com/public/Mohamed-Mahmoud-Taman</a><br/></li>
</ul>
<br/><br/>
<div class="fragment fade-right">
Or <em>google</em> 🕵 me <strong>"Mohamed Taman"</strong>
</div>
</section>
</section>
<!--
=== Slide 2- Introduction (Java History) ===================================================
-->
<section>
<h2>Java History 🛣 </h2>
<img style="border-radius: 15px" width="1460" height="500" class="fragment fade-down" src="media/img/JepPerRelease.png" alt="Java history"/>
<p class="x-small fragment">Image source from:
<a href="https://inside.java/2022/09/20/the-arrival-of-java-19/">The arrival of Java 19</a>
</p>
</section>
<!--
=== Slide 3 - Modularity =======================================================
-->
<section>
<!-- Slide 3.1 - Modularity -->
<section>
<h2>Big change (<span style="color: yellow">Modularity</span> 📦 )</h2>
<div class="fragment">
<div data-markdown>
<script type="text/template">
### Jigsaw [JEP 201](http://openjdk.java.net/jeps/201)<!-- .element: class="jep" -->
</script>
</div>
<blockquote>
“ Module bundle together one or more packages, and offer stronger encapsulation than jars. ”
</blockquote>
</div>
<br/>
<ul>
<li class="fragment fade-up">Allow <strong>scaled down runtime JAR</strong> → IoT, Micro-services, Embedded, Cloud.</li>
<li class="fragment fade-up"><strong>Stronger</strong>: In a module: <code>public</code> is no longer public to others.</li>
</ul>
<br/><br/>
<p class="x-small fragment">For more, here is my <strong>tutorial</strong> @IBM Developer:<br/>
<a href="https://developer.ibm.com/technologies/java/tutorials/java-modularity-1/">Java 9+ modularity: The theory and motivations behind modularity.</a>
</p>
</section>
<!-- Slide 3.2 - Features -->
<section>
<h2>Jigsaw project goals</h2>
<h2>🥅</h2>
<ul>
<li class="fragment">Modular JDK</li>
<li class="fragment">Modular Java Source Code</li>
<li class="fragment">Modular Runtime Images</li>
<li class="fragment">Encapsulate Java Internal APIs</li>
<li class="fragment">Java Platform Module System</li>
</ul>
<br/><br/>
<p class="x-small fragment">For more, here is my two <strong>tutorials</strong> @IBM Developer:<br/>
<a href="https://developer.ibm.com/technologies/java/tutorials/java-modularity-2/">Java 9+ modularity: Module basics and rules.</a><br/>
<a href="https://developer.ibm.com/technologies/java/tutorials/java-modularity-2/">Java 9+ modularity: How to design packages and create modules, Part 1, and 2.</a>
</p>
</section>
<!-- Slide 3.2 - migration tools -->
<section>
<h2>Tools 🧰 for ease of code migrations</h2>
<ul>
<li class="fragment">List built-in modules: <code>java --list-modules</code></li>
<li class="fragment">Find dependencies: <code>jdeps -jdkinternals app.jar</code></li>
<li class="fragment">Find deprecations: <code>jdeprscan app.jar</code></li>
</ul>
<br/><br/>
<p class="x-small fragment">For more, here is my <strong>tutorial</strong> @IBM Developer:<br/>
<a href="https://developer.ibm.com/technologies/java/tutorials/java-modularity-5/">Java 9+ modularity: The difficulties and pitfalls of migrating from Java 8 to Java 9+.</a>
</p>
</section>
</section>
<!--
=== Slide 4 - 6 month release cadence (More productivity) ===================================
-->
<section>
<!-- Slide 4.1 - 6 month release cadence -->
<section>
<h1>The New Six Month Release Cadence and LTS<br/>
<span class="fragment"><strong>🏎</strong></span>
</h1>
</section>
<!-- Slide 4.2 - LTS -->
<section>
<br/>
<h2>LTS 🎗 (Long-Term-Support)</h2>
<p>
Each 2 years we will have an LTS Release.
</p>
</section>
<!-- Slide 4.3 - Java SE 11 Vacuum Cleaner -->
<section>
<h1><span style="color: orange">Java SE 11</span>, is the <br/><br/><span class="fragment" style="font-size:120%">🧹</span><br/><span class="fragment">for Java jungle...</span></h1>
</section>
<!-- Slide 4.4 - Is Java Still Free -->
<!--
<section>
<h2>What is behind the new licensing model of Oracle Java?</h2>
<p>Oracle licensed Java to be commercial starting from Java 8.</p>
<br/> <br/>
<h3 class="fragment">Is <em>Java Still Free</em> of charge?</h3>
<br/>
<div class="fragment">
<h3>Yes it is 💃🕺</h3>
👉 <a href="https://medium.com/@javachampions/java-is-still-free-2-0-0-6b9aa8d6d244">Java is Still Free 2.0.3</a>
</div>
</section>
-->
</section>
<!--
=== Slide 5 - First time preview language feature (Why) =======================================
-->
<section>
<h1>For the first time, <span style="color: orange">Java 12</span></h1>
<div class="fragment">
<h3>introduces a preview language feature</h3>
<h1> <strong>🤔</strong></h1>
</div>
</section>
<!--
=== Slide 6 - Agenda ==========================================================================
-->
<section>
<h1>Agenda</h1>
<ol>
<li class="fragment">What is new?</li>
<li class="fragment">Explore new language features.</li>
<li class="fragment">Explore most of new & Improved APIs.</li>
<li class="fragment">Farewell to APIs has gone forever.</li>
</ol>
</section>
<!--
=== Slide 7 - No more JRE =====================================================================
-->
<section>
<section>
<h1>No more <em>JRE</em> available out there! 😱 </h1>
<ul>
<li class="fragment">JRE installation package is gone, since <span style="color: orange">Java SE 11</span>.</li>
<li class="fragment"><code>jlink</code> tool is here, to generate our custom JRE.</li>
</ul>
</section>
<!-- Slide 7.1 - What is jlink -->
<section>
<h2>What is <code>jlink</code> ?</h2>
<div class="fragment">
<p style=" text-align: left; margin-left:130px"><strong>Linker</strong></p>
<blockquote>
<code>jlink</code> can be used to link a set of modules, along with their transitive dependences,
to create a custom modular run-time image.
</blockquote>
</div>
</section>
</section>
<!--
=== Slide 8 - Learning tools ==================================================================
-->
<section>
<section>
<h1>New learning 👩🏼🏫 tool added to the stack.</h1>
</section>
<!-- Slide 8.1 - JShell -->
<section>
<h3>Java Shell REPL tool: <code>jshell</code> - <span class="small" style="color: orange">Java 9</span></h3>
<div data-markdown style="width: 75%; margin: 0 auto">
<script type="text/template">
````
👻 mohamed_taman:~$ jshell
| Welcome to JShell -- Version 12
| For an introduction type: /help intro
jshell> 3 + 4 * 7
$1 ==> 31
jshell> int add(int a, int b) {
...> return a+b;
...> }
| created method add(int,int)
jshell> add(25, $1)
$3 ==> 56
````
<!-- .element: class="small" -->
Get an overview with `/help` and `/help shortcuts`
<!-- .element: class="x-small" -->
</script>
</div>
<br/>
<p class="x-small fragment">For more, here is my two <strong>tutorials</strong> @IBM Developer:<br/>
<a href="https://developer.ibm.com/tutorials/java-theory-and-practice-4/">Java theory and practice: Interactive Java programming (REPL) with JShell 12, Part 1, and 2.</a>
</p>
</section>
<!-- Slide 8.2 - Old Days -->
<section>
<h2>Running <code>.java</code> old days</h2>
<div data-markdown style="width: 75%; margin: 0 auto">
<script type="text/template">
#### We have a program like this:
````
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello Java 🧡 Developers");
}
}
````
<!-- .element: class="small" -->
- Should be compiled to have `.class`
- Then run `.class` with java
<!-- .element: class="small" -->
````
mohamed_taman$ javac HelloWorld.java
mohamed_taman$ java HelloWorld
Hello Java 🧡 Developers
````
<!-- .element: class="small" -->
</script>
</div>
</section>
<!-- Slide 8.3 - Launch single-file -->
<section>
<h2>Run <code>.java</code> with <code>Java</code><span class="fragment" style="color: orange"> - Java 11</span></h2>
<div class="fragment" data-markdown style="width: 80%; margin: 0 auto">
<script type="text/template">
### Launch Single-File Source-Code Programs [JEP 330](http://openjdk.java.net/jeps/330)<!-- .element: class="jep" -->
##### And now just only run it like this:
````
mohamed_taman$ java HelloWorld.java
Hello Java 🧡 Developers
````
</script>
</div>
<br/>
<p class="x-small fragment">For more, here is my <strong>tutorial</strong> @IBM Developer:<br/>
<a href="https://developer.ibm.com/tutorials/java-theory-and-practice-2/">Java theory and practice: Run single-file source code programs without compilation.</a>
</p>
</section>
</section>
<!--
=== Slide 9 - New Language features ===========================================================
-->
<section>
<section>
<h1><span style="color: orange">Java SE</span> language features<br/><br/> 🎉🎊</h1>
</section>
<!-- Slide 9.1 - var type -->
<section>
<h2>New <code>var</code> type - <span style="color: orange">Java 10</span></h2>
<div class="fragment" data-markdown style="width: 80%; margin: 0 auto">
<script type="text/template">
#### Local-Variable Type Inference [JEP 286](http://openjdk.java.net/jeps/286)<!-- .element: class="jep" -->
````
jshell> var name = "Mohamed Taman"
name ==> "Mohamed Taman"
jshell> var lastName = name.substring(8)
lastName ==> "Taman"
jshell> lastName.getClass().getTypeName()
$3 ==> "java.lang.String"
jshell> var list = List.of(1, 2, 3, 4, 5, 6, 7);
...> var stream = list.stream();
...> stream.filter(x -> x % 2 == 0).forEach(System.out::println)
list ==> [1, 2, 3, 4, 5, 6, 7]
stream ==> java.util.stream.ReferencePipeline$Head@531d72ca
2
4
6
````
<!-- .element: class="small" -->
</script>
</div>
<p class="x-small fragment">For more, here is my <strong>tutorial</strong> @InfoQ:<br/>
<a href="https://www.infoq.com/articles/java-10-var-type">Explore the New Java 10 “var” Type: An Introduction and Hands-on Tutorial.</a>
</p>
</section>
<!-- Slide 9.2 - var for lambda parameters. -->
<section>
<h3>Local-variable (<code>var</code>) Syntax for Lambda Parameters - <span style="color: orange">Java 11</span></h3>
<pre class="fragment"><code>(String a, String b) -> a.concat(b)</code></pre>
<pre class="fragment"><code>( a, b) -> a.concat(b)</code></pre>
<pre class="fragment"><code>(var a, var b) -> a.concat(b)</code></pre>
<div class="fragment">
Because annotations needs a type
<pre><code>(@Nullable var a, @Nonnull var b) -> a.concat(b)</code></pre>
</div>
</section>
<!-- Slide 9.3 - Shell scripting with Java: Shebang files -->
<section>
<h2>Shell scripting with Java: Shebang files - <span style="color: orange">Java 11</span></h2>
<div class="fragment" data-markdown style="width: 80%; margin: 0 auto">
<script type="text/template">
##### The source code is:
````
#!/usr/bin/java --source 11
import java.nio.file.*;
public class DirectoryLister {
public static void main(String[] args) throws Exception {
var dirName = ".";
if ( args == null || args.length < 1 ){
System.err.println("Listing the current directory...");
} else {
dirName = args[0];
}
Files.walk(Paths.get(dirName)).forEach(out::println);
}}
````
<!-- .element: class="small" -->
</script>
</div>
</section>
<!-- Slide 9.3.1 - Run Shebang files -->
<section>
<h3>Run Java Shebang file</h3>
<div style="text-align: left; width: 80%; margin: 0 auto">
<p class="small">Save this code in a file named <code>dirlist</code> <em>without any extension</em> and then mark it as <strong>executable</strong>:</p>
<pre><code>mohamed_taman:code$ chmod +x dirlist</code></pre>
</div>
<div class="fragment" data-markdown style="width: 80%; margin: 0 auto">
<script type="text/template">
###### Run it as the following:
Part of: Launch Single-File Source-Code Programs [JEP 330](http://openjdk.java.net/jeps/330)<!-- .element: class="jep" -->
<!-- .element: class="x-small" -->
````
mohamed_taman:code$ ./dirlist
Listing the current directory...
.
./PalindromeChecker.java
./greater
./UsersHttpClient.java
./HelloWorld.java
./Greater.java
./dirlist
````
<!-- .element: class="small" -->
</script>
</div>
</section>
<!-- Slide 9.5 - The new, standardized HTTP Client module -->
<section>
<h2>HTTP & WebSocket Client module</h2>
<h5>The evolution of <code>HttpClient</code> and <code>WebSocket</code> API</h5>
<br/>
<ul class="x-small">
<li class="fragment">The latest <code>HttpClient</code> and <code>WebSocket</code> APIs originally shipped with <span style="color: orange">JDK 9</span> under the Java Enhancement Proposal <span class="jep">JEP 110</span> as part of an incubator module named <code>jdk.incubator.httpclient</code>.<br/><br/></li>
<li class="fragment">They were re-incubated again in <span style="color: orange">JDK 10</span>, but finally became standardized in a module named <code>java.net.http</code> and brought into the mainstream in <span style="color: orange">JDK 11</span> under <span class="jep">JEP 321</span>.<br/><br/></li>
<li class="fragment">This API provides a high-level client interface to HTTP (<em>versions 1.1 and 2</em>) and low-level client interfaces for the WebSocket API: <code>HttpClient</code>, <code>HttpRequest</code>, <code>HttpResponse</code>, and <code>WebSocket</code>.</li>
</ul>
</section>
<!-- Slide 9.5.1 - The new HTTP Client module -->
<section>
<h2>HTTP Client module</h2>
<h4>Demonstrating how all three APIs work together</h4>
<pre class="fragment" style="width: 80%; margin: 0 auto">
<code>var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
.uri(create("https://postman-echo.com/get/"))
.build();
client.sendAsync(request, ofString())
.thenApply(HttpResponse::body)
.thenAccept(out::println)
.join(); </code></pre>
<p class="x-small fragment">For more, here is my <strong>tutorial</strong> @IBM Developer:<br/>
<a href="https://developer.ibm.com/tutorials/java-theory-and-practice-3/">Java theory and practice: Explore the new Java SE 11 HTTP Client and WebSocket APIs.</a>
</p>
</section>
<!-- Slide 9.5.2 - The new, WebSocket -->
<section>
<h2>WebSocket Client module</h2>
<div class="fragment">
<p class="small" style="text-align: left; margin-left: 10%">First implement the <code>WebSocket.Listener</code> interface:</p>
<pre class="small" style="width: 70%; margin: 0 auto">
<code>public final class EchoListener implements WebSocket.Listener {
@Override
public void onOpen(WebSocket webSocket) {
logger.info("CONNECTED");
....
}
....
} </code></pre>
</div>
<div class="container fragment">
<p class="small" style="text-align: left; margin-left: 10%">use an <code>HttpClient</code> to create a <code>WebSocket</code></p>
<pre class="small" style="width: 70%; margin: 0 auto">
<code>WebSocket webSocket = httpClient.newWebSocketBuilder()
.buildAsync(URI.create("ws://demos.kaazing.com/echo"),
new EchoListener(executor)).join();
webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok").thenRun(() -> logger.info("Sent close")).join();</code>
</pre>
</div>
</section>
<!-- Slide 9.6 - switch statement -->
<section>
<h2>Old Switch statement</h2>
<pre class="x-small" style="width: 55%"><code>jshell> String getRomanNumber(int value){
String romanValue = "";
switch(value){
case 0: romanValue = "nulla";
break;
case 1: romanValue = "I";
break;
case 2: romanValue = "II";
break;
case 3: romanValue = "III";
break;
case 4: romanValue = "IV";
break;
case 5: romanValue = "V";
break;
case 6: romanValue = "VI";
break;
case 7: romanValue = "VII";
break;
case 8: romanValue = "VIII";
break;
case 9: romanValue = "IX";
break;
case 10: romanValue = "X";
break;
default: System.out.printf("Out of range value: %d %n", value);
romanValue = "N/A";
break;
}
return romanValue;
}</code></pre>
</section>
<!-- Slide 9.6.1 - New switch statement -->
<section>
<h3>New Switch statement - <span style="color: orange">Java 12</span></h3>
<pre class="fragment small" style="width: 70%"><code>mohamed_taman:~$ jshell --enable-preview</code></pre>
<pre class="small fragment" style="width: 70%"><code>String getRomanNumber(int value){
String romanValue = "";
switch(value){
case 0 -> romanValue = "nulla";
case 1 -> romanValue = "I";
case 2 -> romanValue = "II";
case 3 -> romanValue = "III";
case 4 -> romanValue = "IV";
case 5 -> romanValue = "V";
case 6 -> romanValue = "VI";
case 7 -> romanValue = "VII";
case 8 -> romanValue = "VIII";
case 9 -> romanValue = "IX";
case 10 -> romanValue = "X";
default -> {
System.out.printf("Out of range value: %d %n", value);
romanValue = "N/A";
}
}
return romanValue;
}</code></pre>
</section>
<!-- Slide 9.6.2 - new switch expression -->
<section>
<h3>New Switch expression</h3>
<pre class="small" style="width: 70%"><code>String getRomanNumber(int value){
return switch(value){
case 0 -> "nulla";
case 1 -> "I";
case 2 -> "II";
case 3 -> "III";
case 4 -> "IV";
case 5 -> "V";
case 6 -> "VI";
case 7 -> "VII";
case 8 -> "VIII";
case 9 -> "IX";
case 10 -> "X";
default -> throw new IllegalStateException("Out of range value: " + value);
};
}</code></pre>
</section>
<!-- Slide 9.6.3 - Multi-case switch statement -->
<section>
<h3>Multiple comma-separated labels in a single switch case</h3>
<div style="width: 105%; margin: 0 auto;">
<div class="twocol fragment fade-right">
<pre class="small" style="width: 95%"><code>jshell> String getOddOrEvenNumber(int value){
String kind = "N/A";
switch(value){
case 0: kind = "Zero"; break;
case 1:
case 3:
case 5:
case 7:
case 9: kind = "Odd"; break;
case 2:
case 4:
case 6:
case 8:
case 10: kind = "Even"; break;
default: System.out.printf("Out of range: %d %n", value);
}
return kind;
}</code></pre>
</div>
<div class="twocol fragment fade-down">
<pre class="small" style="width: 99%"><code>jshell> var kind = switch(value){
...> case 0 -> "Zero";
...> case 1, 3, 5, 7, 9 -> "Odd";
...> case 2, 4, 6, 8, 10 -> "Even";
...> default -> throw new IllegalStateException("Out of range: " + value);
...> };</code></pre>
</br>
<p class="fragment" style="font-size: 80%" >For more, here is my <strong>tutorial</strong> @IBM Developer:<br/>
<a href="https://developer.ibm.com/tutorials/java-theory-and-practice-6/">Effective use of the new switch statement and expression in Java SE 12.</a>
</p>
</div>
</div>
</section>
<!-- Slide 9.6.4 - New Java 13 yield keyword -->
<section>
<h3><strong>Yield</strong> and switch expression - <span style="color: orange">Java 13</span></h3>
<div style="width: 105%; margin: 0 auto;">
<div class="twocol fragment fade-right">
<pre class="small" style="width: 95%"><code>jshell>var value = 3
value ==> 3
jshell> String kind = switch(value){
...> case 0: break "Zero";
...> case 1, 3, 5, 7, 9: break "Odd";
...> case 2, 4, 6, 8, 10: break "Even";
...> default: throw new Exception("Out of range: " + value);};
kind ==> "Odd"</code></pre>
<div class="fragment fade-right">
<p>Dropping <strong style="text-decoration: line-through;">break</strong> & introducing <strong>yield</strong></p>
<pre class="small" style="width: 95%"><code>jshell> value = 10
value ==> 10
jshell> String kind = switch(value){
...> case 0: yield "Zero";
...> case 1, 3, 5, 7, 9: yield "Odd";
...> case 2, 4, 6, 8, 10: yield "Even";
...> default: throw new Exception("Out of range: " + value);};
kind ==> "Even"</code></pre>
</div>
</div>
<div class="twocol fragment fade-down">
<p style="font-size: 80%">This is why <strong>community feedback</strong> is important, & the <strong>preview feature</strong> is great for such changes. </br></br>
- In <span style="color: orange">Java 14</span> switch expressions is standardized.
</p>
<img class="fragment fade-in" src="media/img/image_04.gif" style="width: 80%; border-color: transparent;"></img>
</div>
</div>
</section>
<!-- Slide 9.7 - text block -->
<section>
<h2>New <code>Text Blocks</code> (Preview) - <span style="color: orange">Java 13</span></h2>
<div>
<h3 class="fragment">History:</h3>
<ul class="small">
<li class="fragment fade-right">This feature intended to be introduced in <span style="color: orange">Java 12</span> as <span style="text-decoration: line-through; color: red">Raw String Literals (Preview)</span>.</li>
<li class="fragment fade-right">Re-introduced as <strong>Text Blocks (Preview)</strong> in <span style="color: orange">Java 13</span>.</li>
<li class="fragment fade-right">Continue as <strong>Text Blocks (Second Preview)</strong> in <span style="color: orange">Java 14</span>.</li>
<li class="fragment fade-right">And it is <strong>Text Blocks (Final)</strong> in <span style="color: orange">Java 15</span>.</li>
</ul>
<div data-markdown style="width: 80%; margin: 0 auto" class="fragment fade-down">
<script type="text/template">
[JEP 326](http://openjdk.java.net/jeps/326)<!-- .element: class="jep" -->
[JEP 355](http://openjdk.java.net/jeps/355)<!-- .element: class="jep" -->
[JEP 368](http://openjdk.java.net/jeps/368)<!-- .element: class="jep" -->
[JEP 378](http://openjdk.java.net/jeps/378)<!-- .element: class="jep" -->
</script>
</div>
</div>
<div style="width: 105%; margin: 0 auto;">
<div class="twocol fragment fade-right">
<pre class="small"><code>var html = "\n" +
"<html>\n" +
" <body>\n" +
" <p>Hello, world</p>\n" +
" </body>\n" +
"</html>\n";
</code></pre>
</div>
<div class="twocol fragment fade-left">
<pre class="small"><code>var html = """
<html>
<body>
<p>Hello, world</p>
</body>
</html>
""";</code></pre>
</div>
</div>
</section>
<!-- Slide 9.8 - Pattern matching -->
<section>
<h3>Pattern Matching for <strong>instanceof</strong> (Preview) - <span style="color: orange">Java 14</span>, and (second preview) <span style="color: orange">Java 15</span></h3>
<a class="jep" style="color: white" href="http://openjdk.java.net/jeps/305">JEP 305</a>
<a class="jep" style="color: white" href="http://openjdk.java.net/jeps/375">JEP 375</a>
<div style="width: 105%; margin: 0 auto;">
<div class="twocol">
<pre class="small fragment fade-down" style="width: 95%"><code>//Old Days
if (obj instanceof String) {
// Need to declare & cast again the object
String str = (String) obj;
.. str.contains(..) ..
}else{
.. str = ....
}</code></pre>
<pre class="small fragment fade-right" style="width: 95%"><code>//Java 14 Onwards
if (obj instanceof String str) {
// No need to declare str object again with casting
.. str.contains(..) ..
} else {
.. str....
}</code></pre>
</div>
<div class="twocol fragment fade-down">
<pre class="small" style="width: 99%"><code>//More complex examples
if (obj instanceof String str && str.length() > 5) { .. str.contains(..) .. }</code></pre>
<br/>
<p>The use of pattern matching in <strong>instanceof</strong> should dramatically reduce the overall number of explicit casts in Java programs.</p>
</div>
</div>
</section>
<!-- Slide 9.9 - Records -->
<section>
<h3>Records (1st Preview) <span style="color: orange">Java 14</span>, (2nd Preview) <span style="color: orange">Java 15</span>, & (Standardized) <span style="color: orange">Java 16</span></h3>
<a class="jep" style="color: white" href="http://openjdk.java.net/jeps/359">JEP 359</a>
<a class="jep" style="color: white" href="http://openjdk.java.net/jeps/384">JEP 384</a>
<a class="jep" style="color: white" href="http://openjdk.java.net/jeps/395">JEP 395</a>
<div class="x-small fragment fade-down" style="width: 90%; text-align: left; margin-left: 5%">We need to write a lot of low-value, repetitive code to write a simple data carrier class responsibly: <code>constructors</code>, <code>accessors</code>, <code>equals()</code>, <code>hashCode()</code>, <code>toString()</code>, etc. To avoid this repetitive code, Java introduced records. In the Second preview it works well with Sealed Classes, and could be declared locally.</div>
<pre class="small fragment fade-left"><code>final class Point {
public final int x;
public final int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
// state-based implementations of equals, hashCode, toString
// nothing else</code></pre>
<pre class="small fragment fade-left"><code>record Point(int x, int y) { }</code></pre>
</section>
<!-- Slide 9.10 - NPE enhancements -->
<section>
<h3>Helpful NullPointerExceptions - <span style="color: orange">Java 14</span></h3>
<a class="jep" style="color: white" href="http://openjdk.java.net/jeps/358">JEP 358</a>
<div class="x-small fragment fade-down" style="width: 90%; text-align: left; margin-left: 5%">Before Java 14, the JVM will print out the method, filename, and line number that caused the NPE:</div>
<pre class="small fragment fade-left"><code>a.i = 99;
Exception in thread "main" java.lang.NullPointerException
at Prog.main(Prog.java:5)</code></pre>
<div class="x-small fragment fade-down" style="width: 90%; text-align: left; margin-left: 5%">In Java 14 - Suppose an NPE occurs in this code:</div>
<pre class="small fragment fade-left"><code>a.b.c.i = 99;</code></pre>
<pre class="small fragment fade-left"><code>Exception in thread "main" java.lang.NullPointerException:
Cannot read field 'c' because 'a.b' is null.
at Prog.main(Prog.java:5)</code></pre>
</section>
<!-- Slide 9.9 - Sealed Classes -->
<section>
<h3>Sealed Classes (Preview) - <span style="color: orange">Java 15</span></h3>
<a class="jep" style="color: white" href="http://openjdk.java.net/jeps/360">JEP 360</a>
<div class="x-small fragment fade-down" style="width: 90%; text-align: left; margin-left: 5%">It allow the author of a class or interface to control which code is responsible for implementing it. And it provide a more declarative way than access modifiers to restrict the use of a superclass.</div>
<pre class="small fragment fade-left"><code>package com.example.geometry;
public sealed class Shape
permits Circle, Rectangle, Square {...}
public final class Circle extends Shape {...}
public sealed class Rectangle extends Shape
permits TransparentRectangle, FilledRectangle {...}
public final class TransparentRectangle extends Rectangle {...}
public final class FilledRectangle extends Rectangle {...}
public non-sealed class Square extends Shape {...}</code></pre>
</section>
<!-- Slide 9.10 - Records & Sealed Classes -->
<section>
<h3>Records (2nd Preview) - <span style="color: orange">Java 15</span></h3>
<a class="jep" style="color: white" href="http://openjdk.java.net/jeps/359">JEP 359</a>
<div class="x-small fragment fade-down" style="width: 90%; text-align: left; margin-left: 5%">It allow you to define a sealed interface and implement them on your records</div>
<pre class="small fragment fade-left"><code>sealed interface Car permits BMW, Audi { ... }
record BMW(int price) implements Car { ... }
record Audi(int price, String model) implements Car { ... }</code></pre>
<div class="x-small fragment fade-down" style="width: 90%; text-align: left; margin-left: 5%">Local records are a great boon for Java developers who would earlier have to create helper records</div>
<pre class="small fragment fade-left"><code>List<Merchant> findTopMerchants(List<Merchant> merchants, int month) {
// Local record
record MerchantSales(Merchant merchant, double sales) {}
return merchants.stream()
.map(merchant -> new MerchantSales(merchant, computeSales(merchant, month)))
.sorted((m1, m2) -> Double.compare(m2.sales(), m1.sales()))
.map(MerchantSales::merchant)
.toList();
}</code></pre>
</section>
</section>
<!--
=== Slide 10 - New language APIs ==============================================================
-->
<section>
<!-- Slide 10.1 - New language APIs -->
<section>
<p style="font-size: 300%">👓</p>
<h1 class="fragment"> New language APIs</h1>
</section>
<!-- Slide 10.2.1 - String class new enhancements 1 -->
<section>
<h2><code>String</code> class new enhancements</h2>
<ul>
<li class="fragment"><code>String repeat(int)</code> - <span style="color: orange">Java 11</span>
<pre class="fragment" style="width: 100%"><code>jshell> "no ".repeat(14).trim().concat(", Batman!")
$1 ==> "no no no no no no no no no no no no no no, Batman!</code></pre>
</li>
<li class="fragment"><code>boolean isBlank()</code> - <span style="color: orange">Java 11</span>
<pre class="small" style="width: 100%"><code>jshell>var blankText = " "
blankText ==> " "
jshell>blankText.trim().length() == 0
$2 ==> true
jshell>blankText.isBlank()
$3 ==> true</code></pre>
</li>
</ul>
</section>
<!-- Slide 10.2.2 - String class new enhancements 2 -->
<section>
<ul>
<li><code>String stripLeading()</code> - <span style="color: orange">Java 11</span></li>
<li><code>String stripTrailing()</code> - <span style="color: orange">Java 11</span></li>
<li><code>String strip()</code> - <span style="color: orange">Java 11</span>
<pre class="fragment small" style="width: 100%"><code>jshell>var textWithSpaces = "\n \t Text \u2005"
textWithSpaces ==> "\n \t Text "
jshell>textWithSpaces.trim()
$4 ==> "Text "
jshell>textWithSpaces.strip()
$5 ==> "Text"</code></pre>
</li>
<li class="fragment"><code>Stream lines()</code> - <span style="color: orange">Java 11</span>
<pre class="small" style="width: 100%"><code>jshell> "\nOne\nTwo\nThree\nFour".lines().forEach(System.out::println)
One
Two
Three
Four</code></pre>
</li>
</ul>
</section>
<!-- Slide 10.2.3 - String class new enhancements 3 -->
<section>
<ul>
<li><code>String indent(int)</code> - <span style="color: orange">Java 12</span>
<pre class="fragment small" style="width: 100%"><code>jshell> "\nOne\nTwo\nThree\nFour".indent(5).indent(-2).lines().forEach(System.out::println)
... One
... Two
... Three
... Four</code></pre>
</li>
<li class="fragment"><code>String transform(Function)</code> - <span style="color: orange">Java 12</span>
<pre class="small" style="width: 100%"><code>jshell> var text = "Text with*out *some* *asterisks"
text ==> "Text wi*th *some* * asterisks"
jshell> text.transform(String::toUpperCase)
...> .transform(s -> s.replaceAll("\\*", ""))
...> .transform(s -> s.split(" "))
$1 ==> String[4] { "TEXT", "WITHOUT", "SOME", "ASTERISKS" }
</code></pre>
</li>
</ul>
<p class="x-small fragment">For more, here is my <strong>tutorial</strong> @IBM Developer:<br/>
<a href="https://developer.ibm.com/tutorials/java-theory-and-practice-1/">Java theory and practice: Explore new Java SE 11 and 12 APIs and language features.</a>
</p>
</section>
<!-- Slide 10.2.4 - String class new enhancements 4 -->
<section>
<h4>As part of: Text Blocks (Preview) - <span style="color: orange">Java 13</span>
<div data-markdown>
<script type="text/template">
[JEP 355](https://openjdk.java.net/jeps/355)<!-- .element: class="jep" -->
<!-- .element: class="small" -->
</script>
</div>
</h4>
<ul class="small">
<li><code>String formatted(Object[])</code>
<pre class="small fragment fade-right" style="width: 100%"><code>jshell> "Hello %s!".formatted("World")
| Warning:
| formatted(java.lang.Object...) in java.lang.String has been deprecated and marked for removal
| "Hello %s!".formatted("World")
| ^-------------------^
$11 ==> "Hello World!"</code></pre>
</li>