What is the primary purpose of using a BufferedInputStream in Java?
BufferedInputStream
To directly read and write primitive data types to a file.
To improve file I/O performance by reducing the number of interactions with the underlying storage.
To serialize and deserialize objects to and from a byte stream.
To perform asynchronous file operations for faster data processing.
What type of inner class is defined without a name and is typically used for creating one-off event handlers?
Nested class
Local class
Static inner class
Anonymous class
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
Which interface is used to create a type-safe heterogeneous container in Java?
Iterable
Comparable
Iterator
Collection
Which annotation is used to suppress compiler warnings in Java?
@NoWarnings
@IgnoreWarnings
@SuppressWarnings
@DisableWarnings
What is a potential drawback of using object serialization in Java?
It can be less efficient than custom data writing mechanisms, especially for large objects.
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
Which interface in the Java Collections Framework represents a group of objects where duplicates are not allowed?
List
Queue
Map
Set
What will the following code snippet print?
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5); long count = numbers.stream().filter(n -> n % 2 == 0).map(n -> n * 2).count(); System.out.println(count);
5
2
4
10
Which built-in Java annotation is used to indicate that a method overrides a method in its superclass?
@Override
@FunctionalInterface
@Deprecated
What is the primary purpose of using the @Deprecated annotation in Java?
To indicate that a method is no longer recommended for use
To hide methods from documentation
To prevent a method from being inherited
To throw a runtime exception if the method is called