The expression a != b returns true if a is ______ b.

  • equal to
  • greater than
  • less than
  • not equal to
The expression "a != b" returns true if "a" is not equal to "b." It checks if the values of "a" and "b" are different. The "!=" operator is used for inequality comparisons. The other options represent different comparison operations.

If we have a 2D array int[][] arr, the expression arr[i] refers to the __________.

  • an error
  • entire array
  • ith column of the array
  • ith row of the array
In a 2D array in Java, arr[i] refers to the ith row of the array. This is because a 2D array is essentially an array of arrays, where each element arr[i] is itself an array representing a row. Accessing arr[i] gives you the entire row at index i.

How does Binary Search perform when there are multiple occurrences of the search key in the data?

  • It returns an error due to ambiguity.
  • It returns the index of the first occurrence.
  • It returns the index of the last occurrence.
  • It returns the index of the middle occurrence.
Binary Search is designed to find the index of the last occurrence of the search key when there are multiple occurrences. This is because, in binary search, if a match is found, the algorithm continues searching in the right subarray to ensure it returns the last occurrence. This behavior is efficient for tasks like counting occurrences. The other options do not accurately describe the behavior of Binary Search in this context.

The setLength method, which allows altering the length of the character sequence stored in the object, is a method of ________.

  • CharArray
  • String
  • StringBuffer
  • StringBuilder
The setLength method is a method of the StringBuffer class in Java. It allows you to alter the length of the character sequence stored in the StringBuffer object. The other options are not related to the setLength method.

To avoid an infinite loop, the condition within the ________ loop must eventually be false.

  • infinite
  • inner
  • nested
  • outer
To prevent an infinite loop in Java, the condition within the outer loop must eventually evaluate to false. An infinite loop occurs when the loop condition is always true, and the loop keeps executing indefinitely. The other options are not directly related to the prevention of infinite loops.

The ________ block can be used to handle different types of exceptions in a single block.

  • catch
  • finally
  • throw
  • try
The try block is used to enclose a section of code that may throw exceptions. You can have multiple catch blocks after a single try block to handle different types of exceptions, making it possible to handle various exceptions in a unified way.

Which of the following methods returns the number of rows affected by the DML operation?

  • getRowCount()
  • getUpdateCount()
  • getResultCount()
  • getAffectedRowCount()
The correct method to retrieve the number of rows affected by a DML (Data Manipulation Language) operation in JDBC is getUpdateCount(). This method returns an integer representing the number of rows affected by the last executed query or update statement. Options a, c, and d are not standard JDBC methods for retrieving the row count affected by DML operations.

The ______ interface is implemented by classes that want to handle events of a specific type, with event type and event source defined as generic parameters.

  • ActionListener
  • EventHandler
  • EventListener
  • EventSource
In Java, the EventHandler interface is used for handling events of a specific type. It allows you to define the event type and event source as generic parameters, making it a versatile choice for handling various types of events in a type-safe manner. Classes that implement this interface can respond to events of the specified type.

Which method converts a given string to a sequence of characters?

  • charAt()
  • split()
  • toCharArray()
  • toString()
The toCharArray() method in Java's String class converts a given string into an array of characters, providing a sequence of characters. The other methods do not perform this specific task.

A ________ is used to create a client socket in Java.

  • DatagramSocket
  • InetAddress
  • ServerSocket
  • Socket
In Java, to create a client socket, you use the Socket class. It allows you to establish a connection to a remote server and communicate with it. The other options represent different types of socket classes in Java but are not used for creating client sockets.