What is the primary benefit of using generics in Java?
Enhanced performance at runtime
Stronger type checking at compile time
Reduced code duplication
Improved code readability
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()
Which of the following is true about the 'peek' operation?
It's a terminal operation that returns a new Stream
It's an intermediate operation that modifies the stream elements
It's a terminal operation that triggers stream processing
It's an intermediate operation primarily used for debugging
In the java.time API, which class represents a specific point in time, such as a timestamp?
java.time
Instant
LocalDate
LocalTime
LocalDateTime
What OOP concept is demonstrated when a single method call behaves differently depending on the object's type?
Encapsulation
Polymorphism
Abstraction
Inheritance
Which class in the java.time package represents a date without a time component?
ZonedDateTime
Which interface in the Java Collections Framework represents an ordered collection of elements, allowing duplicates?
List
Set
Map
Queue
Which keyword is used to declare a class that cannot be instantiated but serves as a blueprint for other classes?
final
abstract
static
interface
What is the purpose of defining a custom annotation in Java?
To attach metadata to classes, methods, or fields
To create new keywords in the Java language
To define new data types
To control access modifiers for classes and methods
Which data structure is best suited for implementing a Last-In-First-Out (LIFO) order of elements in Java?
Stack