In a class instance, synchronized blocks can be used to avoid locking the entire method and only lock ________.
- the class instance
- the instance itself
- the method
- the thread
In Java, synchronized blocks allow you to lock specific portions of a method rather than locking the entire method. By using synchronized blocks, you can choose what specific data or code you want to protect from concurrent access by specifying the object that should serve as the lock, commonly referred to as "the method's ________."
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.
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 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.
In Java, constructors have the same name as the _______.
- Class
- Method
- Package
- Variable
In Java, constructors have the same name as the class in which they are defined. This naming convention allows you to identify and use the constructor associated with a particular class.
A variable declared as double d = 10.3; occupies ________ bytes of memory.
- 16
- 2
- 4
- 8
In Java, a variable of type "double" occupies 8 bytes of memory. The "double" data type is a 64-bit floating-point type that can hold both integer and fractional values. It requires 8 bytes to store its precision and range, making it suitable for storing large and decimal numbers with high precision.