1. Which memory area replaced PermGen in Java 8?
Correct Answer: Metaspace
Explanation: Metaspace stores class metadata and replaced PermGen in Java 8.
2. Which collection is thread-safe and optimized for read-heavy
operations?
Correct Answer: CopyOnWriteArrayList
Explanation: It allows safe concurrent access without explicit synchronization.
3. What happens if wait() is called without owning the monitor?
Correct Answer: IllegalMonitorStateException
Explanation: A thread must own the object's monitor to call wait().
4. Which keyword guarantees variable visibility across threads?
Correct Answer: volatile
Explanation: volatile ensures changes are visible across threads.
5. Which Stream method transforms elements?
Correct Answer: map()
Explanation: map() converts each element into another form.
6. Which GC is optimized for low-latency applications?
Correct Answer: G1 GC
Explanation: G1 GC balances throughput with low pause times.
7. Which design pattern ensures only one instance exists?
Correct Answer: Singleton
Explanation: Singleton restricts instantiation to one object.
8. Which interface is a marker interface?
Correct Answer: Serializable
Explanation: Marker interfaces contain no methods.
9. What does Optional help prevent?
Correct Answer: NullPointerException
Explanation: Optional provides a safe container for nullable values.
10. What is the role of ClassLoader?
Correct Answer: Load classes at runtime
Explanation: ClassLoader dynamically loads class definitions into the JVM.
11. Which ExecutorService method stops accepting new tasks?
Correct Answer: shutdown()
Explanation: shutdown() prevents new tasks but allows running tasks to finish.
12. Which keyword prevents a method from being overridden?
Correct Answer: final
Explanation: final methods cannot be overridden by subclasses.
13. Which collection does NOT allow duplicate elements?
Correct Answer: HashSet
Explanation: Set implementations do not allow duplicate values.
14. Which exception is thrown when a thread is interrupted?
Correct Answer: InterruptedException
Explanation: Thrown when a thread is waiting or sleeping and gets interrupted.
15. What is the main benefit of immutable objects?
Correct Answer: Thread safety
Explanation: Immutable objects cannot be changed after creation.
16. Which interface allows custom object sorting?
Correct Answer: Comparable
Explanation: Comparable defines natural ordering of objects.
17. Which keyword allows a method to be accessed without creating an
object?
Correct Answer: static
Explanation: Static methods belong to the class, not instances.
18. Which Stream method converts elements into a single result?
Correct Answer: reduce()
Explanation: reduce() aggregates stream elements into a single value.
19. Which Java feature supports multiple inheritance?
Correct Answer: Interfaces
Explanation: A class can implement multiple interfaces.
20. What does the JVM use the stack for?
Correct Answer: Method execution
Explanation: The stack stores method calls and local variables per thread.