KEMBAR78
Java Networking MCQ Quiz | PDF | Port (Computer Networking) | Network Socket
0% found this document useful (0 votes)
51 views9 pages

Java Networking MCQ Quiz

Uploaded by

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

Java Networking MCQ Quiz

Uploaded by

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

Networking Basics MCQ

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


a) java.io
b) java.util
c) java.net
d) java.network
2. How many ports of TCP/IP are reserved for specific protocols?
a) 10
b) 1024
c) 2048
d) 512
3. How many bits are in a single IP address?
a) 8
b) 16
c) 32
d) 64
4. 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
5. Which of these class is used to encapsulate IP address and DNS?
a) DatagramPacket
b) URL
c) InetAddress
d) ContentHandler
What will be the output of the following Java program?

1. import java.net.*;
2. class networking
3. {
4. public static void main(String[] args) throws
UnknownHostException
5. {
6. InetAddress obj1 = InetAddress.getByName("google.com");
7. InetAddress obj2 = InetAddress.getByName("google.com");
8. boolean x = obj1.equals(obj2);
9. System.out.print(x);
10. }
11. }

a) 0
b) 1
c) true
d) false

6. What will be the output of the following Java program?

1. import java.net.*;
2. public class networking
3. {
4. public static void main(String[] args) throws
UnknownHostException
5. {
6. InetAddress obj1 = InetAddress.getByName("cisco.com");
7. InetAddress obj2 = InetAddress.getByName("google.com");
8. boolean x = obj1.equals(obj2);
9. System.out.print(x);
10. }
11. }
a) 0
b) 1
c) true
d) false

7. What will be the output of the following Java program?

1.import java.io.*;
2.import java.net.*;
3.public class URLDemo
4.{
5. public static void main(String[] args)
6. {
7. try
8. {
9. URL url=new URL("https://www.javatutorial.com/java-mcq");
10. System.out.println("Protocol:
"+url.getProtocol());
11. System.out.println("Host Name: "+url.getHost());
12. System.out.println("Port Number: "+url.getPort());
13. } catch(Exception e){System.out.println(e);}
14. }
15. }
a) Protocol: http
b) Host Name: www.javatutorial.com
c) Port Number: -1
d) All of the mentioned

8. Which of these class is used to create servers that listen for either local or remote client
programs?
a) httpServer
b) ServerSockets
c) MimeHeader
d) HttpResponse
9. What does URL stands for?
a) Uniform Resource Locator
b) Uniform Resource Latch
c) Universal Resource Locator
d) Universal Resource Latch
10. Which of these exceptions is thrown by URL class’s constructors?
a) URLNotFound
b) URLSourceNotFound
c) MalformedURLException
d) URLNotFoundException

11.Which of these methods is used to know host of an URL?


a) host()
b) getHost()
c) GetHost()
d) gethost()
12. Which constructor of DatagramSocket class is used to creates a datagram socket and binds
it with the given Port Number?

a. DatagramSocket(int port)
b. DatagramSocket(int port, InetAddress address)
c. DatagramSocket()
d. None of the above

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

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

a. DatagramSocket
b. DatagramPacket
c. Both A & B
d. None of the above
15. Which method of URL class represents a URL and it has complete set of methods to
manipulate URL in Java?

a. java.net.URL
b. java.net.URLConnection
c. Both A & B
d. None of the above

16. The DatagramSocket and DatagramPacket classes are not used for connection-less socket
programming.

a. True
b. False

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

18. The URLConnection class can be used to read and write data to the specified
resource referred by the URL

a. True
b. False

19. Datagram is basically an information but there is no guarantee of its content, arrival
or arrival time.

a. True
b. False

20. What does the java.net.InetAddress class represent?

a. Socket
b. IP Address
c. Protocol
d. MAC Address
21. The flush() method of PrintStream class flushes any uncleared buffers in memory

a. True
b. False

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

a. Socket
b. IP Address
c. Protocol
d. MAC Address

23. Which steps occur when establishing a TCP connection between two computers
using sockets?

a. The server instantiates a ServerSocket object, denoting which port number


communication is to occur on
b. The server invokes the accept() method of the ServerSocket class. This method waits
until a client connects to the server on the given port
c. After the server is waiting, a client instantiates a Socket object, specifying the server
name and port number to connect to
d. All of the above

24. In InetAddress class which method 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

