Which method is used to display a stage in JavaFX?

  • displayStage()
  • openStage()
  • primaryStage()
  • showStage()
In JavaFX, the show() method is used to display a stage. When you create a JavaFX application, you typically create a Stage object and use its show() method to make it visible. The other options are not valid methods for displaying a stage.

How can CSS be applied to style JavaFX components?

  • By attaching external CSS files to the JavaFX application using the addStylesheet() method.
  • By calling the applyCSS() method on the entire scene graph.
  • By using JavaScript code embedded in the JavaFX application.
  • By using the setStyle() method to apply inline CSS directly to individual components.
CSS can be applied to style JavaFX components by attaching external CSS files to the application using the addStylesheet() method. This allows for a separation of concerns between the application logic and its styling. It provides flexibility and maintainability in designing the user interface. Inline CSS can also be used for individual components, but it's not the standard way to style JavaFX applications.

The keyword ________ is used to apply restrictions on class, method, and variable.

  • final
  • private
  • protected
  • static
The keyword "private" is used to apply restrictions on class members. It restricts access to only within the same class, making it the most restrictive access modifier in Java.

Which of the following methods can be used to create a stream from a collection?

  • filter()
  • forEach()
  • mapToDouble()
  • stream()
You can create a stream from a collection in Java using the stream() method. This method is available on all collections and provides a way to obtain a stream that allows you to perform various stream operations on the elements of the collection. Options 2 to 4 are not used to create streams but for other stream operations.

What is the difference between a synchronized block and a synchronized method?

  • Synchronized blocks are used for asynchronous programming.
  • Synchronized blocks can be used to synchronize multiple sections of code within the same method.
  • Synchronized methods are more efficient than synchronized blocks.
  • Synchronized methods can only be used to synchronize the entire method.
The key difference between a synchronized block and a synchronized method is that synchronized blocks can be used to synchronize multiple sections of code within the same method, providing more fine-grained control over synchronization. In contrast, synchronized methods synchronize the entire method. Synchronized methods are not necessarily more efficient than synchronized blocks; their efficiency depends on the specific use case.

You are developing a payroll system. How would you design a class for storing employee details and ensuring that some sensitive information (like salary) cannot be accessed directly from the object?

  • Define private instance variables for employee details, including salary, and provide public get and set methods for accessing and modifying the salary.
  • Define public instance variables for employee details and make the salary variable final.
  • Define public static variables for employee details, including salary, and use the 'protected' access modifier.
  • Use the 'volatile' keyword for sensitive information like salary.
To ensure that sensitive information like salary cannot be accessed directly from the object, you should define private instance variables for employee details and provide public get and set methods for salary. This follows the principle of encapsulation, which restricts direct access to sensitive data. The other options do not provide adequate security for sensitive information.

Which of the following is a primitive data type in Java?

  • ArrayList
  • Boolean
  • String
  • int
In Java, primitive data types are basic data types that store single values. int is one of the primitive data types and is used to store integer values. String, ArrayList, and Boolean are not primitive data types; they are reference data types or classes.

Imagine a situation where you need to insert a large dataset (for example, 10,000 rows) into a database using JDBC. How would you optimize this process to ensure that it is done efficiently and does not consume excessive resources?

  • Disable database constraints temporarily during the insertion process.
  • Execute individual INSERT statements in a loop for each row in the dataset.
  • Increase the database transaction isolation level to SERIALIZABLE for the insertion operation.
  • Use batch processing with prepared statements to insert multiple rows in a single database call.
Batch processing with prepared statements is the most efficient way to insert a large dataset into a database using JDBC. It reduces the overhead of multiple database calls by grouping multiple insertions into a single call. Executing individual INSERT statements in a loop is resource-intensive and not recommended for large datasets. Disabling database constraints can compromise data integrity. Increasing the transaction isolation level to SERIALIZABLE is not needed for a simple insertion operation.

The collect() method in the Stream API is a type of ________ operation.

  • Intermediate
  • Stateful
  • Stateless
  • Terminal
The collect() method is a terminal operation in the Stream API. It is used to accumulate the elements of a stream into a collection, such as a List or Set. Terminal operations are those that trigger the processing of the stream and produce a final result.

In a real-world application managing user profiles, how might parameterized constructors be used to quickly initialize user objects with provided details during registration?

  • Parameterized constructors are not used for user profile initialization.
  • Parameterized constructors are used for data retrieval from the database.
  • Parameterized constructors are used to create admin profiles with elevated privileges.
  • Parameterized constructors can accept user details as parameters and create user objects with initialized data during registration.
Parameterized constructors can be utilized in a user profile management system to quickly initialize user objects during the registration process. These constructors accept user details (e.g., username, email, password) as parameters, allowing you to create user objects with pre-populated data, making registration more efficient and straightforward.