In Java's concurrency model, what is the primary purpose of a 'wait()' call on an object?
To release the object's lock and put the thread in a waiting state
To forcefully acquire the object's lock
To signal other waiting threads to resume execution
To check if the object's lock is available
What is a custom collector in Java Streams?
A predefined collector provided by the Java API
A user-defined collector to perform specific aggregation operations
A mechanism for sorting stream elements in a custom order
A way to filter elements in a stream based on custom logic
Which of the following is a key advantage of using the Java NIO (New I/O) package for file handling?
It automatically handles file compression and decompression.
It eliminates the need for exception handling during file I/O.
It provides a simpler API for basic file operations like reading and writing.
It offers support for non-blocking I/O operations, enhancing application responsiveness.
What is the most suitable approach to ensure that a specific block of code is executed by only one thread at a time?
Using the 'volatile' keyword
Declaring the variable as 'final'
Implementing the 'Serializable' interface
Using a 'synchronized' block or method
Which Java method would you use to find the index of the first occurrence of a specific substring within a string?
indexOf()
substring()
charAt()
length()
The 'flatMap' operation on a stream is used for:
Flattening a stream of collections into a single stream
Reducing the stream to a single summary value
Transforming each element into a single new element
Filtering elements based on a predicate
Which interface is used to create a type-safe heterogeneous container in Java?
Collection
Comparable
Iterator
Iterable
Which method in the String class is used to compare two strings lexicographically ignoring case?
String
compareTo()
compareToIgnoreCase()
equals()
equalsIgnoreCase()
In Java NIO, what is the purpose of a Selector?
Selector
It manages multiple channels and allows for efficient handling of I/O events.
It represents an open connection to a file for reading or writing data.
It serializes and deserializes objects to and from NIO channels.
It provides a buffer for storing data read from or written to a channel.
How can you access the value of an annotation's element at runtime?
By using the getDeclaredAnnotation() method
getDeclaredAnnotation()
By using the getAnnotation() method
getAnnotation()
By accessing the annotation element directly as a field of the annotated element
By casting the annotated element to the annotation type