0% found this document useful (0 votes)
98 views8 pages

Chapter 4 MCQ

Uploaded by

Mharukh Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views8 pages

Chapter 4 MCQ

Uploaded by

Mharukh Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Chapter 4.

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

4. Which protocol is typically used for sending email in Java applications?


A. HTTP B. FTP C. SMTP D. POP3

5. Which Java class is used to represent an IP address?


A. IPAdress B. InetAddress C. IPHost D. HostAddress

6. What is the purpose of the "URLConnection" class in Java?


A. To represent a URL connection B. To establish a secure SSL connection
C. To handle HTTP requests and responses D. To encode and decode URLs

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

9. What is the role of the "SocketTimeoutException" in Java networking?


A. It indicates a successful network connection.
B. It occurs when a socket is closed gracefully.
C. It signals a timeout when waiting for data on a socket.
D. It represents an error in the socket's IP address.

10. Which Java class allows you to create and manage URL objects?
A. URLBuilder B. URLManager C. URLEncoder D. URLConnection

11. What does HTTP stand for in the context of networking?


a) Hyper Transfer Text Protocol b) Hypertext Transfer Protocol
c) Hyperlink Text Transfer Protocol d) Hypertext Transmission Protocol

12. Which Java class is used for creating network sockets?


a) Socket b) ServerSocket c) DatagramSocket d) InetAddress

13. Which protocol is commonly used for sending email in Java applications?
a) FTP b) SMTP c) HTTP d) Telnet

14. In Java, which class is used to represent an IP address?


a) IP b) IPAddress c) InetAddress d) InetAddressUtils

15. Which Java library is commonly used for making HTTP requests?
a) java.net b) javax.servlet c) java.http d) java.httpclient

16. What does DNS stand for?


a) Dynamic Network System b) Domain Name System c) Data Network Service d) Digital Network Security

17. Which port is commonly used for HTTP communication?


a) 21 b) 80 c) 443 d) 8080

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

20. What is the primary purpose of a firewall in a network?


a) To increase network speed b) To block all incoming and outgoing traffic
c) To protect the network from unauthorized access and threats d) To reroute network traffic

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

23. What is the purpose of the InetAddress class in Java?


a) To represent IP addresses b) To establish socket connections c) To send emails d) To read from files

24. Which of the following is not a valid IP address format?


a) 192.168.1.1 b) 300.200.100.50 c) 10.0.0.1 d) 172.16.0.0

25. Which Java class is used for creating a server socket?


a) SocketServer b) ServerSocket c) TCPServer d) NetworkServer

26. In Java, which protocol is commonly used for sending and receiving email?
a. FTP b. SMTP c. HTTP d. POP3

27. What is the purpose of the HttpURLConnection class in Java?


a. To connect to a database b. To establish a secure connection
c. To work with HTTP connections d. To create a UDP socket

28. Which Java class is used for reading and writing data to a network socket?
a. ServerSocket b. Socket c. DatagramSocket d. InputStreamReader

29. In Java networking, what is the purpose of the InetAddress.getByName() method?


a. To get the IP address of a domain name b. To retrieve the host's hostname
c. To set the local host's IP address d. To create a new InetAddress object

30. What is the role of the java.net.URL class in networking?


a. To read and write files locally b. To manage database connections
c. To represent a Uniform Resource Locator d. To encrypt data during transmission

31. Which Java package is commonly used for socket programming?


a. java.sql b. java.io c. java.util d. java.net

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

34. Which of these class is used to encapsulate IP address and DNS?


a) DatagramPacket b) URL c) InetAddress d) ContentHandler

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

36. What does IP stand for in networking?*


a. Internet Protocol b. Internet Port c. Internal Protocol d. Internet Portability

37. Which class in Java allows you to create a client socket?


a. ServerSocket b. Socket c. DatagramSocket d. InetAddress

38. Which socket type is used for UDP communication in Java?


a. DatagramSocket b. ServerSocket c. Socket d. MulticastSocket

39. What is the main advantage of TCP over UDP in networking?


a. Lower latency b. Connection-oriented c. Suitable for broadcasting d. Simple error handling

40. Which of these class is used to encapsulate IP address and DNS?


a) DatagramPacket b) URL c) InetAddress d) ContentHandler

41. The client in socket programming must know which informations?


a. IPaddress of Server b. Port number c. Both A & B d. None of the above
42. What does the java.net.InetAddress class represent?
a. Socket b. IP Address c. Protocol d. MAC Address
43. Which classes are used for connection-less socket programming?
a. DatagramSocket b. DatagramPacket c. Both A & B d.None of the above

44. 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

45. Show some networking terminologies given below?


A. IP Address B. Protocol C. MAC Address D. All mentioned above

46. TCP,FTP,Telnet,SMTP,POP etc. are examples of ?


A. Socket B. IP Address C. Protocol D. MAC Address

47. Which classes are used for connection-oriented socket programming?


A. Socket B. ServerSocket C. Both A & B 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

50. URL is an acronym for?


A. Uniform Resource Locator B. Unified Resource Locator C. Uniform Restore Locator D. Unified Restore Locator

52. The URLConnection class can be used to read and write data to the specified resource referred by the URL?
A. True B. False

53. The java.net.InetAddress class represents an?


A. Socket B. IP Address C. Protocol D. MAC Address

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

55. Which classes are used for connection-less socket programming?


A. DatagramSocket B. DatagramPacket C. Both A & B D. None of the above

56 . Check whether the following code is correct or not?


