The method ________ is used to send HTTP GET request without parameters.
- doGet()
- executeGET()
- get()
- sendGET()
In Java, to send an HTTP GET request without parameters, you typically use the sendGET() method. This method is commonly used in HTTP client libraries to initiate a GET request to a specified URL. The other options are not standard methods for this purpose.
What will be the initial capacity of a HashSet when no size is defined during its creation?
- 0
- 10
- 16
- It will result in an error
When you create a HashSet in Java without specifying its initial capacity, it defaults to an initial capacity of 16. The capacity dynamically increases as needed when elements are added to the HashSet.
What will be the output of the following code snippet: public int add(int a, long b) { return a + b; } and public long add(int a, int b) { return a + b; }?
- Compilation Error: Ambiguous method call.
- Compilation Error: Duplicate method add with the same parameter types.
- Compilation Error: Mismatched return types.
- The code will run without errors, and the output will be the sum of a and b.
The code will result in a compilation error because both methods have the same name and the same parameter types (int and long). Java does not allow you to overload methods based solely on the return type. Overloaded methods must have different parameter lists. Overloading based on return types would lead to ambiguity.
The ________ method of DatagramSocket class is used to send a packet to a server.
- send()
- sendPacket()
- sendToServer()
- transmitPacket()
In Java, the send() method of the DatagramSocket class is used to send a packet to a server. It is a crucial method for working with UDP (User Datagram Protocol) sockets.
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.
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.
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 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 ________ 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.
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 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.
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.