Networking Basis
Networking Basis
3. Which method returns the local address to which the socket is bound?
a) getInetAddress()
b) getLocalAddress()
c) getSocketAddress()
d) getHostAddress()
Answer: b) getLocalAddress()
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)
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
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)
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()
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
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()
d) URLConnection
Answer: b) DatagramSocket