import javax.net.*;
import java.io.*;
public class Net1
{
public static void main(String args[])
{
try
{
InetAddress ip=InetAddress.getByName("www.javapoint.com");
System.out.println("Host Name: "+ip.getHostName());
System.out.println("Host Address: "+ip.getHostAddress());
}
catch(Exception e)
{
System.out.println(e);
}
}
}

a. Correct b. Incorrect

57. Figure out the error(s) in the following code?


import javax.net.*;
import java.io.*;
public class Net1
{
public static void main(String args[])
{
try
{
InetAddress ip=InetAddress.getByName("www.javapoint.com");
System.out.println("Host Name: "+ip.getHostNam());
System.out.println("Host Address: "+ip.getHostAddress());
}
catch(Exception e)
{
System.out.println(e);
}
}
}

a. In import package b. In Try c. In System.out.println d. Both (a) and (c)

58. In the following code, do we require try-catch compulsorily?


import javax.net.*;
import java.io.*;
public class Net1
{
public static void main(String args[])
{
try
{
InetAddress ip=InetAddress.getByName("www.javapoint.com");
System.out.println("Host Name: "+ip.getHostName());
System.out.println("Host Address: "+ip.getHostAddress());
}
catch(Exception e)
{
System.out.println(e);
}
}
}

a. Yes b. No

59. Check whether the following code is correct or not?


import javax.net.*;
public class Net1
{
public static void main(String args[])throws Exception
{
URL u=new URL("https://www.google.com");
System.out.println("Protocol: "+u.getProtocol());
System.out.println("Port: "+u.getPort());
System.out.println("Host: "+u.getHost());
System.out.println("File: "+u.getFile());
System.out.println("Ref: "+u.getRef());
System.out.println("Exit: "+u.getExternalForm());
}
}

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
{

URL u=new URL("https://www.google.com");


System.out.println("Protocol: "+u.getProtocol());
System.out.println("Port: "+u.getPort());
System.out.println("Host: "+u.getHost());
System.out.println("File: "+u.getFile());
System.out.println("Ref: "+u.getRef());
System.out.println("Exit: "+u.getExternalForm());
}
}

a. No Errors Present b.Errors Present

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. In URLConnection Line b. In URlCreation Line

c. Both (a) and (b) d. None

62. Check whether the following code is correct or not?


import java.io.*;
import java.net.*;
public class InetDemo222
{
public static void main(String args[])
{
try
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(address);
address = InetAddress.getByName("www.google.com");
System.out.println(address);
InetAddress sw[] = InetAddress.getAllByName("www.yahoo.com");
for(int i=0; i<sw.length;i++)
{
System.out.println(sw[i]);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}

a . Correct b. Incorrect

63. Which of the following Java code snippets correctly opens a server socket on port 8080?

(A) ServerSocket = new ServerSocket(8080);


(B) Socket serverSocket = new ServerSocket(8080);
(C) ServerSocket = new Socket(8080);
(D) Socket = new Socket();
socket.bind(new InetSocketAddress(8080));

a. (A) b. (B) c. (C) d. (D)

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?

(A) Socket = new Socket("192.168.1.100", 12345);


(B) Socket = new Socket(12345, "192.168.1.100");
(C) Socket = new Socket("192.168.1.100");
socket.connect(new InetSocketAddress(12345));
(D) ServerSocket = new ServerSocket(12345);
Socket socket = serverSocket.accept();

a. (A) b. (B) c. (C) d. (D)

65. Which of the following Java code snippets is used to set up a UDP socket for sending and receiving datagrams?

(A) Socket socket = new Socket();


(B) DatagramSocket datagramSocket = new DatagramSocket();
(C) ServerSocket serverSocket = new ServerSocket();
(D) DatagramSocket datagramSocket = new DatagramSocket(12345);

a. (A) b. (B) c. (C) d. (D)


66. In Java, which of the following code snippets demonstrates how to read data from a client socket using an InputStream?

(A) Socket socket = new Socket("localhost", 8080);


DataOutputStream out = new DataOutputStream(socket.getOutputStream());
(B) ServerSocket serverSocket = new ServerSocket(8080);
Socket socket = serverSocket.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
(C) Socket socket = new Socket("localhost", 8080);
DataInputStream in = new DataInputStream(socket.getInputStream());
(D) Socket socket = new Socket("localhost", 8080);
OutputStream out = socket.getOutputStream();

a. (A) b. (B) c. (C) d. (D)

67. Which of the following Java code snippets correctly sends an HTTP GET request to a server at "example.com" on port 80?

(A) Socket socket = new Socket("example.com", 80);


PrintWriter out = new PrintWriter(socket.getOutputStream());
out.println("GET / HTTP/1.1");
(B) Socket socket = new Socket("example.com", 80);
OutputStream out = socket.getOutputStream();
PrintWriter writer = new PrintWriter(out);
writer.println("GET / HTTP/1.1");
(C) Socket socket = new Socket("example.com", 80);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
writer.write("GET / HTTP/1.1");
(D) URL url = new URL("http://example.com");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

a. (A) b. (B) c. (C) d. (D)

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?

(A) Socket clientSocket = new Socket("localhost", 8080);


(B) ServerSocket serverSocket = new ServerSocket(8080);
(C) DatagramSocket datagramSocket = new DatagramSocket(8080);
(D) Socket clientSocket = new Socket("localhost");

a. (A) b. (B) c. (C) d. (D)

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?

(A) ServerSocket serverSocket = new ServerSocket(8888);


(B) Socket serverSocket = new Socket("localhost", 8888);
(C) Socket serverSocket = new Socket(8888);
(D) ServerSocket serverSocket = new ServerSocket("localhost", 8888);

a. (A) b. (B) c. (C) d. (D)

You might also like