0% found this document useful (0 votes)
6 views11 pages

24a - w10 - MCQ - Final

Uploaded by

sannutha24
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)
6 views11 pages

24a - w10 - MCQ - Final

Uploaded by

sannutha24
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/ 11

NPTEL Online Certification Courses

Indian Institute of Technology Kharagpur


NOC24-CS105 (July-2024 24A)

PROGRAMMING IN JAVA
Assignment 10
TYPE OF QUESTION: MCQ
Number of questions: 10 Total marks: 10 × 1 = 10

QUESTION 1:

What will be the output of the following Java program?

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

b. Host Name: nptel.ac.in

c. Port Number: -1

d. All of the men oned

Correct Answer:

d. All of the men oned

Detailed Solu on:


NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

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:

What will be the output of the following Java program?

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

d. None of the men oned

Correct Answer:

b. nptel.ac.in

Detailed Solu on:

The host name is nptel.ac.in. It is printed when getHostName() is called.


NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:

Which class provides methods to work with URLs?

a. URLConnec on

b. H pURL

c. NetURL

d. URL

Correct Answer:

d. URL

Detailed Solu on:

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

Detailed Solu on:

UnknownHostException is thrown if no IP address for the host could be found, or if a scope_id


was specified for a global IPv6 address.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:

Which class provides methods to create a client-side socket in Java?

a. ServerSocket

b. NetSocket

c. Socket

d. ClientSocket

Correct Answer:

c. Socket

Detailed Solu on:

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:

Which of the following statement is TRUE?

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.

Detailed Solu on:

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?

a. Socket s = new Socket(ServerName, port);

b. Socket s = serverSocket.accept()

c. Socket s = serverSocket.getSocket()

d. Socket s = new Socket(ServerName);

Correct Answer:

b. Socket s = serverSocket.accept()

Detailed Solu on:

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:

Which of the following is/are application layer protocol(s)?

a. TCP

b. UDP

c. ARP

d. SMTP

Correct Answer:

d. SMTPv

Detailed Solu on:

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:

In the following URL, identify the Resource name?

h ps://nptel.ac.in

a. h ps

b. nptel.ac.in

c. ac.in

d. nptel

Correct Answer:

b. nptel.ac.in

Detailed Solu on:

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:

What does this Java code snippet do?

import java.net.*;

public class NPTEL {


public static void main(String[] args) {
try {
InetAddress address = InetAddress.getByName("nptel.ac.in");
System.out.println("Host Name: " + address.getHostName());
System.out.println("IP Address: "+ address.getHostAddress());
} catch (Exception e) {
System.out.println(e);
}
}
}

a. Just prints the IP address of the local machine

b. Prints the IP address and host name of the local machine

c. Prints the IP address and host name of "nptel.ac.in"

d. Just prints the IP address of "nptel.ac.in"

Correct Answer:

c. Prints the IP address and host name of "nptel.ac.in"

Detailed Solu on:

The code snippet retrieves and prints the IP address and host name of the specified domain
"nptel.ac.in".
Output:

Host Name: nptel.ac.in


IP Address: 216.239.34.21

You might also like