Java Sockets and Server Communication

Last Updated :
Discuss
Comments

Question 1

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

  • A

    Socket

  • B

    ServerSocket

  • C

    DatagramSocket

  • D

    SocketChannel

Question 2

Which protocol does a Java ServerSocket use by default?

  • A

    UDP

  • B

    HTTP

  • C

    TCP

  • D

    FTP

Question 3

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

  • A

    Requires handshaking before data transfer

  • B

    Packets are delivered reliably in order

  • C

    No dedicated connection is established

  • D

    Guarantees message delivery


Question 4

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


  • A

    open()

  • B

    connect()

  • C

    listen()

  • D

    accept()

Question 5

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

  • A

    It automatically closes itself

  • B

    It keeps consuming system resources

  • C

    It throws an exception immediately

  • D

    It terminates the JVM


Question 6

Which class in Java is typically used for UDP communication?

  • A

    Socket


  • B

    ServerSocket


  • C

    DatagramSocket


  • D

    SocketChannel

Question 7

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

  • A

    new ServerSocket(5000);


  • B

    ServerSocket.bind(5000);


  • C

    ServerSocket.connect(5000);


  • D

    ServerSocket.listen(5000);


Question 8

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

  • A

    connect() method of ServerSocket


  • B

    open() method of Socket


  • C

    Socket constructor with server IP and port

  • D

    listen() method of Socket

Question 9

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

  • A

    TCP does not guarantee order of delivery


  • B

    TCP creates a dedicated connection between client and server

  • C

    TCP is faster but less reliable than UDP


  • D

    TCP uses connectionless transmission

Question 10

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

  • A

    Encrypt communication

  • B

    Handle file I/O

  • C

    Facilitate data transfer between server and client

  • D

    Detect connection drops

There are 10 questions to complete.

Take a part in the ongoing discussion