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.

Which JavaFX layout class allows you to arrange components in a resizable grid of rows and columns?

  • BorderPane
  • FlowPane
  • GridPane
  • HBox
The GridPane layout class in JavaFX is used to create a grid-based layout where components can be arranged in rows and columns. This layout is suitable for resizable grids, making it ideal for creating forms and other structured interfaces. Components can be placed in specific grid cells, allowing for precise positioning and alignment.

What is the output of the following code snippet: for(int i = 0; i < 5; i++) { System.out.print(i + " "); }?

  • 0 1 2 3 4
  • 0 1 2 3 4 5
  • 1 2 3 4
  • 1 2 3 4 5
The correct output is "0 1 2 3 4." This is because the loop initializes i to 0, iterates as long as i is less than 5, and increments i by 1 in each iteration. It prints the value of i followed by a space in each iteration. When i reaches 5, the loop terminates.

In a JavaFX application, you have a scenario where a button should become visible only after a sequence of animations has completed. How would you implement this to ensure a smooth UI experience?

  • Manually add a delay between animations and make the button visible using the setVisible method after the delay.
  • Use a ParallelTransition to run animations simultaneously, ensuring that the button appears at the right moment during the animations.
  • Use a SequentialTransition to combine all animations in a sequence and add a ChangeListener to the last animation to make the button visible when it completes.
  • Use a Timeline to schedule the button's visibility change at a specific time relative to the animations.
In JavaFX, for a smooth UI experience, you can use a SequentialTransition to combine animations in a sequence. By adding a ChangeListener to the last animation, you can make the button visible when the sequence completes. This approach ensures synchronization. Using a ParallelTransition won't guarantee the button's visibility at the right time. Manually adding a delay is less reliable and can lead to timing issues. Using a Timeline is not the optimal choice for sequencing animations.

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.