Can a method be both generic and static in Java?
Yes, but the type parameter should be declared before the method name.
Yes, but the type parameter should be declared after the 'static' keyword.
Yes, there are no restrictions.
No, generic methods cannot be static.
Which method is used to convert a Stream back to a List?
reduce(Collectors.toList())
collect(Collectors.toList())
map(Collectors.toList())
filter(Collectors.toList())
What is the core function of an 'ExecutorService' in Java's concurrency framework?
To define custom locking mechanisms
To manage and execute thread pools efficiently
To synchronize access to shared resources
To schedule tasks for execution at fixed intervals
Which interface must a class implement to be eligible for serialization in Java?
Serializable
Parcelable
Iterable
Cloneable
Which method in the String class is used to compare two strings lexicographically ignoring case?
String
compareTo()
compareToIgnoreCase()
equalsIgnoreCase()
equals()
What is a key advantage of using inner classes in Java?
Improved code organization and encapsulation
Increased code execution speed
Enhanced support for multithreading
Reduced memory footprint of the program
Which keyword is used to declare a class that cannot be instantiated but serves as a blueprint for other classes?
final
interface
abstract
static
Which of these is NOT a valid retention policy for a custom annotation in Java?
SOURCE
CLASS
RUNTIME
DEPLOYMENT
What will be the output of the following Java code snippet?
String str = "Hello World"; System.out.println(str.substring(6));
Hello World
World
Hello
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()