How can a developer prevent a field from being serialized?

  • Mark the field as final.
  • Mark the field as private.
  • Mark the field as static.
  • Mark the field as transient.
In Java, to prevent a field from being serialized, you can mark it as transient. When a field is marked as transient, it will not be included in the serialization process. The other options do not directly prevent serialization. Marking a field as final has no impact on serialization. Marking it as static means the field will be serialized. Marking it as private affects only access, not serialization.

By using the keyword ________, a subclass can call a method defined in its superclass.

  • extends
  • inherit
  • override
  • super
In Java, the keyword used to call a method defined in the superclass from a subclass is super. It's commonly used to access overridden methods or constructors in the parent class.

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 synchronized method declaration?

  • public synchronized void myMethod() {}
  • public void myMethod() { synchronized() {} }
  • public void synchronized myMethod() {}
  • synchronized void myMethod() {}
The correct syntax for a synchronized method declaration in Java is public synchronized void myMethod() {}, where the synchronized keyword comes before the access modifier (public) and the return type (void). This ensures that only one thread can execute the myMethod at a time.

If a program encounters an issue while writing to a file and you haven’t handled exceptions, the program will ________.

  • continue execution
  • display an error message
  • pause execution
  • terminate without any error message
If a program encounters an issue while writing to a file and exceptions are not properly handled, the program will terminate abruptly without any error message. This can lead to unexpected behavior and data loss. It's crucial to handle exceptions when working with file I/O to gracefully manage errors and provide meaningful feedback.

The ______ class is used to deserialize objects in Java.

  • Deserializer
  • InputStream
  • ObjectInputStream
  • Serialization
In Java, the ObjectInputStream class is used to deserialize objects. Deserialization is the process of converting serialized objects back into their original form, and this class provides methods for reading objects from a stream. The other options are not responsible for deserialization.

The ________ interface in Java provides a way to traverse, filter, and extract data.

  • Collection
  • Iterable
  • Iterator
  • Stream
The Iterable interface in Java provides a way to traverse (iterate over) a collection of elements. It allows you to loop through the elements and perform operations on them. While it doesn't provide built-in filtering or extraction like Streams, it serves as a foundation for working with collections.