How can you access the value of an annotation's element at runtime?
By using the getDeclaredAnnotation() method
getDeclaredAnnotation()
By casting the annotated element to the annotation type
By accessing the annotation element directly as a field of the annotated element
By using the getAnnotation() method
getAnnotation()
What is the primary benefit of using generics in Java?
Enhanced performance at runtime
Reduced code duplication
Improved code readability
Stronger type checking at compile time
Which annotation is used to indicate that a method from a superclass is being overridden?
@OverrideMethod
@Override
@Overload
@Implement
In the context of Java's 'Future' interface, what does the 'get()' method do?
It sets a timeout for the asynchronous computation
It cancels the asynchronous task associated with the Future
It retrieves the result of an asynchronous computation, potentially blocking until it's available
It checks if the asynchronous task has completed or not
Can a static inner class access non-static members of its outer class directly?
No
Yes
In Java NIO, what is the purpose of a Selector?
Selector
It represents an open connection to a file for reading or writing data.
It serializes and deserializes objects to and from NIO channels.
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.
What will LocalDate.now().plusDays(1) return?
LocalDate.now().plusDays(1)
The current date and time.
The date one day before the current date.
The date one day after the current date.
An error, as the plusDays() method does not exist.
plusDays()
Which method converts a stream of strings to a single comma-separated string?
reduce(", ", String::concat)
Both A and B
collect(Collectors.joining(", "))
map(String::concat).collect(Collectors.toList())
How can you get the current year using the java.time API?
java.time
LocalTime.now().getYear()
LocalDate.now().getYear()
Calendar.getInstance().get(Calendar.YEAR)
Year.now()
What Java mechanism is commonly used to process annotations at runtime?
Inheritance
Generics
Reflection
Serialization