Java Multiple Choice Questions & Answers on Networking Basics for Freshers

1. Which of these package contains classes and interfaces for networking?

a) java.io
b) java.util
c) java.net
d) java.network
Answer: c
2. Which of these is a protocol for breaking and sending packets to an address across a network?

a) TCIP/IP
b) DNS
c) Socket
d) Proxy Server
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.
3. How many ports of TCP/IP are reserved for specific protocols?

a) 10
b) 1024
c) 2048
d) 512
Answer: b
4. How many bits are in a single IP address?

a) 8
b) 16
c) 32
d) 64
Answer: c
5. 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
Answer: d
6. Which of these class is used to encapsulate IP address and DNS?
a) DatagramPacket
b) URL
c) InetAddress
d) ContentHandler
Answer: c

Explanation: InetAddress class encapsulate both IP address and DNS, we can interact with this class by using name of an IP host.
7. What is the output of this program?
  1.     import java.net.*;
  2.     class networking {
  3.         public static void main(String[] args) throws UnknownHostException {
  4.             InetAddress obj1 = InetAddress.getByName("sanfoundary.com");
  5.             InetAddress obj2 = InetAddress.getByName("sanfoundary.com");
  6.             boolean x = obj1.equals(obj2); 
  7.             System.out.print(x);
  8.         }
  9.     }
a) 0
b) 1
c) true
d) false
Answer: c
8. What is the output of this program?
  1.     import java.net.*;
  2.     class networking {
  3.         public static void main(String[] args) throws UnknownHostException {
  4.             InetAddress obj1 = InetAddress.getByName("cisco.com");
  5.             InetAddress obj2 = InetAddress.getByName("sanfoundary.com");
  6.             boolean x = obj1.equals(obj2); 
  7.             System.out.print(x);
  8.         }
  9.     }
a) 0
b) 1
c) true
d) false
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);.
9. What is the output of this program?
  1. import java.io.*;  
  2. import java.net.*;  
  3. public class URLDemo {  
  4.     public static void main(String[] args) {  
  5.         try {  
  6.             URL url=new URL("http://www.sanfoundry.com/java-mcq");  
  7.             System.out.println("Protocol: "+url.getProtocol());  
  8.             System.out.println("Host Name: "+url.getHost());  
  9.             System.out.println("Port Number: "+url.getPort());   
  10.         } catch(Exception e){System.out.println(e);}  
  11.     }  
  12. }
a) Protocol: http
b) Host Name: www.sanfoundry.com
c) Port Number: -1
d) all above mentioned
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.
10. What is the output of this program?
  1.     import java.net.*;
  2.     class networking {
  3.         public static void main(String[] args) throws UnknownHostException {
  4.             InetAddress obj1 = InetAddress.getByName("cisco.com");
  5.             System.out.print(obj1.getHostName());
  6.         }
  7.     }
a) cisco
b) cisco.com
c) www.cisco.com
d) None of the mentioned
Answer: b

Related

C# Questions & Answers on Continue, Goto Statements for Freshers

1. Select output for the following set of code : static void Main(string[] args) { int i; Console.WriteLine("enter value of i:"); i = Convert.ToInt32(Console.ReadLi...

C# Questions & Answers on While Loop Statements for Freshers

1. Select the output for the following set of code : static void Main(string[] args) { int i, j; for (i = 1; i <= 3; i++) { j = 1; while (i % j ==...

C# Questions & Answers on For Loop Statements for Freshers

1. Select the output for the following set of code : static void Main(string[] args) { int i; for (i = 0; ; ) { Console.WriteLine("hello"); } Cons...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item