Chapter 4 MCQ
Chapter 4 MCQ
Networking Basics
1. What does the acronym "HTTP" stand for in the context of web communication?
A. Hyperlink Transfer Protocol B. Hypertext Transfer Protocol
C. Hyper Transfer Text Protocol D. High-Speed Text Protocol
2. In Java, which class is commonly used to establish a server socket for network communication?
A. Socket B. ServerSocket C. DatagramSocket D. InetAddress
3. Which Java package provides classes for working with sockets and networking?
A. java.net B. java.io C. java.lang D. java.util
7. In Java, which protocol is used for transferring files over the network?
A. HTTP B. FTP C. TCP D. UDP
8. Which Java class is used to read and write binary data over a network stream?
A. BufferedReader B. BufferedWriter C. ObjectInputStream D.DataInputStream
10. Which Java class allows you to create and manage URL objects?
A. URLBuilder B. URLManager C. URLEncoder D. URLConnection
13. Which protocol is commonly used for sending email in Java applications?
a) FTP b) SMTP c) HTTP d) Telnet
15. Which Java library is commonly used for making HTTP requests?
a) java.net b) javax.servlet c) java.http d) java.httpclient
18. Which Java class is used for handling UDP (User Datagram Protocol) communication?
a) DatagramSocket b) UDPSocket c) DatagramConnection d) UDPConnection
19. Which Java class is used for reading from and writing to streams?
a) Stream b) InputStream c) OutputStream d) StreamReader
21. Which Java method is used to establish a connection to a remote server using TCP/IP?
a) connect() b) open() c) accept() d) bind()
22. Which protocol is used for secure communication over the internet?
a) SSL b) HTTP c) FTP d) Telnet
26. In Java, which protocol is commonly used for sending and receiving email?
a. FTP b. SMTP c. HTTP d. POP3
28. Which Java class is used for reading and writing data to a network socket?
a. ServerSocket b. Socket c. DatagramSocket d. InputStreamReader
32. Which exception is typically thrown when a network operation fails in Java?
a. NetworkException b. IOException c. MalformedURLException d. DataFormatException
33. Which Java class is commonly used to establish a client-server connection for network communication?
a) Socket b) Datagram c) URLConnection d) HttpRequest
35. Which class is used to create servers that listen for either local client or remote client programs?
a. ServerSockets b. httpServer c. httpResponse d. None of the above
48. Which class can be used to create a server socket. This object is used to establish communication with the clients?
A. ServerSocket B. Socket C. Both A & B D. None of the above
49. Which methods are commonly used in ServerSocket class?
A. public OutputStream getOutputStream() B. public Socket accept()
C. public synchronized void close() D. None of the above
52. The URLConnection class can be used to read and write data to the specified resource referred by the URL?
A. True B. False
54. In InetAddress class which method it returns the host name of the IP Address?
A. public String getHostName() B. public String getHostAddress()
C. public static InetAddress getLocalHost() D. None of the above
a. Correct b. Incorrect
a. Yes b. No
a. Correct b. Incorrect
60. Check out whether the following code contains error(s) or not.
import javax.net.*;
public class Net1
{
public static void main(String arg[])throws MaiformedURLException
{
61. Check out whether the following code contains error(s) or not.
import java.io.*;
import java.net.*;
import java.util.Date;
public class URLINFORMATION
{
public static void main(String args[])
{
URL =new URL("http://www.msbte.com");
URLConnection con = url.openConnection();
System.out.println("");
System.out.println(url);
System.out.println("Date:"+new Date(con.getDate()));
System.out.println("Content-Type"+con.getContentType());
System.out.println("Expiers:"+con.getExpiration());
System.out.println("Last-Modified:"+new Date(con.getLastModified()));
int len = con.getContentLength();
System.out.println("Content-Length:"+len);
}
}
a . Correct b. Incorrect
63. Which of the following Java code snippets correctly opens a server socket on port 8080?
64. Which Java code snippet is used to establish a client socket connection to a server at IP address "192.168.1.100" and port 12345?
65. Which of the following Java code snippets is used to set up a UDP socket for sending and receiving datagrams?
67. Which of the following Java code snippets correctly sends an HTTP GET request to a server at "example.com" on port 80?
68. You want to create a Java program to establish a client-server connection. Which code snippet correctly creates a client socket
and connects to a server running on "localhost" at port 8080?
69. You are developing a Java program to establish a server-client connection. Which code snippet correctly creates a server socket
that listens on port 8888 and accepts incoming connections from clients?