0% found this document useful (0 votes)
23 views13 pages

Networking Basis

The document contains a series of multiple-choice questions and answers related to Java networking concepts, including socket programming, HTTP connections, and protocols. Key topics include methods for setting timeouts, creating secure sockets, handling datagram packets, and understanding connection-oriented versus connectionless protocols. It serves as a quiz or study guide for individuals looking to test their knowledge of Java networking.

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)
23 views13 pages

Networking Basis

The document contains a series of multiple-choice questions and answers related to Java networking concepts, including socket programming, HTTP connections, and protocols. Key topics include methods for setting timeouts, creating secure sockets, handling datagram packets, and understanding connection-oriented versus connectionless protocols. It serves as a quiz or study guide for individuals looking to test their knowledge of Java networking.

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/ 13

Networking Basis

1. Which method is used to set a timeout for reading from a Socket?


a) setSo Timeout()
b) setTimeout()
c) setTimeLimit()
d) setConnectionTimeout()
Answer: a) setSoTimeout()

2. Which class is used to create a secure server socket?


a) SSLSocket
b) SSLServerSocket
c) HTTPSocket
d) SecureSocket
Answer: b) SSLServerSocket

3. Which method returns the local address to which the socket is bound?
a) getInetAddress()
b) getLocalAddress()
c) getSocketAddress()
d) getHostAddress()
Answer: b) getLocalAddress()

4. Which method is used to set the request method in HttpURLConnection?


a) setMethod()
b) setRequestType()
c) setRequestMethod()
d) setPostMethod()
Answer: c) setRequestMethod()
5. Which class represents a socket address with IP and port number in Java?
a) InetSocketAddress
b) SocketAddress
c) InetAddress
d) PortAddress
Answer: a) InetSocketAddress

6. Which of the following protocols is connection-oriented?


a) UDP
b) TCP
c) HTTP
d) FTP
Answer: b) TCP

7. Which method of DatagramPacket class retrieves the length of the data?


a) getSize()
b) getLength()
c) getDataSize()
d) getPacketLength()
Answer: b) getLength()

8. Which of the following is a common error while creating a socket connection?


a) SocketTimeoutException
b) NullPointerException
c) ArrayIndexOutOfBoundsException
d) FileNotFoundException
Answer: a) SocketTimeoutException
9. Which of the following methods is used to flush the output stream in
HttpURLConnection?
a) flush()
b) finish()
c) write()
d) getOutputStream()
Answer: a) flush()

10. Which method is used to create a datagram packet for receiving data in DatagramSocket?
a) createPacket()
b) getPacket()
c) DatagramPacket(byte[] buf, int length)
d) setReceivePacket()
Answer: c) DatagramPacket(byte[] buf, int length)

11. What is the default value for SO_TIMEOUT in a socket?


a) 0 (no timeout)
b) 30 seconds
c) 60 seconds
d) 10 seconds
Answer: a) 0 (no timeout)

12. Which class in Java is used to resolve hostnames?


a) InetSocketAddress
b) URL
c) InetAddress
d) NetworkInterface
Answer: c) InetAddress
13. Which method is used to retrieve the protocol from a URL object?
a) getProtocol()
b) getScheme()
c) getType()
d) getService()
Answer: a) getProtocol()

14. What is the default port for SMTP?


a) 21
b) 25
c) 80
d) 110
Answer: b) 25

15. Which of the following classes implements the Secure Socket Layer (SSL) in Java?
a) SSLServerSocket
b) SecureSocket
c) SSLSocket
d) SecureServerSocket
Answer: c) SSLSocket

16. How do you get the status code from an HttpURLConnection object?
a) getStatus()
b) getResponseCode()
c) getCode()
d) getStatusCode()
Answer: b) getResponseCode()
17. Which method of URL class can be used to obtain the path component of the URL?
a) getPath()
b) getDirectory()
c) getLocation()
d) getURI()
Answer: a) getPath()

18. Which exception is thrown when a DatagramSocket is closed while data is being
transmitted?
a) ClosedChannelException
b) SocketException
c) IOException
d) EOFException
Answer: b) SocketException

19. Which method is used to check if a socket is closed?


a) isClosed()
b) isSocketClosed()
c) isShut()
d) getStatus()
Answer: a) isClosed()

20. Which of the following represents a Connectionless communication model?


a) TCP
b) UDP
c) HTTP
d) FTP
Answer: b) UDP
21. Which method is used to get the port number of the local machine in a ServerSocket?
a) getLocalPort()
b) getPort()
c) getHostPort()
d) getSocketPort()
Answer: a) getLocalPort()

22. Which method is used to get the headers of an HttpURLConnection response?


a) getHeaderField()
b) getHeaders()
c) getResponseHeaders()
d) getResponseData()
Answer: a) getHeaderField()

23. What is the purpose of the DatagramSocket class in Java networking?


