0% found this document useful (0 votes)
12 views11 pages

Networking Basics

The document covers fundamental concepts of networking in Java, including the purpose of the Socket class, networking packages, and methods for handling connections. It discusses various protocols, classes for creating server sockets, and the differences between InputStream and Reader. Additionally, it addresses exceptions, port numbers, and key characteristics of TCP and UDP communication.

Uploaded by

lochansawant0107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views11 pages

Networking Basics

The document covers fundamental concepts of networking in Java, including the purpose of the Socket class, networking packages, and methods for handling connections. It discusses various protocols, classes for creating server sockets, and the differences between InputStream and Reader. Additionally, it addresses exceptions, port numbers, and key characteristics of TCP and UDP communication.

Uploaded by

lochansawant0107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

NETWORKING BASICS

1. What is the primary purpose of the Java `Socket` class?


A) To read data from files
B) To establish a connection between two networked devices
C) To create a user interface
D) To manage database connections
Answer: B

#### 2. Which package is used for networking in Java?


A) java.net
B) java.io
C) java.util
D) java.nio
**Answer:** A

#### 3. Which class is used to create a server socket?


A) ServerSocket
B) Socket
C) DatagramSocket
D) URL
**Answer:** A

#### 4. What method is used to accept incoming connections in a server socket?


A) connect()
B) accept()
C) listen()
D) receive()
**Answer:** B
#### 5. Which protocol is commonly used for reliable data transmission?
A) UDP
B) FTP
C) HTTP
D) TCP
**Answer:** D

#### 6. In UDP communication, which class is used to send and receive packets?
A) Socket
B) ServerSocket
C) DatagramSocket
D) URLConnection
**Answer:** C

#### 7. What is the default port number for HTTP?


A) 21
B) 80
C) 443
D) 25
**Answer:** B

#### 8. Which method is used to close a socket in Java?


A) shutdown()
B) close()
C) disconnect()
D) terminate()
**Answer:** B

#### 9. What is the purpose of the `InetAddress` class?


A) To establish a network connection
B) To represent an IP address
C) To manage threads
D) To encrypt data
**Answer:** B

#### 10. Which exception is thrown when there is an error in networking operations?
A) IOException
B) SQLException
C) FileNotFoundException
D) ClassNotFoundException
**Answer:** A

#### 11. What type of socket is used for connectionless communication?


A) StreamSocket
B) DatagramSocket
C) ConnectionSocket
D) ServerSocket
**Answer:** B

#### 12. Which method is used to retrieve the IP address of a hostname?


A) getHostName()
B) getHostAddress()
C) getAddress()
D) getByName()
**Answer:** D

#### 13. Which class provides a way to create URL connections in Java?
A) URLConnection
B) HttpURLConnection
C) Socket
D) DatagramSocket
**Answer:** A

#### 14. How do you specify a timeout for a socket connection?


A) setTimeout()
B) setSoTimeout()
C) configureTimeout()
D) establishTimeout()
**Answer:** B

#### 15. What is the main characteristic of a client-server architecture?


A) Multiple clients communicate with a single server
B) Clients cannot send data
C) Servers are always local
D) All data is encrypted
**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

#### 18. What is the purpose of the `setReuseAddress()` method in sockets?


A) To enable multiple sockets to bind to the same address
B) To set the socket timeout
C) To close the socket
D) To encrypt the data
**Answer:** A

#### 19. Which protocol is used to securely transmit data over a network?
A) HTTP
B) FTP
C) HTTPS
D) TCP
**Answer:** C

#### 20. What does a URL consist of?


A) Protocol, host, port, path, query
B) Host, port, data
C) Protocol, data
D) Host, path
**Answer:** A

#### 21. What is the purpose of the `OutputStream` class in networking?


A) To read data from a source
B) To write data to a destination
C) To manage network connections
D) To encrypt data
**Answer:** B
#### 22. Which of the following is a method of the `HttpURLConnection` class?
A) connect()
B) send()
C) dispatch()
D) relay()
**Answer:** A

#### 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

#### 26. What does the acronym "DNS" stand for?


A) Data Network Service
B) Domain Name System
C) Digital Name Server
D) Direct Network Service
**Answer:** B

#### 27. Which class allows for the creation of a multithreaded server?
A) ServerSocket
B) Socket
C) Thread
D) MultiSocket
**Answer:** C

#### 28. What is the purpose of the `BufferedReader` class in networking?


A) To buffer outgoing data
B) To read characters from a stream
C) To handle binary data
D) To compress data
**Answer:** B

#### 29. What is the default port number for HTTPS?


A) 80
B) 443
C) 21
D) 25
**Answer:** B

#### 30. Which Java class is used for sending and receiving multicast packets?
A) MulticastSocket
B) DatagramSocket
C) Socket
D) ServerSocket
**Answer:** A

#### 31. What is the result of calling `close()` on a socket?


A) It encrypts the data
B) It closes the connection and releases resources
C) It sends a disconnect message
D) It only logs the action
**Answer:** B

#### 32. Which Java class is typically used for sending data to a web server?
A) Socket
B) HttpURLConnection
C) URL
D) DataOutputStream
**Answer:** B

#### 33. What is the main use of the `DataInputStream` class?


A) To read binary data from a network connection
B) To write binary data to a file
C) To send text data
D) To manage URLs
**Answer:** A

#### 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

#### 36. Which exception indicates that a socket is not connected?


A) SocketTimeoutException
B) SocketException
C) UnknownHostException
D) EOFException
**Answer:** B

#### 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

#### 40. What is a primary characteristic of UDP?


A) Reliable delivery
B) Connection-oriented
C) Low overhead and faster transmission
D) Guaranteed delivery
**Answer:** C

#### 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

You might also like