Welcome to the Java Networking Quiz! If you're new to Java or just want to brush up on your networking basics, you're in the right place. Let's dive into the questions to test your foundational knowledge of Java networking!
1. Which Java package is primarily used for networking?
Answer:
Explanation:
The java.net package provides the classes for implementing networking applications.
2. Which class is used to create a server socket?
Answer:
Explanation:
The ServerSocket class is used to create servers that listen for either local or remote client programs.
3. Which method is used to read data from an InputStream object?
Answer:
Explanation:
The read() method is used to read data from input streams.
4. What does the InetAddress class represent?
Answer:
Explanation:
The InetAddress class represents an IP address.
5. Which protocol ensures error-free data transmission?
Answer:
Explanation:
TCP (Transmission Control Protocol) ensures error-free data transmission by establishing a connection and checking for lost packets.
6. Which class provides methods to work with URLs?
Answer:
Explanation:
The URL class provides methods to work with Uniform Resource Locators.
7. Which exception is thrown when a connection cannot be established with a remote server?
Answer:
Explanation:
UnknownHostException is thrown if no IP address for the host could be found, or if a scope_id was specified for a global IPv6 address.
8. What is the default port number for HTTP?
Answer:
Explanation:
The default port for HTTP is 80.
9. Which class provides methods to create a client-side socket in Java?
Answer:
Explanation:
The Socket class in the java.net package is used to create client-side sockets.
10. Which Java class represents a socket address, consisting of an IP and port number?
Answer:
Explanation:
InetSocketAddress is a class that represents a socket address with an IP address and a port number.
11. Which class is used to create datagram packets?
Answer:
Explanation:
The DatagramPacket class is used to create datagram packets to be sent or received using UDP.
12. Which of the following is NOT a transport layer protocol?
Answer:
Explanation:
FTP stands for File Transfer Protocol and is an application layer protocol. TCP, UDP, and SCTP are all transport layer protocols.
13. What is the purpose of the bind() method in the ServerSocket class?
Answer:
Explanation:
The bind() method in the ServerSocket class is used to bind the server to a specific port number.
14. Which class is used to create an HTTP connection to a URL?
Answer:
Explanation:
HttpURLConnection is a subclass of URLConnection and provides methods to create an HTTP connection to a URL.
15. Which exception is thrown when a socket-related error occurs?
Answer:
Explanation:
While various exceptions can occur during networking tasks, SocketException is a common exception thrown for socket-related errors. Note that SocketException is a subclass of IOException.
16. Which method is used to get the output stream of a socket?
Answer:
Explanation:
The getOutputStream() method of the Socket class is used to retrieve the output stream of the socket.
17. What does URL stand for?
Answer:
Explanation:
URL stands for Uniform Resource Locator, which is used to specify addresses on the World Wide Web.
18. What is the primary difference between TCP and UDP?
Answer:
Explanation:
TCP establishes a connection before sending data, ensuring that all data packets arrive and are in order. UDP sends packets without setting up a connection and doesn't guarantee delivery or order.
19. Which method of the ServerSocket class is used to listen to client requests?
Answer:
Explanation:
The accept() method of the ServerSocket class listens for client requests and establishes a connection when a client request is received.
20. Which of the following is true about a Datagram socket?
Answer:
Explanation:
Datagram sockets use the UDP protocol (which is connectionless) to send and receive data in packets, without the need for an initial handshake or maintaining a persistent connection.
❮ Previous Quiz Next Quiz ❯
Comments
Post a Comment
Leave Comment