Which searching algorithm requires the data to be sorted to work effectively?

  • Binary Search
  • Linear Search
  • Merge Sort
  • Quick Sort
Binary Search is an algorithm that requires the data to be sorted in ascending or descending order for effective searching. It uses the divide and conquer method and is not suitable for unsorted data.

To update UI components from a non-JavaFX thread, use ________.

  • Platform.exit()
  • Platform.repaint()
  • Platform.runLater()
  • Platform.update()
To update UI components from a non-JavaFX thread in JavaFX, you should use the Platform.runLater() method. This method allows you to enqueue a Runnable object to be executed on the JavaFX Application Thread, ensuring that UI updates are performed on the correct thread to avoid concurrency issues.

In which scenarios is it recommended to use synchronized blocks instead of synchronized methods?

  • When you don't want to use synchronization at all.
  • When you want to apply synchronization to a specific section of code within a method, providing more fine-grained control.
  • When you want to synchronize an entire method for simplicity.
  • When you want to synchronize multiple methods simultaneously.
Synchronized blocks are recommended when you want to apply synchronization to a specific section of code within a method, allowing more fine-grained control over synchronization. This can help reduce contention and improve performance in scenarios where synchronization is necessary. Synchronized methods are used when you want to synchronize the entire method for simplicity.

What is the output of the following code snippet: int[][] arr = new int[3][2]; System.out.println(arr.length);?

  • 2
  • 3
  • 6
  • The code will result in a compilation error.
In the given code, arr.length returns the number of rows in the 2D array. Here, arr is declared as a 2D array with 3 rows and 2 columns, so it prints 3, which is the number of rows.

If a method in an interface is declared without an access modifier, it is implicitly ________.

  • package-private (no modifier)
  • private
  • protected
  • public
In Java, if a method in an interface is declared without an access modifier, it is implicitly considered public. This means that the method is accessible from any class that implements the interface, even if it is in a different package. The other access modifiers (private, protected, and package-private) cannot be used for interface methods.

How can you manipulate request headers when using HttpURLConnection?

  • By altering the HTTP request method
  • By calling addRequestHeader method
  • By modifying the Content-Type header
  • By using the setRequestProperty method
To manipulate request headers in HttpURLConnection, you should use the setRequestProperty method. This method allows you to set custom headers for your HTTP request. Modifying the Content-Type header is one specific use case of this method. The other options are not standard ways to manipulate headers using HttpURLConnection.

Which of the following is not a valid JDBC transaction isolation level?

  • TRANSACTION_COMMITTED
  • TRANSACTION_NONE
  • TRANSACTION_REPEATABLE_READ
  • TRANSACTION_SERIALIZABLE
JDBC defines standard transaction isolation levels such as TRANSACTION_NONE, TRANSACTION_SERIALIZABLE, and TRANSACTION_REPEATABLE_READ. However, TRANSACTION_COMMITTED is not a valid JDBC transaction isolation level. Isolation levels determine how transactions interact with each other and the data.

Which method removes the first occurrence of the specified element from a LinkedList?

  • delete()
  • deleteFirst()
  • remove()
  • removeFirst()
The remove() method in a LinkedList is used to remove the first occurrence of the specified element. It takes the element as an argument and searches for its first occurrence, then removes it. removeFirst() is not a standard method in LinkedList. deleteFirst() and delete() are not valid methods for removing elements in a LinkedList.

How can you cancel a task submitted to ExecutorService using Future?

  • future.cancel(true)
  • future.interrupt()
  • future.shutdown()
  • future.stop()
In Java, you can cancel a task submitted to an ExecutorService using the cancel method on a Future object. The argument true passed to cancel(true) means an attempt to interrupt the task, while false means attempting a graceful cancellation. Using stop() and interrupt() is not recommended for canceling tasks, and shutdown() is used to shut down the entire ExecutorService, not to cancel a specific task.

The ________ class in Java creates an immutable sequence of characters.

  • CharArray
  • String
  • StringBuffer
  • StringBuilder
In Java, the String class creates an immutable sequence of characters. This means that once a string is created, its content cannot be changed. The other options, StringBuilder, StringBuffer, and CharArray, are used for mutable character sequences.