Which method is used to add elements to the end of a Queue in Java?
Queue
add()
offer()
push()
insert()
Which built-in Java annotation is used to indicate that a method overrides a method in its superclass?
@FunctionalInterface
@Override
@SuppressWarnings
@Deprecated
What distinct advantage does a 'Callable' interface offer over 'Runnable' in Java?
Callable is used for tasks that don't return a value, while Runnable is for tasks that do
Callable can be used with traditional threads, while Runnable requires an ExecutorService
Callable can throw checked exceptions, while Runnable cannot
Callable executes faster than Runnable
Can a method be both generic and static in Java?
Yes, but the type parameter should be declared before the method name.
No, generic methods cannot be static.
Yes, but the type parameter should be declared after the 'static' keyword.
Yes, there are no restrictions.
In the context of Java's 'Future' interface, what does the 'get()' method do?
It cancels the asynchronous task associated with the Future
It checks if the asynchronous task has completed or not
It sets a timeout for the asynchronous computation
It retrieves the result of an asynchronous computation, potentially blocking until it's available
What is the difference between HashMap and TreeMap in Java?
HashMap
TreeMap
HashMap is synchronized, while TreeMap is not.
HashMap maintains elements in insertion order, while TreeMap sorts elements based on keys.
HashMap allows null keys and values, while TreeMap does not.
HashMap provides faster retrieval times than TreeMap.
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 define custom locking mechanisms
To synchronize access to shared resources
Which interface must a custom annotation extend directly or indirectly?
java.lang.reflect.AnnotatedElement
java.lang.Class
java.lang.annotation.ElementType
java.lang.annotation.Annotation
Which of the following is true about the 'peek' operation?
It's an intermediate operation that modifies the stream elements
It's a terminal operation that triggers stream processing
It's a terminal operation that returns a new Stream
It's an intermediate operation primarily used for debugging
What is the difference between StringBuilder and StringBuffer in Java?
StringBuilder
StringBuffer
StringBuilder is not thread-safe, StringBuffer is thread-safe.
StringBuilder is mutable, StringBuffer is immutable.
StringBuilder is thread-safe, StringBuffer is not thread-safe.
There is no difference, they are aliases for the same class.