QuizzesSocket Programming — Concept Check
intermediate
java

Socket Programming — Concept Check

Questions on Socket Programming. Java sockets enable low-level TCP and UDP communication between processes — the foundation of all networked Java applications.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Socket Programming — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A Java server application using ServerSocket starts experiencing slow response times as the number of clients increases. What is a likely cause?

    • AThe server is using virtual threads for each client.
    • BThe server is using a single thread for all clients.
    • CThe server is using a separate thread for each client.
    • DThe server is using NIO channels for client handling.
  2. 2.A developer uses DatagramSocket for a real-time game server. They notice some packets are missing. What should they do?

    • AUse a separate thread for each packet.
    • BSwitch to a higher port number.
    • CIncrease the buffer size of DatagramSocket.
    • DSwitch to TCP for guaranteed delivery.
  3. 3.In Java, when using NIO with a Selector, what happens if a channel is ready to read but the buffer is full?

    • AThe Selector will continue notifying readiness.
    • BThe channel will throw an IOException.
    • CThe channel will automatically clear the buffer.
    • DThe Selector will block until the buffer is cleared.
  4. 4.A developer mistakenly believes DatagramSocket ensures packet order. What might they observe?

    • APackets arriving out of order.
    • BPackets being dropped.
    • CPackets being duplicated.
    • DAll packets arriving in sequence.
  5. 5.What is the primary advantage of using NIO channels over traditional thread-per-connection models in Java?

    • ASimplified code structure.
    • BAutomatic connection management.
    • CReduced memory usage with fewer threads.
    • DGuaranteed packet delivery.
  6. 6.A Java application uses virtual threads for handling client connections. What is a potential benefit?

    • AAutomatic load balancing.
    • BReduced CPU usage per thread.
    • CScalability with many concurrent connections.
    • DGuaranteed message order.
  7. 7.What happens when ServerSocket.accept() is called in Java?

    • AIt starts a new thread for each client.
    • BIt throws an exception if no client connects.
    • CIt blocks until a client connects.
    • DIt immediately returns a new Socket.
  8. 8.A developer claims that TCP is faster than UDP for real-time applications. What is the flaw in this claim?

    • AUDP is slower because it lacks error checking.
    • BTCP uses smaller packets, increasing speed.
    • CTCP guarantees delivery, making it faster.
    • DUDP is generally faster due to lower overhead.