a) Sending connection-oriented data
b) Sending and receiving UDP packets
c) Establishing secure communication
d) Sending and receiving TCP packets
Answer: b) Sending and receiving UDP packets

24. Which method is used to retrieve the input stream from an HttpURLConnection?
a) getDataStream()
b) getContent()
c) getInputStream()
d) getStream()
Answer: c) getInputStream()
25. What is the use of MulticastSocket in Java?
a) For sending TCP data to multiple clients
b) For sending UDP packets to a multicast group
c) For connecting to multiple hosts
d) For establishing secure connections
Answer: b) For sending UDP packets to a multicast group

26. Which of the following is the default port number for FTP?
a) 21
b) 25
c) 110
d) 443
Answer: a) 21

27. How can you set the keep-alive option in a Socket object?
a) setKeepAlive(true)
b) enableKeepAlive()
c) setSocketOption()
d) setTimeout()
Answer: a) setKeepAlive(true)

28. What method is used to send a request in an HttpURLConnection object?


a) execute()
b) sendRequest()
c) connect()
d) send()
Answer: c) connect()
29. How do you enable automatic redirection handling in HttpURLConnection?
a) setInstanceFollowRedirects(true)
b) setRedirectEnabled(true)
c) enableRedirection()
d) allowRedirects(true)
Answer: a) setInstanceFollowRedirects(true)

30. Which of the following classes is used to send ICMP (ping) requests in Java?
a) DatagramPacket
b) ICMPPacket
c) InetAddress
d) Socket
Answer: c) InetAddress

31. Which method is used to retrieve all header fields from a HttpURLConnection object?
a) getHeaderFields()
b) getHeaders()
c) getResponseHeaders()
d) getAllFields()
Answer: a) getHeaderFields()

32. Which of the following is a valid way to create a DatagramSocket bound to a specific
port?
a) new DatagramSocket(port)
b) new DatagramSocket("localhost", port)
c) new DatagramSocket(InetAddress.getLocalHost())
d) new DatagramSocket(null, port)
Answer: a) new DatagramSocket(port)
33. How do you obtain the time-to-live (TTL) value for multicast in MulticastSocket?
a) getTimeToLive()
b) getTTL()
c) getSocketOption(TTL)
d) getTimeLimit()
Answer: a) getTimeToLive()

34. What is the default port for POP3?


a) 25
b) 110
c) 143
d) 443
Answer: b) 110

35. What type of protocol is HTTP/2 compared to HTTP/1.1?


a) Connectionless
b) Multiplexed
c) Stateless
d) Stateful
Answer: b) Multiplexed

36. How do you set a timeout for establishing a connection in HttpURLConnection?


a) setConnectTimeout()
b) setTimeout()
c) setSocketTimeout()
d) setTimeOutDuration()
Answer: a)
37. Which class is used to create a server socket in Java?
a) Socket
b) ServerSocket
c) DatagramSocket
d) URLConnection
Answer: b) ServerSocket

38. Which class represents an IP address in Java?


a) InetAddress
b) SocketAddress
c) IPAddress
d) URL
Answer: a) InetAddress

39. What is the maximum port number that can be used in Java networking?
a) 1024
b) 32767
c) 65535
d) 8192
Answer: c) 65535

40. Which method of ServerSocket waits for a client to connect?


a) listen()
b) accept()
c) connect()
d) bind()
Answer: b) accept()
41. Which method of Socket is used to send data to the server?
a) getInputStream()
b) getOutputStream()
c) send()
d) write()
Answer: b) getOutputStream()

42. Which protocol is used by the DatagramSocket class?


a) TCP
b) UDP
c) HTTP
d) FTP
Answer: b) UDP

43. How do you bind a server socket to a specific port number in Java?
a) bind()
b) connect()
c) accept()
d) listen()
Answer: a) bind()

44. Which Java class is used to send HTTP requests to a server?


a) URL
b) Socket
c) HttpURLConnection
d) ServerSocket
Answer: c) HttpURLConnection
45. Which method of the URL class opens a connection to the specified URL?
a) connect()
b) openConnection()
c) open()
d) execute()
Answer: b) openConnection()

46. What does the getHostName() method of InetAddress return?


a) IP address
b) Host name
c) MAC address
d) Subnet mask
Answer: b) Host name

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


a) disconnect()
b) shutdown()
c) close()
d) terminate()
Answer: c) close()

48. What is the main advantage of DatagramSocket over Socket?


a) Reliable
b) Faster but connectionless
c) Connection-oriented
d) Uses TCP
Answer: b) Faster but connectionless
49. Which class is used for sending and receiving packets in UDP communication?
a) Socket
b) DatagramSocketc) ServerSocket

d) URLConnection
Answer: b) DatagramSocket

50. Which method is used to send data using a DatagramSocket?


a) send()
b) write()
c) output()
d) transmit()
Answer: a) send()

You might also like