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%
a virtual thread? (more than one is correct) A. Executors.newVirtualThread() B. Executors.newVirtualThreadExecutor() C. Executors.newVirtualThreadPerTaskExecutor() D. new VirtualThread() E. Thread.ofVirtual() F. Thread.ofVirtualThread() 21
virtual thread? (pick two) A. Executors.newVirtualThread() B. Executors.newVirtualThreadExecutor() C. Executors.newVirtualThreadPerTaskExecutor() D. new VirtualThread() E. Thread.ofVirtual() F. Thread.ofVirtualThread() 21 C, E
a platform thread? (more than one is correct) A. Executors.newCachedThreadPool() B. Executors.newPlatformThreadPool() C. Executors.newPlatformThreadPerTaskExecutor() D. new Thread() E. new PlatformThread() F. Thread.ofPlatform() 21
a platform thread? (more than one 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
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 Deck.DIAMOND -> "♦"; case CLUB -> "♣"; case Deck.SPADE -> "♠"; }; } Fails compilation if miss one since no default
boolean check ; switch (age) { case Integer i when i <= 21 : check = true; break; // DOES NOT COMPILE case Integer i when i <= 40 : check = true; break; default : check = false; break; } return check; } Can’t use pattern variable if fall thru
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
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 A (seq4 and seq 5) 21
• UTF-8 is the default character set when reading a file • StringBuilder/StringBuffer have a repeat method • String has new indexOf and splitWithDelimitters methods • Code snippets in JavaDoc • Finalization deprecated for removal