no safe harbor statement. However, I am not authorized to tell you any non public information or if I know any :) Some of the material in this presentation may appear in our upcoming certification books.
study materials Option 2: 1. Study from a Java 17 study guide 2. Read about Java 18-21 features 3. Focus on edge cases 4. Do any practice questions you can find This talk helps with option 2. Or if you just want to learn
threads 95% or higher Pattern matching for switch 95% or higher Record patterns 95% or higher Sequenced Collections 10-30% Other topics + open Q&A less than 5%
and call REST API Proceed CPU Network Still bored… Still waiting for a reply Platform Thread 1 Platform Thread n Do calculation and call REST API Send to threads
calculation and call REST API Proceed CPU Network Thanks for the work! Me too! Platform Thread 1 Platform Thread n Send to threads Virtual Thread t Do calculation and call REST API Virtual Thread t+1 Do calculation and call REST API Virtual Thread x Do calculation and call REST API
create/with a virtual thread? (more than 1 is correct) A. Executors.newVirtualThread() B. Executors.newVirtualThreadExecutor() C. Executors.newVirtualThreadPerTaskExecutor() D. new VirtualThread() E. Thread.ofVirtual() F. Thread.ofVirtualThread() 21
create/with a virtual thread? (more than 1 is correct) A. Executors.newVirtualThread() B. Executors.newVirtualThreadExecutor() C. Executors.newVirtualThreadPerTaskExecutor() D. new VirtualThread() E. Thread.ofVirtual() F. Thread.ofVirtualThread() 21 C, E
create/with a platform thread? (more than 1 is correct) A. Executors.newCachedThreadPool() B. Executors.newPlatformThreadPool() C. Executors.newPlatformThreadPerTaskExecutor() D. new Thread() E. new PlatformThread() F. Thread.ofPlatform() 21
create/with a virtual thread? (more than 1 is correct) A. Executors.newCachedThreadPool() B. Executors.newPlatformThreadPool() C. Executors.newPlatformThreadPerTaskExecutor() D. new Thread() E. new PlatformThread() F. Thread.ofPlatform() 21 A, D, F
at line v1? try (var service = Executors.newVirtualThreadPerTaskExecutor()) { service.submit(() -> doStuff()); } // line v1 A. doStuff() may be running B. doStuff() was killed C. doStuff() completed D. None of the above 21
at line v1? try (var service = Executors.newVirtualThreadPerTaskExecutor()) { service.submit(() -> doStuff()); } // line v1 A. doStuff() may be running B. doStuff() was killed C. doStuff() completed D. None of the above 21 C
case null -> ""; case Integer i when i >= 21 -> "can gamble"; case Integer i -> "too young to gamble"; case String s when "poker".equals(s) -> "table game"; case String s when "craps".equals(s) -> "table game"; case String s -> "other game"; default -> throw new IllegalArgumentException("unexpected type"); }; guard clause pattern variable null allowed Still Null Pointer if don’t specify case null
null -> ""; case Integer i -> "too young to gamble"; case Integer i when i >= 21 -> "can gamble”; // DOES NOT COMPILE case String s -> "other game"; default -> throw new IllegalArgumentException("unexpected type"); }; Order like catching exceptions!
SPADE; } String symbol(Suit suit) { return switch (suit) { case HEART -> "♥"; case Suit.DIAMOND -> "♦"; case CLUB -> "♣"; case Suit.SPADE -> "♠"; }; } Fails compilation if miss one since no default
boolean check ; switch (age) { case Integer i when i <= 21 : check = true; // DOES NOT COMPILE case Integer i when i <= 40 : check = true; default : check = false; } return check; } Can’t use pattern variable if fall thru
# lines do you need to remove to make this code compile? double odds(Object obj) { return switch (obj) { case String s -> throw new IllegalArgumentException("unknown game"); case String s when "blackjack".equals(s) -> .05; case String s when "baccarat".equals(s) -> .12; case Object o -> throw new IllegalArgumentException("unknown game"); default -> throw new IllegalArgumentException("known game"); }; } A. 0 B. 1 21 C. 2 D. 3
do you need to remove to make this code compile? double odds(Object obj) { return switch (obj) { case String s -> throw new IllegalArgumentException("unknown game"); case String s when "blackjack".equals(s) -> .05; case String s when "baccarat".equals(s) -> .12; case Object o -> throw new IllegalArgumentException("unknown game"); default -> throw new IllegalArgumentException("known game"); }; } A. 0 B. 1 21 C. 2 D. 3 C String s & Object o or default
results of odds(“slots”) and odds(null)? double odds(String str) { return switch (str) { case String s when "blackjack".equals(s) -> .05; case String s when "baccarat".equals(s) -> .12; case String s -> throw new IllegalArgumentException("unknown game"); }; } A. IllegalArgumentException B. NullPointerException 21 C. .05 D. Does not compile
results of odds(“slots”) and odds(null)? double odds(String str) { return switch (str) { case String s when "blackjack".equals(s) -> .05; case String s when "baccarat".equals(s) -> .12; case String s -> throw new IllegalArgumentException("unknown game"); }; } A. IllegalArgumentException B. NullPointerException 21 C. .05 D. Does not compile A, B
results of odds("slots") and odds(null)? double odds(String str) { return switch (str) { case String s when "blackjack".equals(s) -> .05; case String s when "baccarat".equals(s) -> .12; case String s -> throw new IllegalArgumentException("unknown game”); case null -> 0.0; }; } A. IllegalArgumentException B. NullPointerException 21 C. 0.0 D. Does not compile
results of odds("slots") and odds(null)? double odds(String str) { return switch (str) { case String s when "blackjack".equals(s) -> .05; case String s when "baccarat".equals(s) -> .12; case String s -> throw new IllegalArgumentException("unknown game”); case null -> 0.0; }; } A. IllegalArgumentException B. NullPointerException 21 C. 0.0 D. Does not compile A, C
(str) { case "heart" -> System.out.println("heart"); } Card card = new Card(Suit.HEART, Rank.NUM_2); switch (card) { case Card(Suit suit, Rank rank) when suit == Suit.HEART -> System.out.println("Heart"); case Card c -> System.out.println("other"); } 21 Must be exhaustive if using “when”
(more than one) A. if (card instanceof Card (Suit suit, Rank rank)) { } B. if (card instanceof Card (var suit, var rank)) { } C. if (card instanceof Card c) { } D. if (card instanceof Card c.suit, c.rank) { } 21
(more than one) A. if (card instanceof Card (Suit suit, Rank rank)) { } B. if (card instanceof Card (var suit, var rank)) { } C. if (card instanceof Card c) { } D. if (card instanceof Card c.suit, c.rank) { } 21 A, B, C
of the following? Card card = new Card(Suit.HEART, Rank.NUM_2); switch (card) { case Card(var suit, var rank) when suit == Suit.HEART && rank == Rank.ACE -> System.out.println("Ace of Hearts"); case Card(var suit, var rank) when suit == Suit.HEART -> System.out.println("Hearts"); } A. Ace of Hearts B. Hearts 21 C. Null Pointer D. Does not compile
of the following? Card card = new Card(Suit.HEART, Rank.NUM_2); switch (card) { case Card(var suit, var rank) when suit == Suit.HEART && rank == Rank.ACE -> System.out.println("Ace of Hearts"); case Card(var suit, var rank) when suit == Suit.HEART -> System.out.println("Hearts"); } A. Ace of Hearts B. Hearts 21 C. Null Pointer D. Does not compile D (no case Card)
of the following? Card card = new Card(Suit.HEART, Rank.NUM_2); switch (card) { case Card(var suit, var rank) when suit == Suit.HEART && rank == Rank.ACE -> System.out.println("Ace of Hearts"); case Card(var suit, var rank) when suit == Suit.HEART -> System.out.println("Hearts"); case Card c -> System.out.println("other"); } 21 A. Ace of Hearts B. Hearts C. Null Pointer D. Does not compile
of the following? Card card = new Card(Suit.HEART, Rank.NUM_2); switch (card) { case Card(var suit, var rank) when suit == Suit.HEART && rank == Rank.ACE -> System.out.println("Ace of Hearts"); case Card(var suit, var rank) when suit == Suit.HEART -> System.out.println("Hearts"); case Card c -> System.out.println("other"); } 21 A. Ace of Hearts B. Hearts C. Null Pointer D. Does not compile B
suit, Rank rank), how many of these compile? case Card(var rank, var suit) when suit == Suit.HEART case Card(Rank rank, Suit suit) when suit == Suit.HEART case Card(Rank rank, var suit) when suit == Suit.HEART case Card(var suit, var rank) when suit == Suit.HEART case Card(Suit suit, Rank rank) when suit == Suit.HEART case Card(var suit, Rank rank) when suit == Suit.HEART A. 0 B. 1 C. 2 21 D. 3 E. 4 F. 5
suit, Rank rank), how many of these compile? case Card(var rank, var suit) when suit == Suit.HEART case Card(Rank rank, Suit suit) when suit == Suit.HEART case Card(Rank rank, var suit) when suit == Suit.HEART case Card(var suit, var rank) when suit == Suit.HEART case Card(Suit suit, Rank rank) when suit == Suit.HEART case Card(var suit, Rank rank) when suit == Suit.HEART A. 0 B. 1 21 C. 2 D. 3 D (last three)
HashSet<>(); set.add("Donald"); set.add("Mickey"); set.add("Minnie"); System.out.println(set.iterator().next()); Encounter order undefined(but Mickey on my machine) 21
compile? SequencedCollection<Integer> seq1 = new HashSet<>(); SequencedSet<Integer> seq2 = new HashSet<>(); SequencedMap<Integer> seq3 = new HashSet<>(); SequencedCollection<Integer> seq4 = new TreeSet<>(); SequencedSet<Integer> seq5 = new TreeSet<>(); SequencedMap<Integer> seq6 = new TreeSet<>(); A. One B. Two C. Three D. Four 21
compile? SequencedCollection<Integer> seq1 = new HashSet<>(); SequencedSet<Integer> seq2 = new HashSet<>(); SequencedMap<Integer> seq3 = new HashSet<>(); SequencedCollection<Integer> seq4 = new TreeSet<>(); SequencedSet<Integer> seq5 = new TreeSet<>(); SequencedMap<Integer> seq6 = new TreeSet<>(); A. One B. Two C. Three D. Four B (seq4 and seq 5) 21
• UTF-8 is the default character set when reading a file • StringBuilder/StringBuffer have a repeat method • String.indexOf(charOrStr, beginIndex, endIndex) • String.splitWithDelimitters(regex, limit) • Finalization deprecated for removal