When a subclass provides a specific implementation for a method already defined in its superclass, what is this called?
Dynamic dispatch
Method overriding
Method hiding
Method overloading
Which of the following is NOT a valid way to create a Stream in Java?
new Stream()
Stream.of(1, 2, 3)
list.stream()
Arrays.stream(array)
What is a potential drawback of using object serialization in Java?
It is incompatible with network communication protocols.
It does not allow for the serialization of primitive data types.
It requires all serialized objects to implement the Cloneable interface.
Cloneable
It can be less efficient than custom data writing mechanisms, especially for large objects.
What distinct advantage does a 'Callable' interface offer over 'Runnable' in Java?
Callable executes faster than Runnable
Callable can be used with traditional threads, while Runnable requires an ExecutorService
Callable can throw checked exceptions, while Runnable cannot
Callable is used for tasks that don't return a value, while Runnable is for tasks that do
What does the File.createNewFile() method do if a file with the same name already exists in the specified location?
File.createNewFile()
It overwrites the existing file with an empty file.
It throws a FileNotFoundException.
FileNotFoundException
It returns false without creating a new file.
false
It appends a number to the file name to create a unique file.
How can you get the current year using the java.time API?
java.time
Year.now()
LocalTime.now().getYear()
Calendar.getInstance().get(Calendar.YEAR)
LocalDate.now().getYear()
Which interface does Java primarily use to represent a task that can be executed concurrently?
Callable
Runnable
Iterable
Threadable
Which annotation is used to suppress compiler warnings in Java?
@DisableWarnings
@NoWarnings
@IgnoreWarnings
@SuppressWarnings
Which mechanism is best suited for coordinating communication between threads where one thread produces data and another consumes it?
Using a 'Semaphore'
Using 'volatile' variables
Employing a 'BlockingQueue'
Directly sharing objects between threads
Which of the following classes in the java.io package is used to read data from a file?
java.io
FileOutputStream
File
FileInputStream
FileWriter