The 'flatMap' operation on a stream is used for:
Filtering elements based on a predicate
Flattening a stream of collections into a single stream
Transforming each element into a single new element
Reducing the stream to a single summary value
Which type of collection is inherently thread-safe and specifically designed for concurrent access in Java?
ConcurrentHashMap
TreeMap
ArrayList
HashSet
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 most suitable approach to ensure that a specific block of code is executed by only one thread at a time?
Implementing the 'Serializable' interface
Declaring the variable as 'final'
Using the 'volatile' keyword
Using a 'synchronized' block or method
Which method is used to add elements to the end of a Queue in Java?
Queue
add()
push()
insert()
offer()
Which of the following is a key advantage of using the Java NIO (New I/O) package for file handling?
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.
It automatically handles file compression and decompression.
It eliminates the need for exception handling during file I/O.
Which data structure is best suited for implementing a Last-In-First-Out (LIFO) order of elements in Java?
Set
Stack
Map
What is a custom collector in Java Streams?
A predefined collector provided by the Java API
A way to filter elements in a stream based on custom logic
A user-defined collector to perform specific aggregation operations
A mechanism for sorting stream elements in a custom order
What will the following code snippet print?
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5); long count = numbers.stream().filter(n -> n % 2 == 0).map(n -> n * 2).count(); System.out.println(count);
5
10
2
4
Which interface in the Java Collections Framework represents an ordered collection of elements, allowing duplicates?
List