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
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 provides a buffer for storing data read from or written to a channel.
It serializes and deserializes objects to and from NIO channels.
It represents an open connection to a file for reading or writing data.
Which built-in Java annotation is used to indicate that a method overrides a method in its superclass?
@Override
@FunctionalInterface
@Deprecated
@SuppressWarnings
Which annotation is used to indicate that a method from a superclass is being overridden?
@Implement
@Overload
@OverrideMethod
When a subclass provides a specific implementation for a method already defined in its superclass, what is this called?
Method hiding
Method overriding
Dynamic dispatch
Method overloading
How can you get the current year using the java.time API?
java.time
Calendar.getInstance().get(Calendar.YEAR)
Year.now()
LocalTime.now().getYear()
LocalDate.now().getYear()
How can you access the value of an annotation's element at runtime?
By casting the annotated element to the annotation type
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
What will LocalDate.now().plusDays(1) return?
LocalDate.now().plusDays(1)
The current date and time.
An error, as the plusDays() method does not exist.
plusDays()
The date one day before the current date.
The date one day after the current date.
Which interface must a custom annotation extend directly or indirectly?
java.lang.annotation.ElementType
java.lang.annotation.Annotation
java.lang.Class
java.lang.reflect.AnnotatedElement
Which method in the String class is used to compare two strings lexicographically ignoring case?
String
equals()
compareToIgnoreCase()
compareTo()
equalsIgnoreCase()