Which interface must a class implement to be eligible for serialization in Java?
Parcelable
Iterable
Cloneable
Serializable
What is the primary benefit of using generics in Java?
Stronger type checking at compile time
Improved code readability
Reduced code duplication
Enhanced performance at runtime
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);
4
2
5
10
Which of the following is a key advantage of using the Java NIO (New I/O) package for file handling?
It provides a simpler API for basic file operations like reading and writing.
It offers support for non-blocking I/O operations, enhancing application responsiveness.
It automatically handles file compression and decompression.
It eliminates the need for exception handling during file I/O.
What is a potential drawback of using object serialization in Java?
It does not allow for the serialization of primitive data types.
It requires all serialized objects to implement the Cloneable interface.
It is incompatible with network communication protocols.
It can be less efficient than custom data writing mechanisms, especially for large objects.
What is the difference between StringBuilder and StringBuffer in Java?
StringBuilder
StringBuffer
StringBuilder is mutable, StringBuffer is immutable.
StringBuilder is not thread-safe, StringBuffer is thread-safe.
StringBuilder is thread-safe, StringBuffer is not thread-safe.
There is no difference, they are aliases for the same class.
What is the purpose of defining a custom annotation in Java?
To control access modifiers for classes and methods
To create new keywords in the Java language
To define new data types
To attach metadata to classes, methods, or fields
In the context of Java's 'Future' interface, what does the 'get()' method do?
It retrieves the result of an asynchronous computation, potentially blocking until it's available
It checks if the asynchronous task has completed or not
It sets a timeout for the asynchronous computation
It cancels the asynchronous task associated with the Future
Which annotation is used to indicate that a method from a superclass is being overridden?
@Implement
@Override
@Overload
@OverrideMethod
What OOP concept is demonstrated when a single method call behaves differently depending on the object's type?
Polymorphism
Abstraction
Inheritance
Encapsulation