How can you get the current year using the java.time API?
java.time
LocalTime.now().getYear()
Year.now()
LocalDate.now().getYear()
Calendar.getInstance().get(Calendar.YEAR)
What is the primary purpose of an interface in Java?
To enforce specific method implementations
To define a template for object creation
To create multiple inheritance of classes
To define a contract for classes to adhere to
Which of the following is a key advantage of using the Java NIO (New I/O) package for file handling?
It eliminates the need for exception handling during file I/O.
It offers support for non-blocking I/O operations, enhancing application responsiveness.
It provides a simpler API for basic file operations like reading and writing.
It automatically handles file compression and decompression.
Which of the following classes in the java.io package is used to read data from a file?
java.io
FileWriter
File
FileOutputStream
FileInputStream
What distinct advantage does a 'Callable' interface offer over 'Runnable' in Java?
Callable can be used with traditional threads, while Runnable requires an ExecutorService
Callable is used for tasks that don't return a value, while Runnable is for tasks that do
Callable executes faster than Runnable
Callable can throw checked exceptions, while Runnable cannot
Which type of collection is inherently thread-safe and specifically designed for concurrent access in Java?
ConcurrentHashMap
ArrayList
HashSet
TreeMap
What Java mechanism is commonly used to process annotations at runtime?
Reflection
Inheritance
Serialization
Generics
What type of inner class is defined without a name and is typically used for creating one-off event handlers?
Local class
Static inner class
Nested class
Anonymous class
Which interface is used to create a type-safe heterogeneous container in Java?
Collection
Comparable
Iterable
Iterator
When a subclass provides a specific implementation for a method already defined in its superclass, what is this called?
Method overloading
Method hiding
Dynamic dispatch
Method overriding