Which method is used to add elements to the end of a Queue in Java?
Queue
add()
insert()
push()
offer()
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 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
The 'flatMap' operation on a stream is used for:
Transforming each element into a single new element
Flattening a stream of collections into a single stream
Reducing the stream to a single summary value
Filtering elements based on a predicate
Which type of collection is inherently thread-safe and specifically designed for concurrent access in Java?
ConcurrentHashMap
ArrayList
HashSet
TreeMap
Which List implementation in Java uses a dynamic array to store elements and provides fast access to elements by their index?
List
Stack
Vector
LinkedList
What is the time complexity of searching for an element in a well-implemented HashMap in the average case?
HashMap
O(log n)
O(n)
O(1)
O(n log n)
How can you access the value of an annotation's element at runtime?
By accessing the annotation element directly as a field of the annotated element
By using the getAnnotation() method
getAnnotation()
By using the getDeclaredAnnotation() method
getDeclaredAnnotation()
By casting the annotated element to the annotation type
How can you get the current year using the java.time API?
java.time
Year.now()
LocalTime.now().getYear()
LocalDate.now().getYear()
Calendar.getInstance().get(Calendar.YEAR)
When should you prefer using try-with-resources over explicitly closing resources in Java file I/O?
try-with-resources
Never, explicit closing provides better control and clarity.
Only when reading from files, not when writing to them.
Always, as it ensures resources are closed even if exceptions occur.
Only when handling multiple resources simultaneously.
Which annotation is used to suppress compiler warnings in Java?
@NoWarnings
@DisableWarnings
@IgnoreWarnings
@SuppressWarnings