The keyword ________ is used within a constructor to call another constructor in the same class.
- constructor()
- extend()
- super()
- this()
In Java, the this() keyword is used within a constructor to call another constructor in the same class. This is called constructor chaining and allows you to reuse code logic among constructors in a class. The super() keyword is used to call a constructor of the superclass. The other options are not valid for constructor invocation.
Can a constructor return a value in Java?
- Yes, a constructor can return a value, which is the default value of the class's primary data type.
- No, constructors cannot return values in Java.
- A constructor can return values, but only if it has the same name as the class.
- A constructor can return values, but they must be of type 'void.'
b) is correct. Constructors in Java cannot return values, and their return type is always 'void.' a), c), and d) are incorrect statements.
To execute a batch of commands, we use the ________ method.
- execute()
- executeBatch()
- executeQuery()
- executeUpdate()
In JDBC, the executeBatch() method is used to execute a batch of SQL commands in a single call to the database. This can be more efficient than executing each command individually, especially when you need to perform multiple operations in a single batch, such as inserts, updates, or deletes.
If a and b are boolean expressions, then a & b is true only if ______.
- a or b
- both a and b
- either a or b
- neither a nor b
In Java, the '&' operator is a bitwise AND operator. To perform a logical AND operation on boolean expressions, you should use '&&' instead. It returns true if both 'a' and 'b' are true.
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.