Which index of a multi-dimensional array represents the row index in Java?

  • First index
  • It depends on the array's dimensions.
  • Second index
  • Third index
In Java, for a multi-dimensional array, the first index represents the row index. For a 2D array, it represents the row number, and for a 3D array, it represents the depth along the first dimension. The other indices represent the columns (2nd index), and if applicable, additional dimensions.

Which class allows you to read lines of text from a file?

  • BufferedReader
  • FileReader
  • InputStreamReader
  • Scanner
The BufferedReader class is commonly used for reading lines of text from a file in Java. It provides methods like readLine() that allow you to read a complete line of text at a time. While other classes like FileReader and Scanner can also be used for reading files, BufferedReader is preferred for its efficiency and ease of use when reading lines of text.

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.

How does the FileWriter class handle character encoding?

  • It always uses the system's default character encoding.
  • It automatically detects and sets the appropriate character encoding.
  • It doesn't support character encoding; it writes bytes as is.
  • It prompts the user to choose the encoding when creating an instance.
The FileWriter class in Java uses the system's default character encoding for writing text to a file. It doesn't automatically detect or set character encoding. To specify a different encoding, you should use constructors like FileWriter(String fileName, Charset charset) to explicitly set the encoding.

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.