623). Which of these package contains classes and interfaces for networking?
[A]java.io
[B]java.util
[C]java.net
[D]java.network
Show Answer
Correct Answer: java.net
Notes:
Answer: c
Explanation: None.
624). Which of these is a protocol for breaking and sending packets to an address across a network?
[A]TCP/IP
[B]DNS
[C]Socket
[D] Proxy Server
Show Answer
Correct Answer: TCP/IP
Notes:
Answer: a
Explanation: TCP/IP – Transfer control protocol/Internet Protocol is used to break data into small packets an send them to an address across a network.
625). How many ports of TCP/IP are reserved for specific protocols?
[A]10
[B]1024
[C]2048
[D]512
Show Answer
Correct Answer: 1024
Notes:
Answer: b
Explanation: None.
626). How many bits are in a single IP address?
Show Answer
Correct Answer: 32
Notes:
Answer: c
Explanation: None.
627). Which of these is a full form of DNS?
[A]Data Network Service
[B] Data Name Service
[C]Domain Network Service
[D] Domain Name Service
Show Answer
Correct Answer: Domain Name Service
Notes:
Answer: d
Explanation: None.
628). Which of these class is used to encapsulate IP address and DNS?
[A]DatagramPacket
[B]URL
[C]InetAddress
[D]ContentHandler
Show Answer
Correct Answer: InetAddress
Notes:
Answer: c
Explanation: InetAddress class encapsulate both IP address and DNS, we can interact with this class by using name of an IP host.
629). What will be the output of the following Java program?
import java.net.*;
class networking
{
public static void main(String[] args) throws UnknownHostException
{
InetAddress obj1 = InetAddress.getByName("sanfoundry.com");
InetAddress obj2 = InetAddress.getByName("sanfoundry.com");
boolean x = obj1.equals(obj2);
System.out.print(x);
}
}
[A]0
[B]1
[C]true
[D]false
Show Answer
Correct Answer: true
Notes:
Answer: c
Explanation: None.
Output:$ javac networking.java
$ java networking
true
630). What will be the output of the following Java program?
import java.net.*;
public class networking
{
public static void main(String[] args) throws UnknownHostException
{
InetAddress obj1 = InetAddress.getByName("cisco.com");
InetAddress obj2 = InetAddress.getByName("sanfoundry.com");
boolean x = obj1.equals(obj2);
System.out.print(x);
}
}
[A]0
[B]1
[C]true
[D]false
Show Answer
Correct Answer: false
Notes:
Answer: d
Explanation: InetAddress obj1 = InetAddress.getByName(“cisco.com”); creates object obj1 having DNS and IP address of cisco.com, InetAddress obj2 = InetAddress.getByName(“sanfoundry.com”); creates obj2 having DNS and IP address of sanfoundry.com, since both these address point to two different locations false is returned by obj1.equals(obj2);.
Output:
$ javac networking.java
$ java networking
false
631). What will be the output of the following Java program?
import java.io.*;
import java.net.*;
public class URLDemo
{
public static void main(String[] args)
{
try
{
URL url=new URL("https://www.sanfoundry.com/java-mcq");
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: http
[B]Host Name: www.sanfoundry.com
[C]Port Number: -1
[D]All of the mentioned
Show Answer
Correct Answer: All of the mentioned
Notes:
Answer: d
Explanation: getProtocol() give protocol which is http
getUrl() give name domain name
getPort() Since we have not explicitly set the port, default value that is -1 is printed.
632). What will be the output of the following Java program?
import java.net.*;
class networking
{
public static void main(String[] args) throws UnknownHostException
{
InetAddress obj1 = InetAddress.getByName("cisco.com");
System.out.print(obj1.getHostName());
}
}
[A]cisco
[B]cisco.com
[C]www.cisco.com
[D]none of the mentioned
Show Answer
Correct Answer: cisco.com
Notes:
Answer: b
Explanation: None.
Output:
$ javac networking.java
$ java networking
cisco.com