What is the difference between StringBuilder and StringBuffer in Java?
StringBuilder
StringBuffer
StringBuilder is not thread-safe, StringBuffer is thread-safe.
StringBuilder is thread-safe, StringBuffer is not thread-safe.
StringBuilder is mutable, StringBuffer is immutable.
There is no difference, they are aliases for the same class.
What is the purpose of the StringBuilder class in Java?
To perform regular expression matching.
To store large text files.
To efficiently build mutable strings.
To create immutable strings.
What is the primary purpose of using a BufferedInputStream in Java?
BufferedInputStream
To improve file I/O performance by reducing the number of interactions with the underlying storage.
To serialize and deserialize objects to and from a byte stream.
To perform asynchronous file operations for faster data processing.
To directly read and write primitive data types to a file.
In the context of Java's 'Future' interface, what does the 'get()' method do?
It retrieves the result of an asynchronous computation, potentially blocking until it's available
It sets a timeout for the asynchronous computation
It checks if the asynchronous task has completed or not
It cancels the asynchronous task associated with the Future
Which interface must a custom annotation extend directly or indirectly?
java.lang.Class
java.lang.annotation.ElementType
java.lang.annotation.Annotation
java.lang.reflect.AnnotatedElement
Which of the following is NOT a valid way to create a Stream in Java?
Stream.of(1, 2, 3)
new Stream()
Arrays.stream(array)
list.stream()
What distinct advantage does a 'Callable' interface offer over 'Runnable' in Java?
Callable executes faster than Runnable
Callable can throw checked exceptions, while Runnable cannot
Callable can be used with traditional threads, while Runnable requires an ExecutorService
Callable is used for tasks that don't return a value, while Runnable is for tasks that do
Which interface in the Java Collections Framework represents an ordered collection of elements, allowing duplicates?
Map
Queue
List
Set
What type of inner class is defined without a name and is typically used for creating one-off event handlers?
Local class
Anonymous class
Static inner class
Nested class
Which interface does Java primarily use to represent a task that can be executed concurrently?
Threadable
Callable
Runnable
Iterable