Java Sockets and Server Communication

Here are 10 essential multiple-choice questions on Java Sockets and Server Communication, covering key concepts.

Last Updated :
Discuss
Comments

Question 1

In Java socket programming, which class is used to listen for incoming client requests on the server side?

  • Socket

  • ServerSocket

  • DatagramSocket

  • SocketChannel

Question 2

Which protocol does a Java ServerSocket use by default?

  • UDP

  • HTTP

  • TCP

  • FTP

Question 3

Which of the following is a characteristic of a connectionless protocol?

  • Requires handshaking before data transfer

  • Packets are delivered reliably in order

  • No dedicated connection is established

  • Guarantees message delivery


Question 4

In socket programming, which method is used by the server to wait for a client to connect?


  • open()

  • connect()

  • listen()

  • accept()

Question 5

What happens if you don't close a socket after communication?

  • It automatically closes itself

  • It keeps consuming system resources

  • It throws an exception immediately

  • It terminates the JVM


Question 6

Which class in Java is typically used for UDP communication?

  • Socket


  • ServerSocket


  • DatagramSocket


  • SocketChannel

Question 7

In server socket programming, which line correctly binds the server to port 5000?

  • new ServerSocket(5000);


  • ServerSocket.bind(5000);


  • ServerSocket.connect(5000);


  • ServerSocket.listen(5000);


Question 8

In a typical Java TCP server-client communication, the client uses which method to initiate the connection?

  • connect() method of ServerSocket


  • open() method of Socket


  • Socket constructor with server IP and port

  • listen() method of Socket

Question 9

Which statement about TCP is true in the context of socket communication?

  • TCP does not guarantee order of delivery


  • TCP creates a dedicated connection between client and server

  • TCP is faster but less reliable than UDP


  • TCP uses connectionless transmission

Question 10

What is the role of InputStream and OutputStream in socket programming?

  • Encrypt communication

  • Handle file I/O

  • Facilitate data transfer between server and client

  • Detect connection drops

There are 10 questions to complete.

Take a part in the ongoing discussion