Carlos M.’s Post

5 Java 21 features you use at work but can't explain on the exam Maybe you can use them every day. But could you pass a 50-question, 120-minute OCP exam on them? 1. Virtual Threads At work: Executors.newVirtualThreadPerTaskExecutor() and it works. Exam trap: What happens inside a synchronized block? → The virtual thread becomes pinned to the carrier thread, limiting scalability. → Prefer ReentrantLock or avoid long blocking operations inside synchronized sections. 2. Records At work: record TradeDTO(String id, BigDecimal price), clean DTOs. Exam trap: → Can a record extend a class? ❌ No (implicitly extends java.lang.Record) → Implement interfaces? ✅ Yes → Add instance fields? ❌ No (only components define state, static fields allowed) 3. Sealed Classes At work: sealed interface Order permits NewOrder, CancelOrder Exam trap: → Permitted subclasses must be declared as final, sealed, or non-sealed. → Missing modifier? - Compilation error 4. Pattern Matching for Switch At work: switch (obj) { case String s -> ... } Exam trap: → Pattern order matters (more specific before general) → Dominance rules apply → Null is not matched implicitly, must be handled explicitly if needed 5. Sequenced Collections At work: list.getFirst(), list.getLast(), cleaner APIs Exam trap: Which interfaces extend SequencedCollection? → List, Deque, SortedSet ✅ → HashSet ❌ Also: → reversed() returns a view, not a copy The OCP 1Z0-830 exam has 50 questions and lasts 120 minutes. Passing score: 68%. Which feature would trip you up on the exam? #java #java21 #ocp #certification #virtualthreads #records #sealedclasses #backend #developer #fintech

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories