Skip to main content

Important Web Design and Development Short Questions

Chapter: 21
Question 1:
How does a socket abstract the network?
Answer: A socket abstracts the network by providing an interface to send and receive data without needing to understand the underlying network mechanics. It is similar to how a file abstracts the hard drive.
Chapter: 21
Question 2:
What is the purpose of a port in socket programming?
Answer: A port is a transport address that processes listen to for connection requests. Ports enable communication over the network using specific protocols, such as TCP or UDP. Ports below 1024 are well-known ports used for standard services like FTP (21), HTTP (80), and TELNET (23).
Chapter: 21
Question 3:
How does a client connect to a server in socket programming?
Answer: The client creates a socket using the server's hostname and port number, connects to the server, and establishes a communication channel. The server listens on a specific port and accepts the client's connection request, leading to the creation of a new communication socket for the session.
Chapter: 21
Question 4:
What is the role of the server socket?
Answer: The server socket listens for incoming connection requests. It is not used for communication but solely to accept connections. Once a connection is accepted, a new communication socket is created for interacting with the client, allowing the server to continue listening for new requests.
Chapter: 21
Question 5:
What steps are involved in creating a simple client socket?
Answer: 1. Import required packages (java.net.*, java.io.*). 2. Connect/open a socket with the server using Socket s = new Socket("serverName", serverPort);. 3. Get I/O streams of the socket using s.getInputStream() and s.getOutputStream(). 4. Send/receive messages using the obtained streams. 5. Close the socket.
Chapter: 21
Question 6:
What are the steps to create a simple server socket?
Answer: 1. Import required packages (java.net.*, java.io.*). 2. Create a server socket with ServerSocket ss = new ServerSocket(serverPort);. 3. Wait for incoming connections using ss.accept();. 4. Get I/O streams from the communication socket. 5. Send/receive messages using the streams. 6. Close the socket.
Chapter: 21
Question 7:
How does the EchoServer handle incoming connections?
Answer: The EchoServer listens for incoming connections in a loop. When a connection request is received, it creates a new communication socket, retrieves the I/O streams, processes the client's message by appending "hello" to it, and sends it back to the client. The server then continues to listen for new connections.
Chapter: 21
Question 8:
What is the function of the PrintWriter class in socket communication?
Answer: PrintWriter is used to write data to the output stream of a socket. It simplifies sending text data over a socket and can automatically flush the output buffer if the second argument in the constructor is set to true.
Chapter: 21
Question 9:
How does the EchoClient interact with the EchoServer?
Answer: The EchoClient connects to the EchoServer using a socket, sends its name to the server, and receives a response from the server that appends "hello" to the name. The client then displays this response to the user through a message dialog box.
Chapter: 22
Question 10:
What is the purpose of serialization in Java?
Answer: Serialization in Java allows objects to be converted into a stream of bytes for storage or transmission. It enables saving an object's state to a file or sending it over a network. This process can then be reversed to recreate the original object, preserving its state.