What is the primary benefit of using generics in Java?
Reduced code duplication
Enhanced performance at runtime
Improved code readability
Stronger type checking at compile time
What is the primary purpose of an interface in Java?
To define a contract for classes to adhere to
To enforce specific method implementations
To define a template for object creation
To create multiple inheritance of classes
Which interface does Java primarily use to represent a task that can be executed concurrently?
Runnable
Iterable
Threadable
Callable
What is the difference between HashMap and TreeMap in Java?
HashMap
TreeMap
HashMap is synchronized, while TreeMap is not.
HashMap allows null keys and values, while TreeMap does not.
HashMap provides faster retrieval times than TreeMap.
HashMap maintains elements in insertion order, while TreeMap sorts elements based on keys.
Which class in the java.time package represents a date without a time component?
java.time
LocalDateTime
LocalDate
ZonedDateTime
Instant
Which interface in the Java Collections Framework represents an ordered collection of elements, allowing duplicates?
Queue
Map
List
Set
Which interface is used to create a type-safe heterogeneous container in Java?
Comparable
Collection
Iterator
Which method is used to convert a Stream back to a List?
collect(Collectors.toList())
reduce(Collectors.toList())
map(Collectors.toList())
filter(Collectors.toList())
What is the primary purpose of using the @Deprecated annotation in Java?
To hide methods from documentation
To throw a runtime exception if the method is called
To indicate that a method is no longer recommended for use
To prevent a method from being inherited
In Java NIO, what is the purpose of a Selector?
Selector
It provides a buffer for storing data read from or written to a channel.
It manages multiple channels and allows for efficient handling of I/O events.
It serializes and deserializes objects to and from NIO channels.
It represents an open connection to a file for reading or writing data.