A custom exception can be thrown using the ________ keyword followed by an object of the custom exception.

  • create
  • initiate
  • raise
  • throw
In Java, a custom exception can be thrown using the throw keyword followed by an object of the custom exception class. This allows you to handle specific exceptional situations that may not be covered by built-in exceptions. It's an essential part of creating robust and specialized exception handling in Java applications.

Which method is used to execute SQL queries in JDBC?

  • executeQuery()
  • executeSQL()
  • executeStatement()
  • executeUpdate()
The executeQuery() method in JDBC is used to execute SQL queries that return a ResultSet, typically used for SELECT statements. The executeUpdate() method is used for executing SQL queries that modify the database, such as INSERT, UPDATE, or DELETE statements. The other options mentioned are not valid JDBC methods.

You are tasked with developing a system where the order of elements matters and you have frequent insertions and deletions. Which List implementation would be preferable and why?

  • ArrayList
  • HashSet
  • LinkedList
  • Vector
In a scenario with frequent insertions and deletions where the order of elements matters, a LinkedList is preferable. LinkedList offers efficient insertions and deletions because it doesn't require shifting elements like ArrayList. Vector is a synchronized version of ArrayList and might introduce unnecessary synchronization overhead if not needed. HashSet is not a List implementation and doesn't preserve order.

What is the purpose of the start() method in a JavaFX application?

  • It defines the application's GUI components.
  • It handles user input events.
  • It initializes the application's resources.
  • It is the entry point for launching the app.
The start() method is the entry point for a JavaFX application. It is automatically called by the JavaFX framework when the application starts. Within this method, you set up the initial state of your application, create the main user interface, and configure event handling. This method serves as the starting point for building your JavaFX application.

Can an abstract class have a constructor in Java?

  • It depends on the class
  • No
  • Yes, always
  • Yes, but with restrictions
Yes, an abstract class can have a constructor in Java. However, there are some restrictions. The constructor of an abstract class is typically used to initialize the fields of the abstract class, and it can be called from subclasses using the super keyword.

Consider a scenario where multiple threads are executing tasks, but the main thread needs to wait until all tasks are complete before proceeding. How can this be achieved using Future and ExecutorService?

  • Use ExecutorService's awaitTermination() method to block the main thread until all tasks are completed.
  • Use ExecutorService's invokeAny() method to submit tasks and block the main thread until any one of the tasks completes.
  • Use ExecutorService's shutdown() method to ensure that all tasks are complete before proceeding with the main thread.
  • Use invokeAll() method of ExecutorService to submit tasks and obtain a list of Future objects, then call get() method on each Future object to block the main thread until tasks are complete.
In this scenario, you can use the invokeAll() method to submit tasks and obtain a list of Future objects representing each task. Calling the get() method on each Future object will block the main thread until all tasks are complete. This allows synchronization between the main thread and the worker threads.

A thread enters the ________ state once its run() method has completed execution.

  • Blocked
  • Runnable
  • Terminated
  • Waiting
A thread enters the "Terminated" state in Java once its "run()" method has completed execution. In this state, the thread has finished its task and is no longer actively executing code.

Which operators are overloaded for the String class in Java?

  • * (repetition)
  • + (concatenation)
  • - (subtraction)
  • / (division)
In Java, the + operator is overloaded for the String class, allowing you to concatenate strings using the + operator. Other operators like *, -, and / are not overloaded for String and would result in compilation errors if used inappropriately.

You are building a text editor in Java which reads large text files. How would you utilize character streams to read data from files, and why are character streams preferable in this scenario?

  • Use BufferedReader and BufferedWriter to create character streams, as they read and write character data in chunks.
  • Use FileInputStream and FileOutputStream to create character streams, as they can handle character data efficiently.
  • Use FileReader and FileWriter to create character streams, as they provide direct access to character data.
  • Use ObjectOutputStream and ObjectInputStream to create character streams, as they can serialize character objects.
In the context of a text editor reading large text files, using BufferedReader and BufferedWriter is preferable. These classes efficiently read and write character data in chunks, reducing the I/O overhead and improving performance. FileInputStream/FileOutputStream deal with bytes, FileReader/FileWriter are less efficient for large files, and ObjectOutputStream/ObjectInputStream are for object serialization.

The ________ interface of the JDBC API provides cursor support, which allows forward and backward navigation through the result set.

  • Connection
  • ResultSet
  • ResultSetMetaData
  • Statement
The ResultSet interface in the JDBC API provides cursor support, allowing you to navigate through the result set of a database query. You can move forward and backward, retrieve data, and perform various operations on the result set. The other options do not provide cursor support.