The process of hiding the internal details of a class and showing only the things that are necessary is known as ________.

  • Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism
In Java, encapsulation is the process of hiding the internal details of a class and exposing only the essential parts. It helps in maintaining the integrity of the class and prevents unauthorized access to its data. This concept is fundamental to object-oriented programming.

Which of the following event types is not a mouse event in JavaFX?

  • KeyEvent
  • MouseDragEvent
  • MouseEvent
  • TouchEvent
In JavaFX, KeyEvent is not a mouse event; it represents keyboard events. Mouse events, such as MouseEvent and MouseDragEvent, are related to mouse input. TouchEvent deals with touch input. Understanding the distinction between these event types is essential when working with JavaFX event handling.

Which exception type must be explicitly handled or declared to be thrown in a method?

  • Checked exceptions
  • Errors
  • None of the above
  • Unchecked exceptions (Runtime)
In Java, checked exceptions (which extend the Exception class but not RuntimeException) must be explicitly handled or declared to be thrown in a method. This requirement ensures that the code handles potentially problematic situations.

In which case(s) does Binary Search perform in O(1) time complexity?

  • When the array is empty
  • When the target element is at the first index of the array
  • When the target element is at the middle of the array
  • When the target element is not present in the array
Binary Search performs in O(1) time complexity when the target element is at the first index of the sorted array. In this case, it can directly access the element and return it. When the array is empty, it still performs in O(1) time complexity as there are no elements to search. In other cases, it performs in O(log n) time complexity, where 'n' is the number of elements in the array.

Which of the following is a valid constructor declaration in Java?

  • MyConstructor() {}
  • public MyConstructor() {}
  • public int MyConstructor() {}
  • void MyConstructor() {}
In Java, a valid constructor declaration doesn't specify a return type, and its name should match the class name. So, MyConstructor() {} is a valid constructor declaration. The other options are invalid because they specify a return type or access modifier.

In which scenario is a Do-While loop most appropriately used as compared to other loop structures?

  • When you know the exact number of iterations required.
  • When you need a loop with a fixed number of iterations.
  • When you need to execute the loop body at least once.
  • When you want to iterate through a collection.
A do-while loop is most appropriate when you need to execute the loop body at least once, regardless of the condition. It is useful when you want to ensure that a certain part of your code runs before checking the loop condition. This is different from other loop structures like for and while, where the loop body may not execute if the initial condition is false.

Which class is used to create a server-side socket that waits for client requests?

  • Server
  • ServerSocket
  • SocketListener
  • SocketServer
In Java, the ServerSocket class is used to create a server-side socket that listens for incoming client requests. It's an essential part of building network servers. The other options do not represent the correct class for this purpose.

Which of the following classes provides a resizable array, which can grow as needed?

  • Array
  • ArrayList
  • LinkedList
  • Vector
The ArrayList class in Java provides a resizable array that can grow dynamically as elements are added. It is part of the java.util package and is widely used for dynamic collections. LinkedList, while useful for certain scenarios, is not specifically designed as a resizable array like ArrayList. Array represents a fixed-size array, and Vector is similar to ArrayList but is synchronized, making it less efficient in most cases.

Which searching algorithm would work even if the data is not sorted?

  • Binary Search
  • Linear Search
  • Merge Sort
  • Quick Sort
Linear Search is an algorithm that can work effectively on unsorted data. It sequentially checks each element in the list until a match is found or the list is exhausted. Other algorithms like Binary Search require the data to be sorted.

What is the purpose of the serialVersionUID field and how does it play a role during deserialization?

  • It determines whether an object can be serialized or not
  • It helps prevent security vulnerabilities in deserialization
  • It is a randomly generated unique identifier
  • It specifies the version of the class, ensuring compatibility during deserialization
The serialVersionUID field is used to specify the version of a class during serialization. It plays a crucial role during deserialization by ensuring compatibility. If the version of the class that was serialized differs from the version during deserialization, it can lead to InvalidClassException. This field helps maintain compatibility and avoid issues. The other options are not the primary purpose of serialVersionUID.