How can you access variables in the surrounding scope from a lambda expression?

  • They are automatically accessible within the lambda.
  • You can access them using the super keyword.
  • You cannot access them.
  • You need to pass them as parameters to the lambda expression.
To access variables from the surrounding scope within a lambda expression, you typically need to pass them as parameters to the lambda expression. This is known as "capturing" variables. Lambda expressions in Java can access effectively final local variables and instance variables. Attempting to access non-final variables can result in compilation errors.

The method ________ is used to execute SQL for DDL statements using JDBC.

  • executeDDL()
  • executeQuery()
  • executeStatement()
  • executeUpdate()
In JDBC, the method executeUpdate() is used to execute SQL statements that perform Data Definition Language (DDL) operations, such as creating, altering, or dropping database objects. It returns an integer representing the number of rows affected by the statement. executeQuery() is used for retrieving data, not DDL statements.

If a class has multiple constructors, it can be said to have constructor ________.

  • chaining
  • overloading
  • overriding
  • polymorphism
When a class has multiple constructors with different parameter lists, it is said to have constructor overloading. Constructor overloading allows you to create multiple constructors in the same class, each with a different set of parameters. This is a form of method overloading specific to constructors. Constructor overriding is not a valid term in Java.

The ________ method is used to move the thread into the Ready/Runnable state.

  • join()
  • sleep()
  • start()
  • wait()
The "start()" method is used to move a thread into the Ready/Runnable state in Java. When a thread is started using "start()", it becomes eligible for execution, and the JVM schedules it for execution at the appropriate time.

What is the role of the JavaFX Application Thread?

  • To execute long-running tasks without affecting the application's responsiveness.
  • To handle background tasks and data processing in a JavaFX application.
  • To manage the user interface (UI) and handle user input events.
  • To synchronize communication between the server and the client.
The JavaFX Application Thread, also known as the JavaFX UI thread, is responsible for managing the user interface (UI) and handling user input events in a JavaFX application. It ensures that UI updates and event handling are done in a thread-safe manner, preventing UI freezes and glitches. This thread is crucial for providing a responsive and smooth user experience in JavaFX applications.

What will be the output of the following code snippet: System.out.println(10 + 20 + "Hello" + 30 + 40);?

  • 100200Hello3040
  • 1020Hello3040
  • 5070Hello
  • Hello10203040
In Java, when you use the + operator with both numbers and strings, it performs left-to-right addition. So, the numbers are added first, and then the result is concatenated with the strings. The correct output is "1020Hello3040."

The “effectively final” concept in the context of Lambda expressions refers to ________.

  • Variables that are static
  • Variables that are unused
  • Variables that don't change
  • Variables with final keyword
In the context of Lambda expressions, "effectively final" refers to variables that are not supposed to change after they are initially assigned a value. Lambda expressions can capture and use local variables from their surrounding scope, but these variables must be effectively final, meaning they are not modified after being captured by the lambda. This is to ensure the consistency of captured variables in the lambda's behavior.

To check whether the socket is bound, the ________ method can be used.

  • boundStatus()
  • checkBound()
  • isBound()
  • verifySocketBound()
In Java, you can use the isBound() method to check whether a socket is bound or not. This method returns true if the socket is bound, otherwise false.

Which method is typically overridden to handle an event in JavaFX?

  • handle()
  • handleEvent()
  • init()
  • start()
In JavaFX, to handle an event, you typically override the handle() method. This method is part of the EventHandler interface, and you provide your custom event-handling logic within it. The other options, such as start(), are methods used for different purposes in JavaFX applications.

In which scenario would you choose an abstract class over an interface?

  • When you want to achieve complete abstraction and hide the implementation details of a class.
  • When you want to define constants and static methods that are common to a group of related classes.
  • When you want to ensure multiple inheritance of behavior without worrying about method implementation conflicts.
  • When you want to provide a common base class with some shared functionality and allow derived classes to implement additional methods.
You would choose an abstract class over an interface when you want to provide a common base class with some shared functionality and allow derived classes to implement additional methods. Abstract classes can have both abstract and concrete methods, making them suitable for situations where you need to provide a common structure along with partial implementation.