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.

An abstract class in Java can have both ________ and non-abstract methods.

  • Both Abstract and Static Methods
  • Non-Static Methods
  • Only Abstract Methods
  • Only Static Methods
An abstract class in Java can have both abstract (unimplemented) and non-abstract (implemented) methods. Abstract methods are declared using the 'abstract' keyword and are meant to be implemented by concrete subclasses, while non-abstract methods provide default implementations that can be inherited by subclasses or overridden.

Which method is used to write characters to a file in Java?

  • append()
  • println()
  • read()
  • write()
To write characters to a file in Java, you typically use the write() method, which is available in classes like FileWriter and BufferedWriter. It allows you to write characters as a sequence of bytes to the file. The other options, such as read(), append(), and println(), are not primarily used for writing characters to a file.

The ________ class is used to display a color picker in JavaFX.

  • ColorChooser
  • ColorDialog
  • ColorPicker
  • ColorSelector
In JavaFX, the ColorPicker class is used to display a color picker. It allows users to select colors easily by providing a graphical interface for color selection. You can integrate it into your JavaFX applications to enable users to choose colors interactively.

What is the return type of the map() function in Java Streams API?

  • List
  • Stream
  • int
  • void
The map() function in Java Streams API transforms the elements of a stream and returns a new stream of the transformed elements. Therefore, the return type of map() is Stream. It allows you to apply a function to each element and map them to a new value or type.

In Java, if an if statement does not have any braces {}, only the ________ line after the if condition is considered part of the if block.

  • first
  • last
  • middle
  • next
In Java, when an if statement does not have braces {}, only the first line of code immediately following the if condition is considered part of the if block. Any subsequent lines of code are executed outside of the if block. This can lead to unexpected behavior if not used carefully.

Which exception might be thrown when trying to create a new Socket instance?

  • IOException
  • NetworkException
  • SocketCreationException
  • SocketException
When attempting to create a new Socket instance, you may encounter an IOException if there's an issue with the network connection or if the host is unreachable. It's a common exception in socket programming. The other options are not standard exceptions related to socket creation.

How does Java determine which overloaded method to call?

  • Java calls the method randomly, as it cannot determine which one to call.
  • Java calls the method that exactly matches the arguments provided during the method call.
  • Java calls the method with the fewest number of parameters.
  • Java calls the method with the most number of parameters.
Java determines which overloaded method to call by examining the number and types of arguments provided during the method call. It looks for the method that exactly matches the provided arguments. If no exact match is found, it results in a compilation error.