The process of defining a new exception by extending an existing exception class is known as ________.

  • Customization of exception
  • Exception chaining
  • Exception creation
  • Exception handling
In Java, when you define a new exception by extending an existing exception class, it's called "Customization of exception." This process allows you to create your own exception classes that suit your application's specific needs while maintaining compatibility with Java's exception hierarchy.

Which of the following methods is used to read data from an InputStream object connected to a socket?

  • read()
  • readData()
  • readFromSocket()
  • readStream()
To read data from an InputStream object connected to a socket, you typically use the read() method. This method reads a single byte of data and returns an integer representation of that byte. You can then cast it to the appropriate data type. The other options are not standard methods for reading from sockets.

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.

Which of the following sorting algorithms is most efficient in terms of average-case time complexity?

  • Bubble Sort
  • Insertion Sort
  • Quick Sort
  • Selection Sort
Quick Sort is known for its efficiency in terms of average-case time complexity. It has an average-case time complexity of O(n log n) and is often faster than other sorting algorithms like Bubble Sort, Selection Sort, and Insertion Sort, which have worse average-case time complexities. Quick Sort's efficiency is achieved through a divide-and-conquer approach.

What will be the output of the following code: int x = 10; x *= 3;?

  • x is assigned the value 0
  • x is assigned the value 10
  • x is assigned the value 13
  • x is assigned the value 30
In this code, x is first assigned the value 10, and then the compound assignment operator *= multiplies it by 3. So, x will be assigned the value 30. The other options are incorrect as they don't represent the correct result of the code.

Which of the following statements about the String data type in Java is incorrect?

  • Strings can be compared using the == operator to check if they have the same content.
  • Strings can be created using string literals, such as "Hello, World!".
  • Strings in Java are a sequence of characters and are represented by the String class.
  • Strings in Java are mutable, meaning their content can be changed after creation.
The incorrect statement is that strings in Java can be reliably compared using the == operator. In Java, the == operator compares references for objects, not their content. To compare the content of two strings, you should use the equals() method. The other options accurately describe aspects of the String data type.

________ is a special type of statement, which is used to invoke a constructor of the same class.

  • Create
  • Instantiate
  • Super
  • This
The "this" keyword in Java is used to refer to the current instance of a class. When used as a statement, "this" is used to invoke the constructor of the same class. This makes option 4 ("This") the correct choice.

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.