25. Which of these is a bundle of information passed between machines?


a) Mime
b) Cache
c) Datagrams
d) DatagramSocket
26. Which of these method of DatagramPacket is used to find the port number?
a) port()
b) getPort()
c) findPort()
d) recievePort()
27. Which of these method of DatagramPacket is used to obtain the byte array of data
contained in a datagram?
a) getData()
b) getBytes()
c) getArray()
d) recieveBytes()
28. Which of these methods of DatagramPacket is used to find the length of byte array?
a) getnumber()
b) length()
c) Length()
d) getLength()
29. Which of these method of DatagramPacket class is used to find the destination
address?
a) findAddress()
b) getAddress()
c) Address()
d) whois()
30. Which of these is a return type of getAddress() method of DatagramPacket class?
a) DatagramPacket
b) DatagramSocket
c) InetAddress
d) ServerSocket
31. Which API gets the SocketAddress (usually IP address + port number) of the remote
host that this packet is being sent to or is coming from.
a) getSocketAddress()
b) getAddress()
c) address()
d) none of the mentioned

32. Which method of URL class returns the object of URLConnection class?
(A) getLocalHost()
(B) openConnection()
(C) getByName(String host)
(D) getHostAddress()

33. A Socket Consists Of?


(A) Port+IP address
(B) Only IP address
(C) only Port address
(D) None of these
34. How do you implement reliable transmission in UDP protocol?
(A) by sequencing packages
(B) by using Middleware
(C) A & B both
(D) None of the above

35. Which Protocol is generally used for multicast? TCP or UDP?


(A) TCP
(B) UDP
(C) A & B both
(D) None of these

36. How to get list of IP address that are assigned to a network interface?
(A) getInetAddresses()
(B) getInterfaceAddresses()
(C) A & B both
(D) None of these

37. Which is not true for socket.


(A) Socket connection means the two machines have information about each other’s network location and
port.
(B) Socket supports only TCP protocol due to its reliability feature.
(C) To connect to other machine we need a socket connection.
(D) Socket programming is used for communication between the applications running on different JRE.

38. If one want to implement Socket at client side then which is the correct way to
implement it?
(A) ServerSocket ss=new ServerSocket(port);
(B) Socket s=ss.accept();
(C) Socket s=new Socket("localhost",port);
(D) Socket s=ss.accept(port);

39. URL contains…?


(A) Protocol
(B) IP Address
(C) Port Number
(D) All of above

40. InetAddress has a cache to store successful and unsuccessful host name
resolutions.
(A) True
(B) False
41. UnknownHostException is immediate child class of_______?
(A) java.lang.Exception
(B) java.lang.IOException
(C) java.lang.Throwable
(D) java.lang.Object

42. Port numbers range from _____ to ______.


(A) 0 to 65535
(B) 1 to 65536
(C) -65535 to 65536
(D) 0 to 1024

43. _________ Protocol is more efficient in terms of both latency and bandwidth.
(A) TCP
(B) UDP
(C) SMTP
(D) FTP

44. What happens if ServerSocket is not able to listen on the specified port?
a) The system exits gracefully with appropriate message
b) The system will wait till port is free
c) IOException is thrown when opening the socket
d) PortOccupiedException is thrown

45. What does bind() method of ServerSocket offer?


a) binds the serversocket to a specific address (IP Address and port)
b) binds the server and client browser
c) binds the server socket to the JVM
d) binds the port to the JVM

46. What happens if IP Address of host cannot be determined?


a) The system exit with no message
b) UnknownHostException is thrown
c) IOException is thrown
d) Temporary IP Address is assigned

47. What is the java method for ping?


a) hostReachable()
b) ping()
c) isReachable()
d) portBusy()

48. Which of the following code retrieves the body of the request as binary data?
a) DataInputStream data = new InputStream()
b) DataInputStream data = response.getInputStream()
c) DataInputStream data = request.getInputStream()
d) DataInputStream data = request.fetchInputStream()

49. These networking classes encapsulate the "socket" paradigm pioneered in the (BSD) Give
the abbrevation of BSD?
A) Berkeley Software Distribution
B) Berkeley Socket Distribution
C) Berkeley System Distribution
D) None of the above

50. What does local IP address start with?


a.10.X.X.X
b.172.X.X.X
c.192.168.X.X
d.10.X.X.X, 172.X.X.X, or 192.168.X.X

You might also like