├── NullPointerExceptionJava11
├── .idea
│ ├── .gitignore
│ ├── misc.xml
│ └── modules.xml
├── NullPointerExceptionJava11.iml
├── out
│ └── production
│ │ └── NullPointerExceptionJava11
│ │ ├── Person.class
│ │ └── new_npe.class
└── src
│ ├── Person.java
│ └── new_npe.java
├── README.md
├── java17-new-features-maven
├── .idea
│ ├── .gitignore
│ ├── .name
│ ├── aws.xml
│ ├── compiler.xml
│ ├── inspectionProfiles
│ │ └── Project_Default.xml
│ ├── jarRepositories.xml
│ ├── java17-new-features-maven.iml
│ ├── jpa-buddy.xml
│ ├── misc.xml
│ ├── sonarlint
│ │ ├── issuestore
│ │ │ ├── 0
│ │ │ │ └── 8
│ │ │ │ │ └── 08ac37da870790b545a243217102f40e60ff8a81
│ │ │ ├── 1
│ │ │ │ └── b
│ │ │ │ │ └── 1b6791915536d60b0fd8e2c791704c29c6f08f5f
│ │ │ ├── 3
│ │ │ │ ├── 3
│ │ │ │ │ └── 33fd82496ade21fe8731c2418170e8144ac95fe4
│ │ │ │ └── c
│ │ │ │ │ └── 3c7d775a28ad92c3eadff6bd73aeac814d3fe544
│ │ │ ├── 4
│ │ │ │ ├── 4
│ │ │ │ │ └── 442292b8a7efeabbe4cc176709b833b1792140ec
│ │ │ │ └── a
│ │ │ │ │ └── 4a248bbc356af3e2d99734ee769633b801c4c1c2
│ │ │ ├── 5
│ │ │ │ └── b
│ │ │ │ │ └── 5bb3a06fd28ff8cb2e17e71ab89d12f2382f35b7
│ │ │ ├── 6
│ │ │ │ ├── 2
│ │ │ │ │ └── 62bb47d63b3ac7f8adef0386c798eeb573850071
│ │ │ │ ├── 3
│ │ │ │ │ └── 633222189768ac274eae82c75850b90844c95a4a
│ │ │ │ └── c
│ │ │ │ │ └── 6ce28a5452654b5719d2ca20b22de2dd56684c34
│ │ │ ├── 7
│ │ │ │ ├── 9
│ │ │ │ │ └── 79fe5d782c33cd96fad93401f84e5ab0c52e44ac
│ │ │ │ └── e
│ │ │ │ │ └── 7e140c1ac04e1cf4d448b804a1c56804b72645e3
│ │ │ ├── 8
│ │ │ │ └── c
│ │ │ │ │ └── 8c05b11263fa3b0e36bb5d89bec21e3b3d2cc4ea
│ │ │ ├── 9
│ │ │ │ ├── 5
│ │ │ │ │ └── 954f0c3af94e5baf95b9597b539030a3e36ad592
│ │ │ │ └── 6
│ │ │ │ │ └── 96dc91351f54e26d99f3f95c1d23e0f5362606db
│ │ │ ├── a
│ │ │ │ ├── 6
│ │ │ │ │ └── a67798c8feb4b061357a15f309a7ae4162b821c9
│ │ │ │ └── b
│ │ │ │ │ └── aba116ac664ef81db1535fb4e209b8aef0b1ed52
│ │ │ ├── b
│ │ │ │ ├── 5
│ │ │ │ │ └── b5b0fb455171995b05507fe4a7c504c37984b438
│ │ │ │ ├── 8
│ │ │ │ │ └── b8b516baca35f078bca44887ad9f03fb6cec6c47
│ │ │ │ └── a
│ │ │ │ │ └── ba50c4a412c04aad20396bfc200292b913d533ad
│ │ │ ├── d
│ │ │ │ ├── 1
│ │ │ │ │ └── d18ecfd8939b56e1d8ada9b7da664879014ac365
│ │ │ │ └── e
│ │ │ │ │ └── de29498ea6fad7ebadde568d54e2d486aa08d908
│ │ │ ├── e
│ │ │ │ ├── 2
│ │ │ │ │ └── e243b9b84490e69eeff8aa975faee840624a3589
│ │ │ │ └── 9
│ │ │ │ │ └── e9032d0738a3fca281d7d249ffdd2ec96a6c3afa
│ │ │ ├── f
│ │ │ │ ├── 4
│ │ │ │ │ └── f4b11938ecbc3fb464638d9e4771f326262771f5
│ │ │ │ └── a
│ │ │ │ │ └── faad8a2def78af87a12d883c19226dac8949be3a
│ │ │ └── index.pb
│ │ └── securityhotspotstore
│ │ │ ├── 0
│ │ │ └── 8
│ │ │ │ └── 08ac37da870790b545a243217102f40e60ff8a81
│ │ │ ├── 1
│ │ │ └── b
│ │ │ │ └── 1b6791915536d60b0fd8e2c791704c29c6f08f5f
│ │ │ ├── 3
│ │ │ ├── 3
│ │ │ │ └── 33fd82496ade21fe8731c2418170e8144ac95fe4
│ │ │ └── c
│ │ │ │ └── 3c7d775a28ad92c3eadff6bd73aeac814d3fe544
│ │ │ ├── 4
│ │ │ ├── 4
│ │ │ │ └── 442292b8a7efeabbe4cc176709b833b1792140ec
│ │ │ └── a
│ │ │ │ └── 4a248bbc356af3e2d99734ee769633b801c4c1c2
│ │ │ ├── 5
│ │ │ └── b
│ │ │ │ └── 5bb3a06fd28ff8cb2e17e71ab89d12f2382f35b7
│ │ │ ├── 6
│ │ │ ├── 2
│ │ │ │ └── 62bb47d63b3ac7f8adef0386c798eeb573850071
│ │ │ ├── 3
│ │ │ │ └── 633222189768ac274eae82c75850b90844c95a4a
│ │ │ └── c
│ │ │ │ └── 6ce28a5452654b5719d2ca20b22de2dd56684c34
│ │ │ ├── 7
│ │ │ ├── 9
│ │ │ │ └── 79fe5d782c33cd96fad93401f84e5ab0c52e44ac
│ │ │ └── e
│ │ │ │ └── 7e140c1ac04e1cf4d448b804a1c56804b72645e3
│ │ │ ├── 8
│ │ │ └── c
│ │ │ │ └── 8c05b11263fa3b0e36bb5d89bec21e3b3d2cc4ea
│ │ │ ├── 9
│ │ │ ├── 5
│ │ │ │ └── 954f0c3af94e5baf95b9597b539030a3e36ad592
│ │ │ └── 6
│ │ │ │ └── 96dc91351f54e26d99f3f95c1d23e0f5362606db
│ │ │ ├── a
│ │ │ ├── 6
│ │ │ │ └── a67798c8feb4b061357a15f309a7ae4162b821c9
│ │ │ └── b
│ │ │ │ └── aba116ac664ef81db1535fb4e209b8aef0b1ed52
│ │ │ ├── b
│ │ │ ├── 5
│ │ │ │ └── b5b0fb455171995b05507fe4a7c504c37984b438
│ │ │ ├── 8
│ │ │ │ └── b8b516baca35f078bca44887ad9f03fb6cec6c47
│ │ │ └── a
│ │ │ │ └── ba50c4a412c04aad20396bfc200292b913d533ad
│ │ │ ├── d
│ │ │ ├── 1
│ │ │ │ └── d18ecfd8939b56e1d8ada9b7da664879014ac365
│ │ │ └── e
│ │ │ │ └── de29498ea6fad7ebadde568d54e2d486aa08d908
│ │ │ ├── e
│ │ │ ├── 2
│ │ │ │ └── e243b9b84490e69eeff8aa975faee840624a3589
│ │ │ └── 9
│ │ │ │ └── e9032d0738a3fca281d7d249ffdd2ec96a6c3afa
│ │ │ ├── f
│ │ │ ├── 4
│ │ │ │ └── f4b11938ecbc3fb464638d9e4771f326262771f5
│ │ │ └── a
│ │ │ │ └── faad8a2def78af87a12d883c19226dac8949be3a
│ │ │ └── index.pb
│ ├── uiDesigner.xml
│ └── vcs.xml
├── java-new-features-maven.iml
├── pom.xml
├── src
│ └── test
│ │ └── java
│ │ ├── java18_to_21
│ │ ├── SequencedCollection
│ │ │ └── SequencedCollectionSample.java
│ │ ├── parttern_matching
│ │ │ ├── record_type
│ │ │ │ └── RecordPatternMatching.java
│ │ │ └── with_switch
│ │ │ │ └── PatternMatchingSwitch.java
│ │ ├── scoped_values
│ │ │ ├── Multiplier.java
│ │ │ └── ScopedValuesExample.java
│ │ ├── string_templates
│ │ │ └── StringTemplates.java
│ │ ├── structured_concurrency
│ │ │ ├── CombinedWeatherInfoDemo.java
│ │ │ ├── CombinedWeatherInfoTaskScope.java
│ │ │ ├── ExecutorServiceDemo.java
│ │ │ ├── ShutdownOnFailureDemo.java
│ │ │ ├── ShutdownOnSuccessDemo.java
│ │ │ ├── StructuredConcurrencyDemo.java
│ │ │ ├── StructuredConcurrencyWithScopedValueDemo.java
│ │ │ ├── model
│ │ │ │ ├── Customer.java
│ │ │ │ ├── Invoice.java
│ │ │ │ ├── Order.java
│ │ │ │ ├── Repository.java
│ │ │ │ ├── RepositoryWithScopedValue.java
│ │ │ │ ├── WeatherApiClient.java
│ │ │ │ └── WeatherInfo.java
│ │ │ └── util
│ │ │ │ └── SimpleLogger.java
│ │ ├── unnamed_classes_and_instance_main_methods
│ │ │ └── UnnamedClassesAndInstanceMainMethods.java
│ │ ├── unnamed_patterns_and_variables
│ │ │ └── UnnamedPatternsAndVariables.java
│ │ └── virtual_thread
│ │ │ └── CreateVirtualThread.java
│ │ └── java9_to_17
│ │ ├── instance_of
│ │ ├── AbstractFile.java
│ │ ├── InstanceOfExample.java
│ │ ├── MusicFile.java
│ │ └── VideoFile.java
│ │ ├── local_variable_type_inference
│ │ └── VarExample.java
│ │ ├── new_NPE
│ │ ├── Person.java
│ │ └── new_npe.java
│ │ ├── new_switch
│ │ ├── EnhanceSwitchStatement.java
│ │ └── TraditionalSwitch.java
│ │ ├── of_for_collections
│ │ └── CollectionsExample.java
│ │ ├── records
│ │ ├── Person.java
│ │ ├── PersonLombok.java
│ │ ├── PersonRecord.java
│ │ └── Records.java
│ │ ├── sealed_classes
│ │ ├── AudioFile.java
│ │ ├── Drive.java
│ │ ├── ExtendedMP3File.java
│ │ ├── HddDrive.java
│ │ └── MP3File.java
│ │ └── text_blocks
│ │ └── TextBlocks.java
└── target
│ └── test-classes
│ ├── instance_of
│ ├── AbstractFile.class
│ ├── InstanceOfExample.class
│ ├── MusicFile.class
│ └── VideoFile.class
│ ├── local_variable_type_inference
│ └── VarExample.class
│ ├── new_NPE
│ ├── Person.class
│ └── new_npe.class
│ ├── new_switch
│ ├── EnhanceSwitchStatement.class
│ └── TraditionalSwitch.class
│ ├── of_for_collections
│ └── CollectionsExample.class
│ ├── records
│ ├── Person.class
│ ├── PersonRecord.class
│ └── Records.class
│ ├── sealed_classes
│ ├── AudioFile.class
│ ├── Drive.class
│ ├── ExtendedMP3File.class
│ ├── HddDrive.class
│ └── MP3File.class
│ └── text_blocks
│ └── TextBlocks.class
├── jdk-22
├── jdk-22.iml
└── src
│ └── StreamGatherers.java
└── resources
├── Java 8 - 18 New features.pptx
├── Java new features - Presenter notes.docx
├── Pictures.png
├── java-release-plan.JPG
├── poster.png
├── poster.psd
└── some-notes-to-compile-new-JDK-21-RC-version-features.txt
/NullPointerExceptionJava11/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/NullPointerExceptionJava11/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/NullPointerExceptionJava11/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/NullPointerExceptionJava11/NullPointerExceptionJava11.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/NullPointerExceptionJava11/out/production/NullPointerExceptionJava11/Person.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/NullPointerExceptionJava11/out/production/NullPointerExceptionJava11/Person.class
--------------------------------------------------------------------------------
/NullPointerExceptionJava11/out/production/NullPointerExceptionJava11/new_npe.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/NullPointerExceptionJava11/out/production/NullPointerExceptionJava11/new_npe.class
--------------------------------------------------------------------------------
/NullPointerExceptionJava11/src/Person.java:
--------------------------------------------------------------------------------
1 | public class Person {
2 |
3 | private String name;
4 | private int age;
5 |
6 | public Person(String name, int age) {
7 | this.name = name;
8 | this.age = age;
9 | }
10 |
11 | public String getName() {
12 | return name;
13 | }
14 |
15 | public int getAge() {
16 | return age;
17 | }
18 | }
--------------------------------------------------------------------------------
/NullPointerExceptionJava11/src/new_npe.java:
--------------------------------------------------------------------------------
1 | public class new_npe {
2 |
3 | public static void main(String[] args) {
4 |
5 | Person person1 = new Person("Mehdi", 34);
6 | System.out.println(person1.getName().toLowerCase());
7 |
8 | // Person person2 = new Person(null, 34);
9 | // System.out.println(person2.getName().toLowerCase());
10 |
11 | Person person3 = null;
12 | System.out.println(person3.getName().toLowerCase());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | https://youtu.be/zTBmcUdoEOA
2 |
3 | In this repository, you can find some examples of new JDK features:
4 |
5 | 1. new instanceOf
6 | 2. Local variable type inference
7 | 3. Descriptive NullPointerException
8 | 4. New switch statement
9 | 5. The of() method for collection framework
10 | 6. The record type
11 | 7. Sealed classes
12 | 8. Text blocks
13 | 9. Pattern matching for switch statement
14 | 10. Pattern matching for record type
15 | 11. Scoped values
16 | 12. Sequenced collections
17 | 13. String templates
18 | 14. structured concurrency
19 | 15. Unnamed classes and main method
20 | 16. Unnamed variables
21 | 17. Virtual threads
22 |
23 | JDK 22:
24 | 1. Stream Gatherers (JEP-461) for Enhanced Java Stream Operations
25 |
26 |
27 | Please, Don't forget to STAR the repository. Thank you!
28 |
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/.name:
--------------------------------------------------------------------------------
1 | java-new-features-maven
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/aws.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
11 |
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/java17-new-features-maven.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/jpa-buddy.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/0/8/08ac37da870790b545a243217102f40e60ff8a81:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/0/8/08ac37da870790b545a243217102f40e60ff8a81
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/1/b/1b6791915536d60b0fd8e2c791704c29c6f08f5f:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/1/b/1b6791915536d60b0fd8e2c791704c29c6f08f5f
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/3/3/33fd82496ade21fe8731c2418170e8144ac95fe4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/3/3/33fd82496ade21fe8731c2418170e8144ac95fe4
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/3/c/3c7d775a28ad92c3eadff6bd73aeac814d3fe544:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/3/c/3c7d775a28ad92c3eadff6bd73aeac814d3fe544
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/4/4/442292b8a7efeabbe4cc176709b833b1792140ec:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/4/4/442292b8a7efeabbe4cc176709b833b1792140ec
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/4/a/4a248bbc356af3e2d99734ee769633b801c4c1c2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/4/a/4a248bbc356af3e2d99734ee769633b801c4c1c2
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/5/b/5bb3a06fd28ff8cb2e17e71ab89d12f2382f35b7:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/5/b/5bb3a06fd28ff8cb2e17e71ab89d12f2382f35b7
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/6/2/62bb47d63b3ac7f8adef0386c798eeb573850071:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/6/2/62bb47d63b3ac7f8adef0386c798eeb573850071
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/6/3/633222189768ac274eae82c75850b90844c95a4a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/6/3/633222189768ac274eae82c75850b90844c95a4a
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/6/c/6ce28a5452654b5719d2ca20b22de2dd56684c34:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/6/c/6ce28a5452654b5719d2ca20b22de2dd56684c34
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/7/9/79fe5d782c33cd96fad93401f84e5ab0c52e44ac:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/7/9/79fe5d782c33cd96fad93401f84e5ab0c52e44ac
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/7/e/7e140c1ac04e1cf4d448b804a1c56804b72645e3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/7/e/7e140c1ac04e1cf4d448b804a1c56804b72645e3
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/8/c/8c05b11263fa3b0e36bb5d89bec21e3b3d2cc4ea:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/8/c/8c05b11263fa3b0e36bb5d89bec21e3b3d2cc4ea
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/9/5/954f0c3af94e5baf95b9597b539030a3e36ad592:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/9/5/954f0c3af94e5baf95b9597b539030a3e36ad592
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/9/6/96dc91351f54e26d99f3f95c1d23e0f5362606db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/9/6/96dc91351f54e26d99f3f95c1d23e0f5362606db
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/a/6/a67798c8feb4b061357a15f309a7ae4162b821c9:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/a/6/a67798c8feb4b061357a15f309a7ae4162b821c9
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/a/b/aba116ac664ef81db1535fb4e209b8aef0b1ed52:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/a/b/aba116ac664ef81db1535fb4e209b8aef0b1ed52
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/b/5/b5b0fb455171995b05507fe4a7c504c37984b438:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/b/5/b5b0fb455171995b05507fe4a7c504c37984b438
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/b/8/b8b516baca35f078bca44887ad9f03fb6cec6c47:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/b/8/b8b516baca35f078bca44887ad9f03fb6cec6c47
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/b/a/ba50c4a412c04aad20396bfc200292b913d533ad:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/b/a/ba50c4a412c04aad20396bfc200292b913d533ad
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/d/1/d18ecfd8939b56e1d8ada9b7da664879014ac365:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/d/1/d18ecfd8939b56e1d8ada9b7da664879014ac365
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/d/e/de29498ea6fad7ebadde568d54e2d486aa08d908:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/d/e/de29498ea6fad7ebadde568d54e2d486aa08d908
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/e/2/e243b9b84490e69eeff8aa975faee840624a3589:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/e/2/e243b9b84490e69eeff8aa975faee840624a3589
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/e/9/e9032d0738a3fca281d7d249ffdd2ec96a6c3afa:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/e/9/e9032d0738a3fca281d7d249ffdd2ec96a6c3afa
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/f/4/f4b11938ecbc3fb464638d9e4771f326262771f5:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/f/4/f4b11938ecbc3fb464638d9e4771f326262771f5
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/f/a/faad8a2def78af87a12d883c19226dac8949be3a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/f/a/faad8a2def78af87a12d883c19226dac8949be3a
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/issuestore/index.pb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/issuestore/index.pb
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/0/8/08ac37da870790b545a243217102f40e60ff8a81:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/0/8/08ac37da870790b545a243217102f40e60ff8a81
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/1/b/1b6791915536d60b0fd8e2c791704c29c6f08f5f:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/1/b/1b6791915536d60b0fd8e2c791704c29c6f08f5f
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/3/3/33fd82496ade21fe8731c2418170e8144ac95fe4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/3/3/33fd82496ade21fe8731c2418170e8144ac95fe4
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/3/c/3c7d775a28ad92c3eadff6bd73aeac814d3fe544:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/3/c/3c7d775a28ad92c3eadff6bd73aeac814d3fe544
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/4/4/442292b8a7efeabbe4cc176709b833b1792140ec:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/4/4/442292b8a7efeabbe4cc176709b833b1792140ec
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/4/a/4a248bbc356af3e2d99734ee769633b801c4c1c2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/4/a/4a248bbc356af3e2d99734ee769633b801c4c1c2
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/5/b/5bb3a06fd28ff8cb2e17e71ab89d12f2382f35b7:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/5/b/5bb3a06fd28ff8cb2e17e71ab89d12f2382f35b7
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/6/2/62bb47d63b3ac7f8adef0386c798eeb573850071:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/6/2/62bb47d63b3ac7f8adef0386c798eeb573850071
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/6/3/633222189768ac274eae82c75850b90844c95a4a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/6/3/633222189768ac274eae82c75850b90844c95a4a
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/6/c/6ce28a5452654b5719d2ca20b22de2dd56684c34:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/6/c/6ce28a5452654b5719d2ca20b22de2dd56684c34
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/7/9/79fe5d782c33cd96fad93401f84e5ab0c52e44ac:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/7/9/79fe5d782c33cd96fad93401f84e5ab0c52e44ac
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/7/e/7e140c1ac04e1cf4d448b804a1c56804b72645e3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/7/e/7e140c1ac04e1cf4d448b804a1c56804b72645e3
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/8/c/8c05b11263fa3b0e36bb5d89bec21e3b3d2cc4ea:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/8/c/8c05b11263fa3b0e36bb5d89bec21e3b3d2cc4ea
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/9/5/954f0c3af94e5baf95b9597b539030a3e36ad592:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/9/5/954f0c3af94e5baf95b9597b539030a3e36ad592
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/9/6/96dc91351f54e26d99f3f95c1d23e0f5362606db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/9/6/96dc91351f54e26d99f3f95c1d23e0f5362606db
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/a/6/a67798c8feb4b061357a15f309a7ae4162b821c9:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/a/6/a67798c8feb4b061357a15f309a7ae4162b821c9
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/a/b/aba116ac664ef81db1535fb4e209b8aef0b1ed52:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/a/b/aba116ac664ef81db1535fb4e209b8aef0b1ed52
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/b/5/b5b0fb455171995b05507fe4a7c504c37984b438:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/b/5/b5b0fb455171995b05507fe4a7c504c37984b438
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/b/8/b8b516baca35f078bca44887ad9f03fb6cec6c47:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/b/8/b8b516baca35f078bca44887ad9f03fb6cec6c47
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/b/a/ba50c4a412c04aad20396bfc200292b913d533ad:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/b/a/ba50c4a412c04aad20396bfc200292b913d533ad
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/d/1/d18ecfd8939b56e1d8ada9b7da664879014ac365:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/d/1/d18ecfd8939b56e1d8ada9b7da664879014ac365
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/d/e/de29498ea6fad7ebadde568d54e2d486aa08d908:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/d/e/de29498ea6fad7ebadde568d54e2d486aa08d908
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/e/2/e243b9b84490e69eeff8aa975faee840624a3589:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/e/2/e243b9b84490e69eeff8aa975faee840624a3589
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/e/9/e9032d0738a3fca281d7d249ffdd2ec96a6c3afa:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/e/9/e9032d0738a3fca281d7d249ffdd2ec96a6c3afa
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/f/4/f4b11938ecbc3fb464638d9e4771f326262771f5:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/f/4/f4b11938ecbc3fb464638d9e4771f326262771f5
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/f/a/faad8a2def78af87a12d883c19226dac8949be3a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/f/a/faad8a2def78af87a12d883c19226dac8949be3a
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/index.pb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/.idea/sonarlint/securityhotspotstore/index.pb
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/java17-new-features-maven/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/java17-new-features-maven/java-new-features-maven.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/java17-new-features-maven/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.example
8 | java-new-features-maven
9 | 1.0-SNAPSHOT
10 |
11 |
12 | 21
13 |
14 |
15 | 21
16 |
17 |
18 |
19 |
20 |
21 | projectlombok.org
22 | https://projectlombok.org/edge-releases
23 |
24 |
25 |
26 |
27 |
28 | org.junit.jupiter
29 | junit-jupiter-engine
30 | 5.8.2
31 | test
32 |
33 |
34 | org.junit.jupiter
35 | junit-jupiter-api
36 | 5.8.2
37 | test
38 |
39 |
40 | org.junit.jupiter
41 | junit-jupiter-params
42 | 5.8.2
43 | test
44 |
45 |
46 | org.junit.platform
47 | junit-platform-suite
48 | 1.8.2
49 | test
50 |
51 |
52 | org.projectlombok
53 | lombok
54 | 1.18.30
55 | provided
56 |
57 |
58 |
59 |
60 |
61 | org.apache.maven.plugins
62 | maven-compiler-plugin
63 | 3.11.0
64 |
65 | 21
66 | 21
67 | --enable-preview
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/SequencedCollection/SequencedCollectionSample.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.SequencedCollection;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class SequencedCollectionSample {
6 |
7 | public static void main(String[] args) {
8 |
9 | // Traditional - first and last element
10 | var arrayList = new ArrayList();
11 |
12 | arrayList.add(1); // [1]
13 |
14 | // arrayList.get(arrayList.iterator().next()); // first element
15 | // arrayList.get(arrayList.size() - 1); // last element
16 |
17 | // SequencedCollection interface
18 |
19 | arrayList = new ArrayList<>();
20 |
21 | arrayList.add(1); // [1]
22 |
23 | arrayList.addFirst(0); // [0, 1]
24 | arrayList.addLast(2); // [0, 1, 2]
25 |
26 | arrayList.getFirst(); // 0
27 | arrayList.getLast(); // 2
28 |
29 | arrayList.forEach(System.out::println); // [0, 1, 2]
30 | }
31 |
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/parttern_matching/record_type/RecordPatternMatching.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.parttern_matching.record_type;
2 |
3 | //@formatter:off
4 | record PersonRecord(String name, int age) {}
5 |
6 | //@formatter:on
7 |
8 | public class RecordPatternMatching {
9 |
10 | public static void main(String[] args) {
11 | PersonRecord personRecord = new PersonRecord("John", 30);
12 | System.out.println(personRecord);
13 |
14 | Object personRecordAsObj = personRecord;
15 |
16 | // traditional way
17 |
18 | if (personRecordAsObj instanceof PersonRecord p) {
19 |
20 | String name = p.name();
21 | int age = p.age();
22 | System.out.println("name: " + name + ", age: " + age);
23 | }
24 |
25 | // record pattern matching with new way
26 |
27 | if (personRecordAsObj instanceof PersonRecord(String name, int age)) {
28 |
29 | System.out.println("name: " + name + ", age: " + age);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/parttern_matching/with_switch/PatternMatchingSwitch.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.parttern_matching.with_switch;
2 |
3 | record Point(
4 | int x,
5 | int y) {
6 |
7 | }
8 |
9 | public class PatternMatchingSwitch {
10 |
11 | public void traditionalPrint(Object o) {
12 |
13 | switch (o) {
14 |
15 | case Point p -> System.out.printf("o is a position: %d/%d%n", p.x(), p.y());
16 | case String s -> System.out.printf("o is a string: %s%n", s);
17 | default -> System.out.printf("o is something else: %s%n", o);
18 | }
19 | }
20 |
21 | public void print(Object o) {
22 |
23 | switch (o) {
24 |
25 | case Point(int x, int y) -> System.out.printf("o is a position: %d/%d%n", x, y);
26 | case String s -> System.out.printf("o is a string: %s%n", s);
27 | default -> System.out.printf("o is something else: %s%n", o);
28 | }
29 | }
30 |
31 | public static void main(String[] args) {
32 |
33 | PatternMatchingSwitch pms = new PatternMatchingSwitch();
34 | pms.print(new Point(1, 2));
35 |
36 | pms.print("Hello");
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/scoped_values/Multiplier.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.scoped_values;
2 |
3 | import java.math.BigInteger;
4 |
5 | public class Multiplier {
6 |
7 | // Creates a new ScopedValue
8 | ScopedValue MULTIPLIER = ScopedValue.newInstance();
9 |
10 | public BigInteger multiply(BigInteger number) throws Exception {
11 | // invokes the squared method and saves the result in variable multiplied
12 | return ScopedValue.callWhere(MULTIPLIER, number, () -> squared());
13 | }
14 |
15 | public BigInteger squared() {
16 | BigInteger number = MULTIPLIER.get();
17 | return number.multiply(number);
18 | }
19 |
20 | public static void main(String[] args) throws Exception {
21 |
22 | var multiplier = new Multiplier();
23 |
24 | System.out.println(multiplier.multiply(BigInteger.valueOf(10)));
25 |
26 | System.out.println(multiplier.multiply(BigInteger.valueOf(11)));
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/scoped_values/ScopedValuesExample.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.scoped_values;
2 |
3 | public class ScopedValuesExample {
4 |
5 | private final static ScopedValue USER_ID = ScopedValue.newInstance();
6 |
7 | public void processWithUser(String sessionUserId) {
8 | // sessionUserId is bound to the ScopedValue USER_ID for the execution of the
9 | // runWhere method, the runWhere method invokes the processRequest method.
10 | ScopedValue.runWhere(USER_ID, sessionUserId, () -> processRequest());
11 | }
12 |
13 | private void processRequest() {
14 | System.out.println(USER_ID.get());
15 | }
16 |
17 | public static void main(String[] args) {
18 | ScopedValuesExample example = new ScopedValuesExample();
19 | example.processWithUser("123");
20 | }
21 |
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/string_templates/StringTemplates.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.string_templates;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.time.LocalTime;
6 | import java.time.format.DateTimeFormatter;
7 |
8 | import static java.lang.StringTemplate.STR;
9 |
10 | public class StringTemplates {
11 |
12 | String name = "Mahdi";
13 |
14 | @Test
15 | void testStringTemplates() {
16 | // let message = "Greetings {{ name }}!"; //TypeScript
17 |
18 | String name = "Mahdi";
19 |
20 | //concatenation
21 | String message = "Greetings " + name + "!";
22 | //String.format()
23 | message = String.format("Greetings %s!", name); //concatenation
24 | //StringBuilder
25 | message = new StringBuilder().append("Greetings ").append(name).append("!").toString();
26 |
27 | //variable
28 | message = STR."Greetings \{name}!";
29 |
30 | //method
31 | message = STR."Greetings \{getName()}!";
32 |
33 | //field
34 | message = STR."Greetings \{this.name}!";
35 |
36 | System.out.println(message);
37 |
38 | int x = 10, y = 20;
39 | String s = STR."\{x} + \{y} = \{x + y}"; //"10 + 20 = 30"
40 | System.out.println(s);
41 | }
42 |
43 | public String getName() {
44 | return name;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/structured_concurrency/CombinedWeatherInfoDemo.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.structured_concurrency;
2 |
3 | import java18_to_21.structured_concurrency.model.WeatherApiClient;
4 | import java18_to_21.structured_concurrency.model.WeatherInfo;
5 |
6 | import java.util.concurrent.ExecutionException;
7 |
8 | import static java18_to_21.structured_concurrency.util.SimpleLogger.log;
9 |
10 | public class CombinedWeatherInfoDemo {
11 |
12 | public static void main(String[] args) throws ExecutionException, InterruptedException {
13 | CombinedWeatherInfoDemo demo = new CombinedWeatherInfoDemo();
14 | WeatherInfo weatherInfo = demo.loadCombinedWeatherInfo();
15 | log("Result: " + weatherInfo);
16 | }
17 |
18 | WeatherInfo loadCombinedWeatherInfo() throws InterruptedException, ExecutionException {
19 | try (var scope = new CombinedWeatherInfoTaskScope()) {
20 | log("Forking tasks");
21 | scope.fork(() -> WeatherApiClient.loadWeatherInfo("provider-a"));
22 | scope.fork(() -> WeatherApiClient.loadWeatherInfo("provider-b"));
23 | scope.fork(() -> WeatherApiClient.loadWeatherInfo("provider-c"));
24 | scope.fork(() -> WeatherApiClient.loadWeatherInfo("provider-d"));
25 |
26 | log("Waiting for result combined from first two responses");
27 | scope.join();
28 |
29 | log("Retrieving result");
30 | WeatherInfo result = scope.result();
31 |
32 | log("Done");
33 | return result;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/structured_concurrency/CombinedWeatherInfoTaskScope.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.structured_concurrency;
2 |
3 | import java18_to_21.structured_concurrency.model.WeatherInfo;
4 |
5 | import java.util.concurrent.ExecutionException;
6 | import java.util.concurrent.StructuredTaskScope;
7 | import java.util.concurrent.atomic.AtomicReference;
8 |
9 | public class CombinedWeatherInfoTaskScope extends StructuredTaskScope {
10 |
11 | private final AtomicReference firstResult = new AtomicReference<>();
12 | private final AtomicReference secondResult = new AtomicReference<>();
13 | private final AtomicReference firstException = new AtomicReference<>();
14 |
15 | @Override
16 | protected void handleComplete(Subtask extends WeatherInfo> subtask) {
17 | if (subtask.state() == Subtask.State.SUCCESS) {
18 | WeatherInfo result = subtask.get();
19 | if (!firstResult.compareAndSet(null, result)) {
20 | if (secondResult.compareAndSet(null, result)) {
21 | shutdown();
22 | }
23 | }
24 | } else {
25 | firstException.compareAndSet(null, subtask.exception());
26 | }
27 | }
28 |
29 | public WeatherInfo result() throws ExecutionException {
30 | WeatherInfo firstWeatherInfo = firstResult.get();
31 | WeatherInfo secondWeatherInfo = secondResult.get();
32 | if (firstWeatherInfo != null && secondWeatherInfo != null) {
33 | return firstWeatherInfo.combineWith(secondWeatherInfo);
34 | }
35 |
36 | Throwable exception = firstException.get();
37 | if (exception != null) {
38 | throw new ExecutionException(exception);
39 | }
40 |
41 | throw new IllegalStateException("Neither two completed subtasks nor an exception");
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/structured_concurrency/ExecutorServiceDemo.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.structured_concurrency;
2 |
3 | import java18_to_21.structured_concurrency.model.Customer;
4 | import java18_to_21.structured_concurrency.model.Invoice;
5 | import java18_to_21.structured_concurrency.model.Order;
6 |
7 | import java.util.concurrent.ExecutionException;
8 | import java.util.concurrent.ExecutorService;
9 | import java.util.concurrent.Executors;
10 | import java.util.concurrent.Future;
11 |
12 | import static java18_to_21.structured_concurrency.model.Repository.loadCustomerFromDatabase;
13 | import static java18_to_21.structured_concurrency.model.Repository.loadInvoiceTemplateFromFile;
14 | import static java18_to_21.structured_concurrency.model.Repository.loadOrderFromOrderService;
15 | import static java18_to_21.structured_concurrency.util.SimpleLogger.log;
16 |
17 | public class ExecutorServiceDemo {
18 |
19 | public static void main(String[] args) throws ExecutionException, InterruptedException {
20 | ExecutorServiceDemo demo = new ExecutorServiceDemo();
21 | demo.createInvoice(10012, 61157, "en");
22 | demo.shutDown();
23 | }
24 |
25 | private final ExecutorService executor = Executors.newCachedThreadPool();
26 |
27 | Invoice createInvoice(int orderId, int customerId, String language)
28 | throws ExecutionException, InterruptedException {
29 | log("Submitting tasks");
30 |
31 | Future orderFuture = executor.submit(() -> loadOrderFromOrderService(orderId));
32 |
33 | Future customerFuture = executor.submit(() -> loadCustomerFromDatabase(customerId));
34 |
35 | Future invoiceTemplateFuture =
36 | executor.submit(() -> loadInvoiceTemplateFromFile(language));
37 |
38 | log("Waiting for order");
39 | Order order = orderFuture.get();
40 |
41 | log("Waiting for customer");
42 | Customer customer = customerFuture.get();
43 |
44 | log("Waiting for template");
45 | String invoiceTemplate = invoiceTemplateFuture.get();
46 |
47 | log("Generating invoice");
48 | Invoice invoice = Invoice.generate(order, customer, invoiceTemplate);
49 |
50 | log("Done");
51 | return invoice;
52 | }
53 |
54 | private void shutDown() {
55 | executor.shutdown();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/structured_concurrency/ShutdownOnFailureDemo.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.structured_concurrency;
2 |
3 | import java18_to_21.structured_concurrency.model.Customer;
4 | import java18_to_21.structured_concurrency.model.Invoice;
5 | import java18_to_21.structured_concurrency.model.Order;
6 |
7 | import java.util.concurrent.ExecutionException;
8 | import java.util.concurrent.StructuredTaskScope;
9 | import java.util.concurrent.StructuredTaskScope.Subtask;
10 |
11 | import static java18_to_21.structured_concurrency.model.Repository.loadCustomerFromDatabase;
12 | import static java18_to_21.structured_concurrency.model.Repository.loadInvoiceTemplateFromFile;
13 | import static java18_to_21.structured_concurrency.model.Repository.loadOrderFromOrderService;
14 | import static java18_to_21.structured_concurrency.util.SimpleLogger.log;
15 |
16 | public class ShutdownOnFailureDemo {
17 |
18 | public static void main(String[] args) throws ExecutionException, InterruptedException {
19 | ShutdownOnFailureDemo demo = new ShutdownOnFailureDemo();
20 | demo.createInvoice(10012, 61157, "en");
21 | }
22 |
23 | Invoice createInvoice(int orderId, int customerId, String language)
24 | throws InterruptedException, ExecutionException {
25 | try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
26 | log("Forking tasks");
27 | Subtask orderSubtask = scope.fork(() -> loadOrderFromOrderService(orderId));
28 |
29 | Subtask customerSubtask = scope.fork(() -> loadCustomerFromDatabase(customerId));
30 |
31 | Subtask invoiceTemplateSubtask =
32 | scope.fork(() -> loadInvoiceTemplateFromFile(language));
33 |
34 | log("Waiting for all tasks to finish or one to fail");
35 | scope.join();
36 | scope.throwIfFailed();
37 |
38 | log("Retrieving results");
39 | Order order = orderSubtask.get();
40 | Customer customer = customerSubtask.get();
41 | String invoiceTemplate = invoiceTemplateSubtask.get();
42 |
43 | log("Generating invoice");
44 | Invoice invoice = Invoice.generate(order, customer, invoiceTemplate);
45 |
46 | log("Done");
47 | return invoice;
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/structured_concurrency/ShutdownOnSuccessDemo.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.structured_concurrency;
2 |
3 | import java18_to_21.structured_concurrency.model.WeatherApiClient;
4 | import java18_to_21.structured_concurrency.model.WeatherInfo;
5 |
6 | import java.util.concurrent.ExecutionException;
7 | import java.util.concurrent.StructuredTaskScope;
8 |
9 | import static java18_to_21.structured_concurrency.util.SimpleLogger.log;
10 |
11 | public class ShutdownOnSuccessDemo {
12 |
13 | public static void main(String[] args) throws ExecutionException, InterruptedException {
14 | ShutdownOnSuccessDemo demo = new ShutdownOnSuccessDemo();
15 | demo.loadWeatherInfo();
16 | }
17 |
18 | WeatherInfo loadWeatherInfo() throws InterruptedException, ExecutionException {
19 | try (var scope = new StructuredTaskScope.ShutdownOnSuccess()) {
20 | log("Forking tasks");
21 | scope.fork(() -> WeatherApiClient.loadWeatherInfo("provider-a"));
22 | scope.fork(() -> WeatherApiClient.loadWeatherInfo("provider-b"));
23 | scope.fork(() -> WeatherApiClient.loadWeatherInfo("provider-c"));
24 |
25 | log("Waiting for one task to finish");
26 | scope.join();
27 |
28 | log("Retrieving result");
29 | WeatherInfo result = scope.result();
30 |
31 | log("Done");
32 | return result;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/structured_concurrency/StructuredConcurrencyDemo.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.structured_concurrency;
2 |
3 | import java18_to_21.structured_concurrency.model.Customer;
4 | import java18_to_21.structured_concurrency.model.Invoice;
5 | import java18_to_21.structured_concurrency.model.Order;
6 |
7 | import java.util.concurrent.ExecutionException;
8 | import java.util.concurrent.StructuredTaskScope;
9 | import java.util.concurrent.StructuredTaskScope.Subtask;
10 |
11 | import static java18_to_21.structured_concurrency.model.Repository.loadCustomerFromDatabase;
12 | import static java18_to_21.structured_concurrency.model.Repository.loadInvoiceTemplateFromFile;
13 | import static java18_to_21.structured_concurrency.model.Repository.loadOrderFromOrderService;
14 | import static java18_to_21.structured_concurrency.util.SimpleLogger.log;
15 |
16 | public class StructuredConcurrencyDemo {
17 |
18 | public static void main(String[] args) throws ExecutionException, InterruptedException {
19 | StructuredConcurrencyDemo demo = new StructuredConcurrencyDemo();
20 | demo.createInvoice(10012, 61157, "en");
21 | }
22 |
23 | Invoice createInvoice(int orderId, int customerId, String language) throws InterruptedException {
24 | try (var scope = new StructuredTaskScope<>()) {
25 | log("Forking tasks");
26 | Subtask orderSubtask = scope.fork(() -> loadOrderFromOrderService(orderId));
27 |
28 | Subtask customerSubtask = scope.fork(() -> loadCustomerFromDatabase(customerId));
29 |
30 | Subtask invoiceTemplateSubtask =
31 | scope.fork(() -> loadInvoiceTemplateFromFile(language));
32 |
33 | log("Waiting for all tasks to finish");
34 | scope.join();
35 |
36 | log("Retrieving results");
37 | Order order = orderSubtask.get();
38 | Customer customer = customerSubtask.get();
39 | String invoiceTemplate = invoiceTemplateSubtask.get();
40 |
41 | log("Generating invoice");
42 | Invoice invoice = Invoice.generate(order, customer, invoiceTemplate);
43 |
44 | log("Done");
45 | return invoice;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/structured_concurrency/StructuredConcurrencyWithScopedValueDemo.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.structured_concurrency;
2 |
3 | import java18_to_21.structured_concurrency.model.Customer;
4 | import java18_to_21.structured_concurrency.model.Invoice;
5 | import java18_to_21.structured_concurrency.model.Order;
6 |
7 | import java.util.concurrent.StructuredTaskScope;
8 | import java.util.concurrent.StructuredTaskScope.Subtask;
9 |
10 | import static java18_to_21.structured_concurrency.model.RepositoryWithScopedValue.loadCustomerFromDatabase;
11 | import static java18_to_21.structured_concurrency.model.RepositoryWithScopedValue.loadInvoiceTemplateFromFile;
12 | import static java18_to_21.structured_concurrency.model.RepositoryWithScopedValue.loadOrderFromOrderService;
13 | import static java18_to_21.structured_concurrency.util.SimpleLogger.log;
14 |
15 | public class StructuredConcurrencyWithScopedValueDemo {
16 |
17 | public static void main(String[] args) throws Exception {
18 | StructuredConcurrencyWithScopedValueDemo demo = new StructuredConcurrencyWithScopedValueDemo();
19 | demo.createInvoice(10012, 61157, "en");
20 | }
21 |
22 | public static final ScopedValue INVOICE_NUMBER = ScopedValue.newInstance();
23 |
24 | Invoice createInvoice(int orderId, int customerId, String language) throws Exception {
25 | return ScopedValue.callWhere(INVOICE_NUMBER, "2023-437",
26 | () -> {
27 | try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
28 | log("Forking tasks");
29 | Subtask orderSubtask = scope.fork(() -> loadOrderFromOrderService(orderId));
30 |
31 | Subtask customerSubtask =
32 | scope.fork(() -> loadCustomerFromDatabase(customerId));
33 |
34 | Subtask invoiceTemplateSubtask =
35 | scope.fork(() -> loadInvoiceTemplateFromFile(language));
36 |
37 | log("Waiting for all tasks to finish");
38 | scope.join();
39 | scope.throwIfFailed();
40 |
41 | log("Retrieving results");
42 | Order order = orderSubtask.get();
43 | Customer customer = customerSubtask.get();
44 | String invoiceTemplate = invoiceTemplateSubtask.get();
45 |
46 | log("Generating invoice");
47 | Invoice invoice = Invoice.generate(order, customer, invoiceTemplate);
48 |
49 | log("Done");
50 | return invoice;
51 | }
52 | });
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/structured_concurrency/model/Customer.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.structured_concurrency.model;
2 |
3 | public record Customer() {}
4 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/structured_concurrency/model/Invoice.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.structured_concurrency.model;
2 |
3 | public record Invoice() {
4 | public static Invoice generate(Order order, Customer customer, String invoiceTemplate) {
5 | return new Invoice();
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/structured_concurrency/model/Order.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.structured_concurrency.model;
2 |
3 | public record Order() {}
4 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/structured_concurrency/model/Repository.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.structured_concurrency.model;
2 |
3 | import java.util.concurrent.ThreadLocalRandom;
4 |
5 | import static java18_to_21.structured_concurrency.util.SimpleLogger.log;
6 |
7 | public final class Repository {
8 |
9 | private Repository() {}
10 |
11 | public static Order loadOrderFromOrderService(int orderId) throws InterruptedException {
12 | log("Loading order");
13 | try {
14 | Thread.sleep(ThreadLocalRandom.current().nextLong(500, 1000));
15 | } catch (InterruptedException e) {
16 | log("Order loading was interrupted");
17 | throw e;
18 | }
19 |
20 | if (ThreadLocalRandom.current().nextDouble() > 0.8) {
21 | log("Error loading order");
22 | throw new RuntimeException("Error loading order");
23 | }
24 |
25 | log("Finished loading order");
26 | return new Order();
27 | }
28 |
29 | public static Customer loadCustomerFromDatabase(int customerId) throws InterruptedException {
30 | log("Loading customer");
31 | try {
32 | Thread.sleep(ThreadLocalRandom.current().nextLong(500, 1000));
33 | } catch (InterruptedException e) {
34 | log("Customer loading was interrupted");
35 | throw e;
36 | }
37 |
38 | if (ThreadLocalRandom.current().nextDouble() > 0.8) {
39 | log("Error loading customer");
40 | throw new RuntimeException("Error loading customer");
41 | }
42 |
43 | log("Finished loading customer");
44 | return new Customer();
45 | }
46 |
47 | public static String loadInvoiceTemplateFromFile(String language) throws InterruptedException {
48 | log("Loading template");
49 | try {
50 | Thread.sleep(ThreadLocalRandom.current().nextLong(500, 1000));
51 | } catch (InterruptedException e) {
52 | log("Template loading was interrupted");
53 | throw e;
54 | }
55 |
56 | if (ThreadLocalRandom.current().nextDouble() > 0.8) {
57 | log("Error loading template");
58 | throw new RuntimeException("Error loading template");
59 | }
60 |
61 | log("Finished loading template");
62 | return "TEMPLATE";
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/structured_concurrency/model/RepositoryWithScopedValue.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.structured_concurrency.model;
2 |
3 | import java18_to_21.structured_concurrency.StructuredConcurrencyWithScopedValueDemo;
4 |
5 | import java.util.concurrent.ThreadLocalRandom;
6 |
7 | import static java18_to_21.structured_concurrency.util.SimpleLogger.log;
8 |
9 | public final class RepositoryWithScopedValue {
10 |
11 | private RepositoryWithScopedValue() {}
12 |
13 | public static Order loadOrderFromOrderService(int orderId) throws InterruptedException {
14 | String invoiceNumber = StructuredConcurrencyWithScopedValueDemo.INVOICE_NUMBER.get();
15 | log("Loading order for invoice " + invoiceNumber);
16 | Thread.sleep(ThreadLocalRandom.current().nextLong(500, 1000));
17 | log("Finished loading order");
18 | return new Order();
19 | }
20 |
21 | public static Customer loadCustomerFromDatabase(int customerId) throws InterruptedException {
22 | String invoiceNumber = StructuredConcurrencyWithScopedValueDemo.INVOICE_NUMBER.get();
23 | log("Loading customer for invoice " + invoiceNumber);
24 | Thread.sleep(ThreadLocalRandom.current().nextLong(500, 1000));
25 | log("Finished loading customer");
26 | return new Customer();
27 | }
28 |
29 | public static String loadInvoiceTemplateFromFile(String language) throws InterruptedException {
30 | String invoiceNumber = StructuredConcurrencyWithScopedValueDemo.INVOICE_NUMBER.get();
31 | log("Loading template for invoice " + invoiceNumber);
32 | Thread.sleep(ThreadLocalRandom.current().nextLong(500, 1000));
33 | log("Finished loading template");
34 | return "TEMPLATE";
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/structured_concurrency/model/WeatherApiClient.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.structured_concurrency.model;
2 |
3 | import java.util.concurrent.ThreadLocalRandom;
4 |
5 | import static java18_to_21.structured_concurrency.util.SimpleLogger.log;
6 |
7 | public final class WeatherApiClient {
8 |
9 | private WeatherApiClient() {}
10 |
11 | public static WeatherInfo loadWeatherInfo(String provider) throws InterruptedException {
12 | log("Loading weather info from provider " + provider);
13 | try {
14 | Thread.sleep(ThreadLocalRandom.current().nextLong(500, 1000));
15 | } catch (InterruptedException e) {
16 | log("Loading weather info from provider " + provider + " was interrupted");
17 | throw e;
18 | }
19 |
20 | if (ThreadLocalRandom.current().nextDouble() > 0.8) {
21 | log("Error loading weather info from provider " + provider);
22 | throw new RuntimeException("Error loading weather info from provider " + provider);
23 | }
24 |
25 | WeatherInfo weatherInfo = new WeatherInfo(ThreadLocalRandom.current().nextDouble(0.0, 45.0));
26 | log("Finished loading weather info from provider " + provider + ": " + weatherInfo);
27 | return weatherInfo;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/structured_concurrency/model/WeatherInfo.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.structured_concurrency.model;
2 |
3 | public record WeatherInfo(double temperature) {
4 | public WeatherInfo combineWith(WeatherInfo other) {
5 | return new WeatherInfo((this.temperature + other.temperature) / 2.0);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/structured_concurrency/util/SimpleLogger.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.structured_concurrency.util;
2 |
3 | public final class SimpleLogger {
4 |
5 | private SimpleLogger() {}
6 |
7 | public static void log(String description) {
8 | System.out.printf("[%s] %s%n", Thread.currentThread(), description);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/unnamed_classes_and_instance_main_methods/UnnamedClassesAndInstanceMainMethods.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | void main(String[] args) {
4 | System.out.println("Main method with args");
5 | }
6 |
7 | void main() {
8 | System.out.println("Main method without args");
9 | }
10 |
11 | //static void main(String[] args){
12 | // System.out.println("static Main method with args");
13 | //}
14 |
15 | //static void main() {
16 | // System.out.println("static Main method without args");
17 | //}
18 |
19 | //Rules
20 | // 1. package Statement is Not Allowed
21 | // 2. No Constructor is Allowed
22 | // 3. A main() Method must Exist
23 | // 4. Unnamed class cannot extend or implement (always final)
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/unnamed_patterns_and_variables/UnnamedPatternsAndVariables.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.unnamed_patterns_and_variables;
2 |
3 | public class UnnamedPatternsAndVariables {
4 |
5 | public static void main(String[] args) {
6 |
7 | String s = "Hello, World!";
8 |
9 | try {
10 | int i = Integer.parseInt(s);
11 | //use i
12 | } catch (NumberFormatException _) {
13 | System.out.println("Invalid number: " + s);
14 | }
15 |
16 | /*Object obj = s;
17 |
18 | switch (obj) {
19 |
20 | case Byte, Short, Integer, Long _ -> System.out.println("Input is a number");
21 | case Float, Double _ -> System.out.println("Input is a floating-point number");
22 |
23 | case String _ -> System.out.println("Input is a string");
24 |
25 | default -> System.out.println("Object type not expected");
26 | }*/
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java18_to_21/virtual_thread/CreateVirtualThread.java:
--------------------------------------------------------------------------------
1 | package java18_to_21.virtual_thread;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.concurrent.Callable;
6 | import java.util.concurrent.CompletableFuture;
7 | import java.util.concurrent.ExecutionException;
8 | import java.util.concurrent.ExecutorService;
9 | import java.util.concurrent.Executors;
10 | import java.util.concurrent.Future;
11 |
12 | public class CreateVirtualThread {
13 |
14 | public static void main(String[] args) throws InterruptedException, ExecutionException {
15 |
16 | // Traditional 1: java 1.0 - Thread class
17 | Thread thread1 = new Thread() {
18 |
19 | public void run() {
20 | System.out.println(Thread.currentThread());
21 | }
22 | };
23 | thread1.start();
24 |
25 | // Traditional 2: java 1.0 - Runnable interface
26 | Runnable runnable2 =
27 | new Runnable() {
28 | public void run() {
29 | System.out.println(Thread.currentThread());
30 | }
31 | };
32 |
33 | runnable2.run();
34 |
35 | // Traditional 3: java 1.8 - Runnable interface with lambda and functional interface
36 | Runnable runnable3 =
37 | () -> System.out.println("Lambda Runnable running");
38 |
39 | runnable3.run();
40 |
41 | // ExecuteService Interface: java 1.8 - Execute multiple threads in a single task queue
42 | long start = System.currentTimeMillis();
43 | try (ExecutorService singleTaskQueueExecutor = Executors.newFixedThreadPool(3)) {
44 | List finalResultList = new ArrayList<>();
45 | for (int i = 0; i < 10; i++) {
46 | Future futureResult = singleTaskQueueExecutor.submit(new Add(10, 20)); // 2
47 | Integer intermediateResult = futureResult.get(); // blocking // 3
48 | Future finalResult = singleTaskQueueExecutor.submit(new Multiply(intermediateResult)); // 4
49 | finalResultList.add(i + " " + finalResult.get()); // blocking //5
50 | }
51 | singleTaskQueueExecutor.shutdown();
52 | System.out.println("Total time using ExecutorService and future: " + (System.currentTimeMillis() - start));
53 | }
54 |
55 | // CompletableFuture: java 1.8 - Execute multiple threads in a multiple task queue
56 | start = System.currentTimeMillis();
57 | ExecutorService executor = Executors.newFixedThreadPool(3);
58 | List> finalResultList = new ArrayList<>();
59 |
60 | for (int i = 0; i < 10; i++) {
61 | CompletableFuture voidCompletableFuture = CompletableFuture
62 | .supplyAsync(() -> add(10, 20), executor)
63 | .thenApplyAsync(CreateVirtualThread::multiply, executor);
64 |
65 | finalResultList.add(voidCompletableFuture);
66 | }
67 |
68 | for (CompletableFuture future : finalResultList) {
69 | future.get();
70 | }
71 | executor.shutdown();
72 | System.out.println("Total time using ExecutorService and CompletableFuture: " + (System.currentTimeMillis() - start));
73 |
74 | // Java 21 ----------------------------------------------------------------
75 |
76 | /**
77 | *
78 | * Definition:
79 | * Virtual threads are lightweight threads that dramatically reduce the effort of writing,
80 | * maintaining, and observing high-throughput concurrent applications.
81 | *
82 | * Note: Virtual Thread using Platform thread resources
83 | *
84 | * Advantages of Java virtual threads *
85 | 1. Improves application availability
86 |
87 | 2. Improves application throughput
88 |
89 | 3. Reduces ‘OutOfMemoryError: unable to create new native thread’
90 |
91 | 4. Reduces application memory consumption
92 |
93 | 5. Improves code quality
94 |
95 | 6. 100% compatible with Platform Threads
96 | */
97 |
98 | // Platform Thread
99 | var platformThread = Thread.ofPlatform().unstarted(() -> System.out.println(Thread.currentThread()));
100 |
101 | platformThread.start();
102 | platformThread.join();
103 |
104 | System.out.println("Class: " + platformThread.getClass());
105 |
106 | // Virtual Thread
107 | var virtualThread = Thread.ofVirtual().unstarted(() -> System.out.println(Thread.currentThread()));
108 |
109 | virtualThread.start();
110 | virtualThread.join();
111 |
112 | System.out.println("Class: " + virtualThread.getClass());
113 |
114 | // 2
115 | Runnable runnable = () -> System.out.println(Thread.currentThread());
116 | Thread.startVirtualThread(runnable);
117 |
118 | // 3
119 | try (var virtualThreadPerTaskExecutor = Executors.newVirtualThreadPerTaskExecutor()) {
120 |
121 | virtualThreadPerTaskExecutor.submit(runnable);
122 | virtualThreadPerTaskExecutor.submit(runnable);
123 | }
124 | }
125 |
126 | static class Add implements Callable {
127 |
128 | int a;
129 | int b;
130 |
131 | Add(int a, int b) {
132 | this.a = a;
133 | this.b = b;
134 | }
135 |
136 | @Override
137 | public Integer call() throws Exception {
138 | return a + b;
139 | }
140 |
141 | }
142 |
143 | static class Multiply implements Callable {
144 |
145 | int result;
146 |
147 | Multiply(int result) throws InterruptedException {
148 | Thread.sleep(100);
149 | this.result = result;
150 | }
151 |
152 | @Override
153 | public Integer call() throws Exception {
154 | result = result * 10;
155 | System.out.println(Thread.currentThread().getName() + " " + result);
156 | return result;
157 | }
158 |
159 | }
160 |
161 | public static Integer add(int a, int b) {
162 | return a + b;
163 | }
164 |
165 | public static Integer multiply(int a) {
166 |
167 |
168 | a = a * 10;
169 | try {
170 | Thread.sleep(100);
171 | }
172 | catch (InterruptedException _) {
173 | }
174 | System.out.println(Thread.currentThread().getName() + " " + a);
175 | return a;
176 | }
177 |
178 | }
179 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/instance_of/AbstractFile.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.instance_of;
2 |
3 | public abstract class AbstractFile {
4 | }
5 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/instance_of/InstanceOfExample.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.instance_of;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | public class InstanceOfExample {
6 |
7 | @Test
8 | void instanceOfExample() {
9 |
10 | AbstractFile abstractFile = new MusicFile();
11 | useInstanceOf(abstractFile);
12 | }
13 |
14 | private void useInstanceOf(AbstractFile abstractFile) {
15 |
16 | // Traditional
17 | if (abstractFile instanceof MusicFile) {
18 |
19 | ((MusicFile) abstractFile).playMusic();
20 | }
21 |
22 | // New Way
23 | if (abstractFile instanceof MusicFile musicFile) {
24 |
25 | musicFile.playMusic();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/instance_of/MusicFile.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.instance_of;
2 |
3 | public class MusicFile extends AbstractFile {
4 |
5 | public void playMusic() {
6 |
7 | System.out.println("Playing Music");
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/instance_of/VideoFile.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.instance_of;
2 |
3 | public class VideoFile extends AbstractFile {
4 |
5 | public void playVideo() {
6 |
7 | System.out.println("Playing Video");
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/local_variable_type_inference/VarExample.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.local_variable_type_inference;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | public class VarExample {
9 |
10 |
11 | // var name = "Mehdi";
12 |
13 | int i = 10;
14 |
15 | @Test
16 | public void varExample() {
17 |
18 | // Java 5
19 | List names = new ArrayList();
20 |
21 | // Java 7
22 | List names2 = new ArrayList<>();
23 |
24 | // local variable type inference - Java 10
25 | var names3 = new ArrayList();
26 |
27 | var i = 10;
28 | var name = "Lewandowski"; // String pool
29 |
30 | var anotherName = new String("Neuer");
31 |
32 | // Backward compatibility
33 | var var = "Messi";
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/new_NPE/Person.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.new_NPE;
2 |
3 | public class Person {
4 |
5 | private String name;
6 | private int age;
7 |
8 | public Person(String name, int age) {
9 | this.name = name;
10 | this.age = age;
11 | }
12 |
13 | public String getName() {
14 | return name;
15 | }
16 |
17 | public int getAge() {
18 | return age;
19 | }
20 | }
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/new_NPE/new_npe.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.new_NPE;
2 |
3 | public class new_npe {
4 |
5 | public static void main(String[] args) {
6 |
7 | Person person1 = new Person("Mehdi", 34);
8 | System.out.println(person1.getName().toLowerCase());
9 |
10 | // Person person2 = new Person(null, 34);
11 | // System.out.println(person2.getName().toLowerCase());
12 | //
13 | Person person3 = null;
14 | System.out.println(person3.getName().toLowerCase());
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/new_switch/EnhanceSwitchStatement.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.new_switch;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | public class EnhanceSwitchStatement {
6 |
7 | @Test
8 | public void SwitchExample() {
9 | //String player = "Lewandowski";
10 | String player = "Messi";
11 |
12 | runSwitch(player);
13 | }
14 |
15 | private void runSwitch(String player) {
16 |
17 | switch (player) {
18 | case "Muller", "Neuer" -> System.out.println("Bayern");
19 | case "Messi" -> System.out.println("Miami");
20 | case "Ronaldo" -> System.out.println("Al Nasr");
21 | default -> System.out.println("i dont know this player.");
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/new_switch/TraditionalSwitch.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.new_switch;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | public class TraditionalSwitch {
6 |
7 | @Test
8 | public void SwitchExample() {
9 |
10 | String player = "Messi";
11 |
12 | runSwitch(player);
13 |
14 | }
15 |
16 | private void runSwitch(String player) {
17 |
18 | switch (player) {
19 |
20 | case "Muller":
21 | case "Neuer":
22 | System.out.println("Bayern");
23 | break;
24 | case "Messi":
25 | System.out.println("Miami");
26 | break;
27 | case "Ronaldo":
28 | System.out.println("Al Nassr");
29 | break;
30 | default:
31 | System.out.println("i dont know this player.");
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/of_for_collections/CollectionsExample.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.of_for_collections;
2 |
3 | import java.util.*;
4 |
5 | public class CollectionsExample {
6 |
7 | public void CollectionsExample () {
8 |
9 | //Traditional
10 |
11 | Set namesSet = new HashSet<>();
12 | namesSet.add("Mehdi");
13 | namesSet.add("Mohammad");
14 |
15 | HashMap countriesMap = new HashMap<>();
16 | countriesMap.put("IRAN", "Tehran");
17 | countriesMap.put("IRAN", "Ahvaz");
18 |
19 | ArrayList namesList = new ArrayList<>();
20 | namesList.add("Zahra");
21 | namesList.add("Fatemeh");
22 |
23 |
24 | List namesList2 = Arrays.asList("Taghi", "Naghi");
25 |
26 | //New
27 |
28 | List names = List.of("Mehdi", "Mohammad");
29 | Set newSet = Set.of("Mehdi", "Mohammad");
30 | Map countries = Map.of("IRAN", "Tehran", "IRAN", "Ahvaz");
31 | Map countries2 = Map.ofEntries(Map.entry("IRAN", "Tehran"), Map.entry("IRAN", "Tehran"));
32 |
33 |
34 |
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/records/Person.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.records;
2 |
3 | import java.util.Objects;
4 |
5 | public class Person {
6 |
7 | private final String name;
8 | private final Integer age;
9 |
10 | public Person(String name, Integer age) {
11 | this.name = name;
12 | this.age = age;
13 | }
14 |
15 | public String getName() {
16 | return name;
17 | }
18 |
19 | public Integer getAge() {
20 | return age;
21 | }
22 |
23 | @Override
24 | public boolean equals(Object o) {
25 | if (this == o) return true;
26 | if (o == null || getClass() != o.getClass()) return false;
27 | Person person = (Person) o;
28 | return Objects.equals(name, person.name) && Objects.equals(age, person.age);
29 | }
30 |
31 | @Override
32 | public int hashCode() {
33 | return Objects.hash(name, age);
34 | }
35 |
36 | @Override
37 | public String toString() {
38 | return "Person{" +
39 | "name='" + name + '\'' +
40 | ", age=" + age +
41 | '}';
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/records/PersonLombok.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.records;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class PersonLombok {
7 |
8 | private final String name;
9 | private final Integer age;
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/records/PersonRecord.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.records;
2 |
3 | public record PersonRecord(String name, int age) {
4 | }
5 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/records/Records.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.records;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | public class Records {
6 |
7 | @Test
8 | public void recordsExample() {
9 |
10 | Person person1 = new Person("Mehdi Tilab", 34);
11 | PersonRecord person2 = new PersonRecord("Mehdi Tilab", 34);
12 |
13 | System.out.println(person1.getAge());
14 | System.out.println(person2.age());
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/sealed_classes/AudioFile.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.sealed_classes;
2 |
3 | public sealed abstract class AudioFile permits MP3File {
4 | }
5 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/sealed_classes/Drive.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.sealed_classes;
2 |
3 | public sealed interface Drive permits HddDrive {
4 | }
5 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/sealed_classes/ExtendedMP3File.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.sealed_classes;
2 |
3 | public final class ExtendedMP3File extends MP3File {
4 | }
5 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/sealed_classes/HddDrive.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.sealed_classes;
2 |
3 | public non-sealed interface HddDrive extends Drive {
4 | }
5 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/sealed_classes/MP3File.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.sealed_classes;
2 |
3 | public sealed class MP3File extends AudioFile permits ExtendedMP3File {
4 | }
5 |
--------------------------------------------------------------------------------
/java17-new-features-maven/src/test/java/java9_to_17/text_blocks/TextBlocks.java:
--------------------------------------------------------------------------------
1 | package java9_to_17.text_blocks;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | public class TextBlocks {
6 |
7 | @Test
8 | public void oldMultilineTexts() {
9 |
10 | String json = "{\n" +
11 | " \"glossary\": {\n" +
12 | " \"title\": \"example glossary\",\n" +
13 | "\t\t\"GlossDiv\": {\n" +
14 | " \"title\": \"S\",\n" +
15 | "\t\t\t\"GlossList\": {\n" +
16 | " \"GlossEntry\": {\n" +
17 | " \"ID\": \"SGML\",\n" +
18 | "\t\t\t\t\t\"SortAs\": \"SGML\",\n" +
19 | "\t\t\t\t\t\"GlossTerm\": \"Standard Generalized Markup Language\",\n" +
20 | "\t\t\t\t\t\"Acronym\": \"SGML\",\n" +
21 | "\t\t\t\t\t\"Abbrev\": \"ISO 8879:1986\",\n" +
22 | "\t\t\t\t\t\"GlossDef\": {\n" +
23 | " \"para\": \"A meta-markup language, used to create markup languages such as DocBook.\",\n" +
24 | "\t\t\t\t\t\t\"GlossSeeAlso\": [\"GML\", \"XML\"]\n" +
25 | " },\n" +
26 | "\t\t\t\t\t\"GlossSee\": \"markup\"\n" +
27 | " }\n" +
28 | " }\n" +
29 | " }\n" +
30 | " }\n" +
31 | "}";
32 |
33 | System.out.println(json);
34 | }
35 |
36 | @Test
37 | public void textBlocks() {
38 |
39 | String json = """
40 | {
41 | "glossary": {
42 | "title": "example glossary",
43 | "GlossDiv": {
44 | "title": "S",
45 | "GlossList": {
46 | "GlossEntry": {
47 | "ID": "SGML",
48 | "SortAs": "SGML",
49 | "GlossTerm": "Standard Generalized Markup Language",
50 | "Acronym": "SGML",
51 | "Abbrev": "ISO 8879:1986",
52 | "GlossDef": {
53 | "para": "A meta-markup language, used to create markup languages such as DocBook.",
54 | "GlossSeeAlso": ["GML", "XML"]
55 | },
56 | "GlossSee": "markup"
57 | }
58 | }
59 | }
60 | }
61 | }""";
62 |
63 | System.out.println(json);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/instance_of/AbstractFile.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/instance_of/AbstractFile.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/instance_of/InstanceOfExample.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/instance_of/InstanceOfExample.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/instance_of/MusicFile.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/instance_of/MusicFile.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/instance_of/VideoFile.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/instance_of/VideoFile.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/local_variable_type_inference/VarExample.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/local_variable_type_inference/VarExample.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/new_NPE/Person.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/new_NPE/Person.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/new_NPE/new_npe.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/new_NPE/new_npe.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/new_switch/EnhanceSwitchStatement.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/new_switch/EnhanceSwitchStatement.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/new_switch/TraditionalSwitch.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/new_switch/TraditionalSwitch.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/of_for_collections/CollectionsExample.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/of_for_collections/CollectionsExample.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/records/Person.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/records/Person.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/records/PersonRecord.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/records/PersonRecord.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/records/Records.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/records/Records.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/sealed_classes/AudioFile.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/sealed_classes/AudioFile.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/sealed_classes/Drive.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/sealed_classes/Drive.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/sealed_classes/ExtendedMP3File.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/sealed_classes/ExtendedMP3File.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/sealed_classes/HddDrive.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/sealed_classes/HddDrive.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/sealed_classes/MP3File.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/sealed_classes/MP3File.class
--------------------------------------------------------------------------------
/java17-new-features-maven/target/test-classes/text_blocks/TextBlocks.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/java17-new-features-maven/target/test-classes/text_blocks/TextBlocks.class
--------------------------------------------------------------------------------
/jdk-22/jdk-22.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/jdk-22/src/StreamGatherers.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 | import java.util.List;
3 | import java.util.stream.Collector;
4 | import java.util.stream.Collectors;
5 | import java.util.stream.Gatherers;
6 | import java.util.stream.Stream;
7 |
8 | public class StreamGatherers {
9 | public static void main(String[] args) {
10 |
11 | findGroupsOfThree(10, 3);
12 |
13 | findGroupsOfThreeWithGatherer(10, 3);
14 | }
15 |
16 | // Traditional Example
17 | public static ArrayList> findGroupsOfThree(long fixed_size, int grouping) {
18 |
19 | return Stream.iterate(0, i -> i + 1)
20 | .limit(fixed_size * grouping)
21 | .collect(Collector.of(
22 | () -> new ArrayList<>(),
23 | (groups, element) -> {
24 | if (groups.isEmpty() || groups.getLast().size() == fixed_size) {
25 | var current = new ArrayList();
26 | current.add(element);
27 | groups.addLast(current);
28 | } else {
29 | groups.getLast().add(element);
30 | }
31 | },
32 | (left, right) -> {
33 | throw new UnsupportedOperationException("Cannot be parallelized");
34 | }
35 | ));
36 | }
37 |
38 | // New Example using Gatherer interface
39 | public static List> findGroupsOfThreeWithGatherer(long fixed_size, int grouping) {
40 |
41 | return Stream.iterate(0, i -> i + 1)
42 | .gather(Gatherers.windowFixed((int) fixed_size))
43 | .limit(grouping)
44 | .collect(Collectors.toList());
45 | }
46 | }
--------------------------------------------------------------------------------
/resources/Java 8 - 18 New features.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/resources/Java 8 - 18 New features.pptx
--------------------------------------------------------------------------------
/resources/Java new features - Presenter notes.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/resources/Java new features - Presenter notes.docx
--------------------------------------------------------------------------------
/resources/Pictures.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/resources/Pictures.png
--------------------------------------------------------------------------------
/resources/java-release-plan.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/resources/java-release-plan.JPG
--------------------------------------------------------------------------------
/resources/poster.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/resources/poster.png
--------------------------------------------------------------------------------
/resources/poster.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-tilab/java-new-features/2613c69125fb6b4dc164fbadb28a029610325df3/resources/poster.psd
--------------------------------------------------------------------------------
/resources/some-notes-to-compile-new-JDK-21-RC-version-features.txt:
--------------------------------------------------------------------------------
1 | Some notes for compile:
2 |
3 | C:\DevTools\jdk\jdk-21\bin\javac.exe -Xlint:preview --enable-preview -source 21 UnnamedPatternsAndVariables.java
4 | C:\DevTools\jdk\jdk-21\bin\java.exe --enable-preview --source 21 UnnamedPatternsAndVariables.java
5 |
6 | C:\DevTools\jdk\jdk-21\bin\javac.exe -Xlint:preview --enable-preview -source 21 UnnamedClassesAndInstanceMainMethods.java
7 | C:\DevTools\jdk\jdk-21\bin\java.exe --enable-preview --source 21 UnnamedClassesAndInstanceMainMethods.java
--------------------------------------------------------------------------------