Which keyword is used to create a generic method in Java?
No specific keyword is required
generic
typeparam
template
What does the File.createNewFile() method do if a file with the same name already exists in the specified location?
File.createNewFile()
It throws a FileNotFoundException.
FileNotFoundException
It returns false without creating a new file.
false
It overwrites the existing file with an empty file.
It appends a number to the file name to create a unique file.
Which method converts a stream of strings to a single comma-separated string?
collect(Collectors.joining(", "))
reduce(", ", String::concat)
map(String::concat).collect(Collectors.toList())
Both A and B
Which keyword is used to declare a class that cannot be instantiated but serves as a blueprint for other classes?
final
interface
static
abstract
In Java's concurrency model, what is the primary purpose of a 'wait()' call on an object?
To signal other waiting threads to resume execution
To forcefully acquire the object's lock
To check if the object's lock is available
To release the object's lock and put the thread in a waiting state
Which Java method would you use to find the index of the first occurrence of a specific substring within a string?
length()
charAt()
indexOf()
substring()
Which interface must a custom annotation extend directly or indirectly?
java.lang.annotation.Annotation
java.lang.Class
java.lang.reflect.AnnotatedElement
java.lang.annotation.ElementType
What happens when a generic class is instantiated with a primitive type in Java?
A compile-time error occurs.
A runtime exception is thrown.
It works as expected.
The primitive type is autoboxed to its wrapper class.
Which annotation is used to suppress compiler warnings in Java?
@DisableWarnings
@NoWarnings
@SuppressWarnings
@IgnoreWarnings
Which mechanism is best suited for coordinating communication between threads where one thread produces data and another consumes it?
Using a 'Semaphore'
Employing a 'BlockingQueue'
Directly sharing objects between threads
Using 'volatile' variables