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 symbol is used in the syntax of a Lambda expression in Java?
- ->
- ::
- =>
- {}
In Java, the syntax of a lambda expression uses the -> symbol. It separates the lambda parameters from the lambda body and is a distinctive feature of lambda expressions, making them easy to identify in code.
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.
You are developing a real-time gaming application where certain operations need to be repeated at regular time intervals. Which looping mechanism and timing control statements would you use to achieve this without blocking the user interface?
- do-while loop and Thread.yield()
- for loop and System.nanoTime()
- forEach loop and System.currentTimeMillis()
- while loop and Thread.sleep()
In a real-time gaming application, you would typically use a while loop in combination with the Thread.sleep() method to introduce a delay between iterations without blocking the UI. The other options may not be suitable for achieving this specific timing control.
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.
What method is commonly used to execute SQL queries in Java?
- execute()
- executeQuery()
- executeStatement()
- executeUpdate()
In Java, the executeQuery() method is commonly used to execute SQL queries using JDBC. This method is specifically designed for executing SELECT queries and returns a ResultSet containing the query results. The other options (executeStatement(), executeUpdate(), and execute()) are not typically used for executing queries or have different purposes.
Imagine a situation where you are dealing with very large files that need to be read and processed, but you want to ensure that the system remains responsive and does not run out of memory. How would you implement file reading in this case?
- Read the entire file into memory using FileInputStream.
- Use a BufferedReader with a small buffer size.
- Implement a memory-mapped file using FileChannel and MappedByteBuffer.
- Use Scanner with a large buffer size.
To ensure responsiveness and prevent memory exhaustion when dealing with large files, it's best to use a BufferedReader with a reasonably small buffer size. This allows for efficient reading of the file without loading the entire content into memory. The other options are less efficient and may lead to memory issues.