24a - w10 - MCQ - Final
24a - w10 - MCQ - Final
PROGRAMMING IN JAVA
Assignment 10
TYPE OF QUESTION: MCQ
Number of questions: 10 Total marks: 10 × 1 = 10
QUESTION 1:
import java.net.*;
public class NPTEL {
public static void main(String[] args) {
try {
URI uri = new URI("https://nptel.ac.in/");
URL url = uri.toURL();
System.out.println("Protocol: " + url.getProtocol());
System.out.println("Host Name: " + url.getHost());
System.out.println("Port Number: " + url.getPort());
} catch (Exception e) {
System.out.println(e);
}
}
}
a. Protocol: h ps
c. Port Number: -1
Correct Answer:
getProtocol() give protocol which is h ps. getUrl() give name domain name which is
nptel.ac.in. getPort() Since the port has not been explicitly set, default value that is -1 is printed.
Output:
Protocol: https
Host Name: nptel.ac.in
Port Number: -1
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 2:
import java.net.*;
class NPTEL {
public static void main(String[] args) throws UnknownHostException {
InetAddress obj1 = InetAddress.getByName("nptel.ac.in");
System.out.print(obj1.getHostName());
}
}
a. nptel
b. nptel.ac.in
c. www.nptel.ac.in
Correct Answer:
b. nptel.ac.in
QUESTION 3:
a. URLConnec on
b. H pURL
c. NetURL
d. URL
Correct Answer:
d. URL
The URL class provides methods to work with Uniform Resource Locators.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 4:
Which exception is thrown when a connection cannot be established with a remote server?
a. IOExcep on
b. UnknownHostExcep on
c. Connec onExcep on
d. NetworkExcep on
Correct Answer:
b. UnknownHostExcep on
QUESTION 5:
a. ServerSocket
b. NetSocket
c. Socket
d. ClientSocket
Correct Answer:
c. Socket
The Socket class in the java.net package is used to create client-side sockets.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 6:
a. With stream sockets there is no need to establish any connec on and data flows between the
processes are as con nuous streams.
b. Stream sockets are said to provide a connec on-less service and UDP protocol is used
c. Datagram sockets are said to provide a connec on-oriented service and TCP protocol is used
d. With datagram sockets there is no need to establish any connec on and data flows between
the processes are as packets.
Correct Answer:
d. With datagram sockets there is no need to establish any connec on and data flows between
the processes are as packets.
The datagram sockets allow communica on without establishing any connec on.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 7:
The server listens for a connection request from a client using which of the following statement?
b. Socket s = serverSocket.accept()
c. Socket s = serverSocket.getSocket()
Correct Answer:
b. Socket s = serverSocket.accept()
In server-client communica on using sockets, the server typically listens for incoming connec on
requests from clients. When a client a empts to connect to the server, the server must accept this
connec on request to establish a connec on.
The serverSocket.accept() method is used by the server to listen for and accept incoming
connec on requests from clients. When a client a empts to connect, serverSocket.accept()
blocks un l a connec on is made, and then it returns a new Socket object represen ng the connec on
between the server and the client.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 8:
a. TCP
b. UDP
c. ARP
d. SMTP
Correct Answer:
d. SMTPv
Applica on layer protocols are protocols that operate at the highest layer of the OSI model and are used
for specific types of data communica on tasks performed between programs running on different
devices. They include protocols such as HTTP, FTP, SMTP, POP3, etc.
TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are transport layer protocols.
ARP (Address Resolu on Protocol) operates at the data link layer.
TCP, UDP are transport layer protocols. ARP is a Network - IP layer protocol. SMTP is Applica on layer
protocol.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 9:
h ps://nptel.ac.in
a. h ps
b. nptel.ac.in
c. ac.in
d. nptel
Correct Answer:
b. nptel.ac.in
Resource name is nptel.ac.in. In the URL h ps://nptel.ac.in, the resource name typically refers to the
domain name or hostname, which in this case is nptel.ac.in. This por on of the URL iden fies the
specific server or resource loca on on the internet.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 10:
import java.net.*;
Correct Answer:
The code snippet retrieves and prints the IP address and host name of the specified domain
"nptel.ac.in".
Output: