Quiz
Eight quick questions on modern Java - records, sealed types, virtual threads, pattern matching.
Sample questions
EXAMPLE
# Java quiz 1) Records are: a) mutable POJOs b) compact immutable data carriers with auto-generated equals/hashCode/toString c) interfaces with default methods d) abstract classes 2) Sealed types let you: a) lock the file from edits b) restrict which classes can implement an interface or extend a class c) prevent reflection d) enable bytecode signing 3) Virtual threads (Java 21): a) are OS threads b) are lightweight scheduled by the JVM, cheap to create by the million c) replace ForkJoinPool d) only work on Linux 4) Optional.get() should be used: a) freely b) only after isPresent() or with orElse / orElseThrow c) never d) inside finally 5) Streams are: a) IO streams b) lazy pipelines that compute on terminal operations c) eager arrays d) always parallel 6) Pattern matching for switch on Java 21 supports: a) types only b) types, deconstruction, and guards c) regex d) primitives only 7) try-with-resources requires the resource to implement: a) AutoCloseable b) Iterable c) Comparable d) nothing 8) The Java module system (JPMS) helps you: a) install dependencies b) declare strong encapsulation and dependencies at module level c) replace Maven d) compile to native by default Answers: 1b, 2b, 3b, 4b, 5b, 6b, 7a, 8b.
Why it matters
Modern Java is a different language than Java 8. Records, sealed types, pattern matching, and virtual threads cut boilerplate and rewrite how you do concurrency. If you skip them you are writing Java 1.4 in a 21 runtime.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Discussion
Loading…