Networking Basics
Networking Basics
#### 6. In UDP communication, which class is used to send and receive packets?
A) Socket
B) ServerSocket
C) DatagramSocket
D) URLConnection
**Answer:** C
#### 10. Which exception is thrown when there is an error in networking operations?
A) IOException
B) SQLException
C) FileNotFoundException
D) ClassNotFoundException
**Answer:** A
#### 13. Which class provides a way to create URL connections in Java?
A) URLConnection
B) HttpURLConnection
C) Socket
D) DatagramSocket
**Answer:** A
#### 16. Which method is used to read data from a socket’s input stream?
A) read()
B) receive()
C) get()
D) accept()
**Answer:** A
#### 17. Which of the following can be used to create a simple web server in Java?
A) HttpServer
B) WebSocket
C) ServerSocket
D) RMI
**Answer:** A
#### 19. Which protocol is used to securely transmit data over a network?
A) HTTP
B) FTP
C) HTTPS
D) TCP
**Answer:** C
#### 23. How do you create a socket connection to a specific host and port?
A) new Socket(host, port)
B) Socket.create(host, port)
C) Socket.connect(host, port)
D) Socket.bind(host, port)
**Answer:** A
#### 24. Which class is used to read and write data over a socket?
A) DataOutputStream
B) BufferedReader
C) FileReader
D) All of the above
**Answer:** D
#### 25. What does the `getLocalHost()` method of the `InetAddress` class return?
A) The hostname of the local machine
B) The IP address of the local machine
C) Both hostname and IP address
D) The MAC address of the local machine
**Answer:** B
#### 27. Which class allows for the creation of a multithreaded server?
A) ServerSocket
B) Socket
C) Thread
D) MultiSocket
**Answer:** C
#### 30. Which Java class is used for sending and receiving multicast packets?
A) MulticastSocket
B) DatagramSocket
C) Socket
D) ServerSocket
**Answer:** A
#### 32. Which Java class is typically used for sending data to a web server?
A) Socket
B) HttpURLConnection
C) URL
D) DataOutputStream
**Answer:** B
#### 34. Which of the following is NOT a feature of the TCP protocol?
A) Connection-oriented
B) Reliable delivery
C) Flow control
D) Broadcast support
**Answer:** D
#### 35. What type of communication does the `URLConnection` class support?
A) HTTP only
B) FTP only
C) Both HTTP and FTP
D) No protocols
**Answer:** C
#### 37. In which layer of the OSI model does TCP operate?
A) Application
B) Transport
C) Network
D) Data Link
**Answer:** B
#### 38. Which command is used to bind a server socket to a specific port?
A) bind()
B) listen()
C) accept()
D) connect()
**Answer:** A
#### 39. What type of stream does the `Socket` class provide for reading and writing?
A) BufferedStream
B) InputStream and OutputStream
C) FileStream
D) DataStream
**Answer:** B
#### 41. Which method of the `Socket` class is used to retrieve the remote address?
A) getPort()
B) getInetAddress()
C) getRemoteHost()
D) getAddress()
**Answer:** B
#### 42. What is a primary use case for the `ServerSocket` class?
A) To manage file uploads
B) To create a socket that listens for incoming connections
C) To send data to a client
D) To manage database connections
**Answer:** B
#### 43. What is the difference between `InputStream` and `Reader` in Java?
A) `InputStream` is for binary data, `Reader` is for character data
B) `InputStream` is for character data, `Reader` is for binary data
C) Both are the same
D) `Reader` is deprecated
**Answer