What will be the output of the following Java code snippet?
String str = "Hello World"; System.out.println(str.substring(6));
World
Hello
Hello World
What is the purpose of the StringBuilder class in Java?
StringBuilder
To efficiently build mutable strings.
To store large text files.
To create immutable strings.
To perform regular expression matching.
Which method is used to forcefully stop the execution of a thread, although considered deprecated due to potential risks?
destroy()
interrupt()
stop()
halt()
What is the primary benefit of using generics in Java?
Enhanced performance at runtime
Improved code readability
Stronger type checking at compile time
Reduced code duplication
What is the difference between StringBuilder and StringBuffer in Java?
StringBuffer
StringBuilder is thread-safe, StringBuffer is not thread-safe.
StringBuilder is not thread-safe, StringBuffer is thread-safe.
StringBuilder is mutable, StringBuffer is immutable.
There is no difference, they are aliases for the same class.
Which method in the String class is used to compare two strings lexicographically ignoring case?
String
equalsIgnoreCase()
compareToIgnoreCase()
compareTo()
equals()
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 control access modifiers for classes and methods
To define new data types
What is a custom collector in Java Streams?
A mechanism for sorting stream elements in a custom order
A user-defined collector to perform specific aggregation operations
A way to filter elements in a stream based on custom logic
A predefined collector provided by the Java API
Which built-in Java annotation is used to indicate that a method overrides a method in its superclass?
@SuppressWarnings
@Deprecated
@FunctionalInterface
@Override
Which keyword is used to create a generic method in Java?
template
generic
No specific keyword is required
typeparam