Which mechanism is best suited for coordinating communication between threads where one thread produces data and another consumes it?
Using a 'Semaphore'
Employing a 'BlockingQueue'
Using 'volatile' variables
Directly sharing objects between threads
What type of inner class is defined without a name and is typically used for creating one-off event handlers?
Anonymous class
Local class
Nested class
Static inner class
What happens when a Stream encounters an exception during execution?
The exception is ignored, and the stream continues processing
The stream processing pauses, and the user is prompted to handle the exception
The exception is caught and wrapped in a RuntimeException
The stream processing stops, and the exception is thrown
What is the purpose of the StringBuilder class in Java?
StringBuilder
To perform regular expression matching.
To create immutable strings.
To efficiently build mutable strings.
To store large text files.
The 'flatMap' operation on a stream is used for:
Flattening a stream of collections into a single stream
Filtering elements based on a predicate
Transforming each element into a single new element
Reducing the stream to a single summary value
What is the core function of an 'ExecutorService' in Java's concurrency framework?
To schedule tasks for execution at fixed intervals
To manage and execute thread pools efficiently
To synchronize access to shared resources
To define custom locking mechanisms
What will be the output of the following Java code snippet?
String str = "Hello World"; System.out.println(str.substring(6));
World
Hello World
Hello
Which of the following classes in the java.io package is used to read data from a file?
java.io
FileInputStream
FileOutputStream
File
FileWriter
Can a static inner class access non-static members of its outer class directly?
No
Yes
Which interface must a custom annotation extend directly or indirectly?
java.lang.annotation.ElementType
java.lang.annotation.Annotation
java.lang.reflect.AnnotatedElement
java.lang.Class