Engineering Questions with Answers - Multiple Choice Questions

MCQs on Socket Programming

1 - Question

Which methods are commonly used in Server Socket class?
a) Public Output Stream get Output Stream ()
b) Public Socket accept ()
c) Public synchronized void close ()
d) Public void connect ()

View Answer

Answer: b
Explanation: The Public socket accept () method is used by the ServerSocket class to accept the connection request of exactly one client at a time. The client requests by initializing the socket object with the servers IP address.




2 - Question

Which constructor of Datagram Socket class is used to create a datagram socket and binds it with the given Port Number?
a) Datagram Socket(int port)
b) Datagram Socket(int port, Int Address address)
c) Datagram Socket()
d) Datagram Socket(int address)

View Answer

Answer: b
Explanation: Datagram Socket (int port, Int Address address) is used to create a datagram socket. A datagram socket is created for connection-less communication between the server and the client. There is no accept() method in this class.




3 - Question

The client in socket programming must know which information?
a) IP address of Server
b) Port number
c) Both IP address of Server & Port number
d) Only its own IP address

View Answer

Answer: c
Explanation: The client in socket programming must know IP address of Server as it has to use that IP address in order to initialize the socket class constructor. That is how the client requests a connection to the server.




4 - Question

The URL Connection class can be used to read and write data to the specified resource that is referred by the URL.
a) True
b) False

View Answer

Answer: a
Explanation: The URL Connection class can be used to read and write data to the specified resource referred by the URL. A connection to the URL is initialized by the OpenConnection() method of the class.




5 - Question

Datagram is basically just a piece of information but there is no guarantee of its content, arrival or arrival time.
a) True
b) False

View Answer

Answer: a
Explanation: Datagram is basically some information travelling between the sender and the receiver, but there is no guarantee of its content, arrival or arrival time. A Datagram socket class object is created to make a datagram connection between the server and the client.




6 - Question

TCP, FTP, Telnet, SMTP, POP etc. are examples of ___________
a) Socket
b) IP Address
c) Protocol
d) MAC Address

View Answer

Answer: c
Explanation: TCP, FTP, Telnet, SMTP, POP etc. are examples of Protocol. Out of them, TCP is a transport layer protocol and FTP, TELNET, SMTP and POP are application layer protocols.




7 - Question

What does the java.net.InetAddress class represent?
a) Socket
b) IP Address
c) Protocol
d) MAC Address

View Answer

Answer: b
Explanation: The java.net.InetAddress class represents IP Address of a particular specified host. It can be used to resolve the host name from the IP address or the IP address from the host name.




8 - Question

The flush () method of Print Stream class flushes any un-cleared buffers in the memory.
a) True
b) False

View Answer

Answer: a
Explanation: The flush () method of Print Stream class flushes any un cleared buffers in memory.




9 - Question

Which classes are used for connection-less socket programming?
a) Datagram Socket
b) Datagram Packet
c) Both Datagram Socket & Datagram Packet
d) Server Socket

View Answer

Answer: c
Explanation: Datagram is basically some information travelling between the sender and the receiver, but there is no guarantee of its content, arrival or arrival time. Datagram Socket, Datagram Packet are used for connection-less socket programming, while Server Socket is used for connection-oriented socket programming.




10 - Question

In Inet Address class, which method returns the host name of the IP Address?
a) Public String get Hostname()
b) Public String getHostAddress()
c) Public static InetAddress get Localhost()
d) Public getByName()

View Answer

Answer: a
Explanation: In Inet Address class public String getHostname() method returns the host name of the IP Address. The getHostAddress() method returns the IP address of the given host name.

Get weekly updates about new MCQs and other posts by joining 18000+ community of active learners