If a class is declared as ________, it cannot be extended.

  • abstract
  • final
  • private
  • static
In Java, if a class is declared as final, it cannot be extended or subclassed. This is often used to prevent further modification or inheritance of a class, providing a level of immutability.

What happens when two methods are overloaded with array arguments of the type where one is an array of derived type and another is an array of its base type?

  • It depends on the order in which the methods are defined in the class.
  • The compiler throws an error as it cannot distinguish between the two overloaded methods.
  • The method with the array of the base type is called.
  • The method with the array of the derived type is called.
When two methods are overloaded with array arguments in Java, and one takes an array of a derived type while the other takes an array of its base type, the compiler throws an error. This is because the compiler cannot distinguish between the two methods based on the type of the array, as arrays in Java are covariant.

The showAndWait() method is used to display a ________ and wait for the user's response.

  • Alert
  • Dialog
  • Notification
  • Popup
In JavaFX, the Alert class is often used to display dialog boxes that require user interaction. The showAndWait() method is used to display an alert dialog and wait for the user's response before proceeding. The other options, Dialog, Popup, and Notification, are not the classes commonly associated with this method.

Which method is used to read a single character from a character input stream in Java?

  • read()
  • readChar()
  • readCharacter()
  • readLine()
The read() method in Java's character input stream classes is used to read a single character at a time. It returns an integer representing the Unicode code point of the character read. The other options are not valid methods for reading a single character from a character input stream.

Consider a scenario where you need to enforce singleton behavior on a class. How would constructors play a role in ensuring this?

  • Constructors are used to create multiple instances, each with a unique ID.
  • Constructors are used to enforce thread safety in the singleton pattern.
  • Constructors ensure single instance creation by marking the constructor as private and providing a static method to retrieve the instance.
  • Constructors play no role in enforcing singleton behavior.
In the singleton pattern, constructors play a crucial role in enforcing the creation of a single instance of a class. To achieve this, the constructor is marked as private to prevent external instantiation, and a static method is provided to retrieve the single instance. This ensures that only one instance of the class exists throughout the application's lifecycle.

How are Lambda expressions compiled in Java?

  • Lambdas are compiled into native machine code for better performance.
  • Lambdas are compiled into traditional anonymous inner classes.
  • Lambdas are not compiled; they are interpreted at runtime.
  • Lambdas are pre-compiled and stored as bytecode in a separate file.
In Java, Lambda expressions are compiled into traditional anonymous inner classes by the Java compiler. These inner classes capture the behavior defined by the Lambda expression. The use of inner classes allows the Java Virtual Machine (JVM) to treat Lambdas as objects with associated methods, which makes them compatible with existing Java features and enables the use of functional interfaces. Understanding this compilation process is crucial for developers who want to understand the inner workings of Lambdas and their impact on the bytecode.

To retrieve the value of the first column in the current row of a ResultSet, you can use the method ________.

  • getFirstColumnValue()
  • getInt(0)
  • getRowValue()
  • getString(1)
To retrieve the value of the first column in the current row of a ResultSet, you can use the method getString(1). This method fetches the value of the column at index 1 (the first column) and returns it as a string. The other options are not valid methods for this purpose.

What is the primary difference between Runnable and Callable interfaces?

  • Callable can be scheduled for future execution.
  • Callable can run without being wrapped in a thread.
  • Runnable allows returning a result.
  • Runnable can be used for multi-threading.
The primary difference between Runnable and Callable interfaces is that Callable allows you to return a result from the computation, whereas Runnable does not. Callable is typically used when you need a result from a task that can be scheduled for future execution, while Runnable is a simple interface for a task that does not return a result.

The ________ method in the Stream API returns an equivalent stream that is sequential.

  • filter
  • map
  • parallel
  • sequential
In the Stream API of Java, the sequential() method is used to return an equivalent stream that is sequential in nature. This method can be useful when you want to ensure that subsequent operations on the stream are executed in a sequential order.

In Java, a variable declared within a method is referred to as a ________ variable.

  • Global
  • Instance
  • Local
  • Static
In Java, a variable declared within a method is referred to as a "Local" variable. Local variables are defined within a method and are only accessible within that method's scope. They are used for temporary storage and are typically used to store intermediate results or data specific to a method.