Which annotation is used to suppress compiler warnings in Java?
@IgnoreWarnings
@NoWarnings
@SuppressWarnings
@DisableWarnings
Which class in the java.time package represents a date without a time component?
java.time
LocalDateTime
Instant
LocalDate
ZonedDateTime
When should you prefer using try-with-resources over explicitly closing resources in Java file I/O?
try-with-resources
Always, as it ensures resources are closed even if exceptions occur.
Only when reading from files, not when writing to them.
Only when handling multiple resources simultaneously.
Never, explicit closing provides better control and clarity.
What happens when a Stream encounters an exception during execution?
The stream processing stops, and the exception is thrown
The exception is ignored, and the stream continues processing
The stream processing pauses, and the user is prompted to handle the exception
The exception is caught and wrapped in a RuntimeException
Can a static inner class access non-static members of its outer class directly?
No
Yes
What is the difference between StringBuilder and StringBuffer in Java?
StringBuilder
StringBuffer
StringBuilder is mutable, StringBuffer is immutable.
StringBuilder is thread-safe, StringBuffer is not thread-safe.
There is no difference, they are aliases for the same class.
StringBuilder is not thread-safe, StringBuffer is thread-safe.
Which keyword is used to create a generic method in Java?
generic
template
No specific keyword is required
typeparam
What is the purpose of defining a custom annotation in Java?
To define new data types
To attach metadata to classes, methods, or fields
To control access modifiers for classes and methods
To create new keywords in the Java language
Which interface must a custom annotation extend directly or indirectly?
java.lang.Class
java.lang.annotation.Annotation
java.lang.annotation.ElementType
java.lang.reflect.AnnotatedElement
Which interface in the Java Collections Framework represents an ordered collection of elements, allowing duplicates?
Queue
Map
Set
List