121. What is the purpose of the 'var' keyword in lambda parameters (Java 11+)?
- a) To allow dynamic typing
- b) To enable type inference
- c) To make parameters final
- d) var cannot be used in lambdas
Answer: D - var is not permitted in lambda parameter declarations.
122. Which is not a valid switch expression feature (Java 14+)?
- a) Multiple case labels
- b) Arrow syntax (->)
- c) Returning values
- d) Pattern matching
Answer: D - Pattern matching in switch came later (Java 17+).
123. What is the purpose of the 'instanceof' pattern matching (Java 16+)?
- a) To simplify type checking and casting
- b) To implement visitor pattern
- c) To optimize instanceof performance
- d) To replace polymorphism
Answer: A - Eliminates need for explicit casting after instanceof checks.
124. Which is not a valid Java record component modifier?
- a) final
- b) static
- c) volatile
- d) transient
Answer: C - Record components cannot be volatile.
125. What is the purpose of the 'sealed' keyword in Java?
- a) To prevent serialization
- b) To restrict inheritance
- c) To make classes immutable
- d) To optimize performance
Answer: B - Sealed classes control which classes may extend them (Java 17+).
126. Which is not a valid use of text blocks (Java 15+)?
- a) Multiline strings
- b) JSON templates
- c) SQL queries
- d) Binary data
Answer: D - Text blocks are for text content, not binary data.
127. What is the purpose of the 'NullPointerException' detail message (Java 14+)?
- a) To show stack trace
- b) To indicate which variable was null
- c) To suggest fixes
- d) To log automatically
Answer: B - Now shows which reference was null in the exception message.
128. Which is not a valid Java module phase?
- a) Compilation
- b) Packaging
- c) Linking
- d) Interpretation
Answer: D - Java doesn't have an interpretation phase for modules.
129. What is the purpose of the 'Stream.toList()' method (Java 16+)?
- a) To create mutable lists
- b) As a shortcut for Collectors.toList()
- c) To optimize list creation
- d) To filter list elements
Answer: B - Convenience method that returns an unmodifiable list.
130. Which is not a valid 'var' usage (Java 10+)?
- a) Local variables
- b) Lambda parameters
- c) For-loop indexes
- d) Resource variables
Answer: B - var cannot be used for lambda parameters.
131. What is the purpose of the 'Pattern.asMatchPredicate()' method?
- a) To create regex patterns
- b) To convert patterns to predicates
- c) To optimize pattern matching
- d) To chain pattern operations
Answer: B - Creates a Predicate for whole-string matching (Java 11+).
132. Which is not a valid way to create a sealed class hierarchy?
- a) sealed interface permits Class1, Class2
- b) sealed class permits Subclass1, Subclass2
- c) sealed abstract class permits Subclass
- d) sealed enum permits Value1, Value2
Answer: D - Enums cannot be sealed.
133. What is the purpose of the 'Files.writeString()' method?
- a) To write binary data
- b) To append to files
- c) To write text conveniently
- d) To optimize file writes
Answer: C - Simplifies writing strings to files (Java 11+).
134. Which is not a valid Java primitive type?
- a) int
- b) float
- c) string
- d) boolean
Answer: C - string is not a primitive (it's String, a class).
135. What is the purpose of the 'Optional.isEmpty()' method?
- a) To check for null
- b) As negation of isPresent()
- c) To clear the Optional
- d) To convert to Stream
Answer: B - Returns true when no value is present (Java 11+).
136. Which is not a valid Java memory area?
- a) Heap
- b) Stack
- c) Cache
- d) Metaspace
Answer: C - Cache is not a designated JVM memory area.
137. What is the purpose of the 'String.indent()' method?
- a) To add leading spaces
- b) To normalize whitespace
- c) To format JSON
- d) To optimize string storage
Answer: A - Adjusts indentation of text blocks (Java 12+).
138. Which is not a valid CompletableFuture composition method?
- a) thenCompose()
- b) thenCombine()
- c) thenMerge()
- d) thenAcceptBoth()
Answer: C - There's no thenMerge() method.
139. What is the purpose of the 'Collectors.filtering()' method?
- a) To filter before collecting
- b) To optimize stream filters
- c) To chain multiple filters
- d) To replace Stream.filter()
Answer: A - Applies filter during collection (Java 9+).
140. Which is not a valid Java concurrency utility?
- a) CountDownLatch
- b) CyclicBarrier
- c) ThreadGate
- d) Phaser
Answer: C - There's no ThreadGate class in java.util.concurrent.