You are on page 1of 19

Unit-IV

Networking Basics

1) Socket s1= Socket ( localhost, 1346), What does it means ?


b) Client socket is created to connect with specified
a) Client socket is waiting for connection
host name and port number
c) Client socket is name as localhost and Port number d) server socket is connected to local host with port
is 1346 number 1346

2) Correct way of using ServerSocket is___________


a) ServerSocket(int port) b) ServerSocket(int port,int maxQueue)
c) ServerSocket(int port,int maxQueue,InetAddress
d) All of the above
localAddress)

3) What is the output of the following statement?


ServerSocket ss=new ServerSocket(1234);
Socket s1=ss.accept();
System.out.println(s1.getPort());
a) port number of client socket b) 1349
c) local port d) None of the above

4) If your application has successfully bound to specified port and is ready for client request then_________
a) an exception is thrown b) an IOException is thrown
c) it does not throw an exception d) UnknownHostException is thrown

5) Which steps occur when establishing a TCP connection between two computers using socket?
b) The server invokes the accept() method of
a) The server initiates a ServerSocket object denoting
ServerSocket class. This method waits until a client
port number to be connected
connects to the server on the given port
c) After the server is waiting, a client instantiates a
socket object with specified server name and port d) All of the above
number

6) What is the output of following statement?


ServerSocket ss=new ServerSocket(1234);
Socket s1=ss.accept();
System.out.println(s1.getRemoteSocketAddress());
a) 1234 b) iPAddress of serversocket
c) IPAddress of client with port number d) IPAddress of server with port number

7) What is the output of following statement?


Socket s1=new Socket("localhost",1234);
System.out.println(s1.getRemoteSocketAddress());
b) host name, IPAddress and port number of
a) IPAddress of client with port number
Serversocket
c) host name and IPAddress Serversocket d) IPAddress of server with port number
8) Connection timed out exception is occurred _________
a) if client socket is not created b) if serversocket does not accept client request
c) if port number is not available which is specified
d) None of the above
by client socket with host name

9) Which exception will occur when port is already bound with an application and other application is requesting
for same port?
a) IOException b) PortNotFoundException
c) UnknownPortNameException d) ConectException
Ans: IOException

10) Which constructor will you use to connect to specified host and port by creating a socket on the local host at
specified address & port
a) Socket() b) Socket(String host, int port)
d) Socket ( String host,int port, Inetaddress ipAdd,
c) Socket (Inetaddress ipAdd,int port)
int localport )

11) Which exception will occur if specified port number is not available for DatagramSoclet?
a) UnknownException b) SocketException
c) UnknownSocketException d) UnknownPortException

12) getData() & getLenght() are the methods of ___________ class


a) DatagramSoclet b) ServerSocket
c) DatagramPacket d) ClientSocket

13) Unlike User Datagram Protocol (UDP), Transmission Control Protocol (TCP) has Services which is
a) Connection Oriented b) Connectionless
c) Connection Available d) Connection Origin

14) getDate() method present in which class?


a) URL b) URLDecoder
c) URLConnection d) All of the mentioned

15) Which of these methods is used to know the full URL of an URL object?
a) fullHost() b) getHost()
c) ExternalForm() d) toExternalForm()

16) getLocalHost() method simply returns the InetAddress object which represents______________
a) host name b) machine name
c) local host d) remote host

17) The getByName() method returns an ________________ with host name


a) IP address b) InetAddress Object
c) port number d) IPv4

18) getAllByName() method returns an array of_____________ that represents all of the addresses that specific
host name has
a) host names b) InetAddresses
c) ipaddresses d) objects

19) InetAddress also Includes a factory method called____


a) getByAddress() b) getHostName()
c) getAddress() d) getIPAddress()

20) InetAddress has two subclasses called as:


a) IPV4Address() and IPV6Address() b) IP4VAddress() and IP6VAddress()
c) Inet4Address() and Inet6Address() d) InetAddress4() and InetAddress6()

21) InetAddress class is used to encapsulate both numerical IP address and the ______________
a) port number b) host name
c) server name d) socket name

22) You can simply use InetAddress class when working with IP address because it can accommodate both
___________ styles.
a) IP4V and IP6V b) IPV4 and IPV6
c) host name and IP d) A and B

23) Which of the following class is used to create server that listen for clients ?
a) httpserver b) ServerSocket
c) DatagramSocket d) Socket

24) __________method returns the local port to which the invoking socket object is bound.
a) int getLocalHost() b) int getLocalPort()
c) int getPort() d) int GetLocalHost()

25) Which of the following are factory methods of InetAddress class?


a) static InetAddress[] getAllByName(String
b) static InetAddres getLocalHost()
hostname)
c) string getHostName() d) A and B

26) Which of the following methods belong to ServerSocket class


a) accept() b) connect()
c) bind() d) A and C

27) ServerSocket class has one of the following constructor


a) ServerSocket(int port) b) ServerSocket(String host, int port)
c) ServerSocket(int port, InetAddress add) d) ServerSocket(InetAddress add, int port)

28) How long is an IPv6 address?


a) 32 bits b) 128 bytes
c) 64 bits d) 128 bits

29) __________________method is needed only when you instantiate the socket using the not argument
constructer.
a) bind() b) connect()
c) accept() d) SetHostName()

30) accept method is used for _______________________


a) Incoming Client connection b) Incoming Server socket
c) Accepting request from server d) Waiting socket

31) _____________class represents the socket that both the client & server use to communicate with each other
a) java.net.Serversocket b) java.net.Server
c) java.net.socket d) java.net.Clientsocket

32) public InputStream getInputStream() is method of ____________ class


a) Serversocket b) ClientSocket
c) Socket d) All of the above

33) getOutputStream() returns the output stream of the ________


a) Socket b) ServerSocket
c) ClientSocket d) None of the above

34) __________method makes socket object no longer capable of connecting again to any server
a) send() b) wait()
c) connect() d) close()

35) Socket is the combination of ______________ and __________.


a) IP address and port number b) port number and local host
c) IPAddress and machine number d) All of the above

36) Which method is used to expose the details of establishing connection between server socket & client socket ?
a) connect() b) receive()
c) there is no such method d) None of the above

37) Socket(InetAddress host, int port) in this constructor, what does first parameter stands for ?
b) host name and IPAddress specified by
a) host name
InetAddress object
c) IpAddress of host d) ipaddress and port number

38) Which of the following class is used to create client socket


a) httpserver b) Datagram Socket
c) Socket d) ClientSocket

39) Which of the following are Instance method of InetAddress Class


a) byte[] getAddress() b) string getHostName()
c) A and B d) static InetAddress getByName(string hostname)

40) Java DatagramSocket and DatagramPacket classes are used for _______________ socket programming
a) Connection-oriented b) Connection-less
c) A & B d) Reliable
41) Which constructor of DatagramSocket class is used to create a datagram socket and binds it with the given
port number?
a) DatagramSocket(int port) b) DatagramSoclet(int port InetAddress add)
c) DatagramSoclet() d) None of the above

42) Which of the below are common network protocols?


a) TCP b) UDP
c) TCP and UDP d) FTP

43) Which of these package contains classes and interfaces for networking?
a) java.io b) java.util
c) java.net d) java.network

44) How many ports of TCP/IP are reserved for specific protocols?
a) 10 b) 1024
c) 2048 d) 512

45) How many bits are in a single IP address?


a) 8 b) 16
c) 32 d) 64

46) How many bits value does IPv4 and IPv6 uses to represent the address?
a) 32 and 64 b) 64 and 128
c) 32 and 128 d) 64 and 64

47) __________is a server that is mediator between real web server and client application.
a) IBMServer b) SQLServer
c) ReserverSockets d) Proxy server

48) Port number 80 is reserved for


a) FTP b) Telnet
c) e-mail d) HTTP

49) __________method is used to know the type of content used in the URL.
a) ContentType() b) Contenttype()
c) GetContentType() d) getContentType()

50) Port number 25 is reserved for


a) FTP b) Telnet
c) SMTP d) HTTP

51) Which class is used to encapsulate IP address and DNS?


a) URLConnection b) Telnet
c) DatagramPacket d) InetAddress
52) Port number 21 is reserved for
a) FTP b) Telnet
c) e-mail d) HTTP
53) User Datagram Protocol is__________
a) Support fast transfer of packets b) support connection-less transport of packets
c) support unreliable transport of packets d) All of the above

54) The Transmission Control Protocol is


a) Low level routing protocol b) Middle level routing protocol
c) Higher level routing protocol d) None of above

55) Internet Protocol is


a) Low level routing protocol b) Middle level routing protocol
c) Higher level routing protocol d) None of above

56) Which class provides system independent server side implementation?


a) Socket b) ServerSocket
c) Server d) ServerReader

57) Following Shows networking terminologies ?


a) IP Address b) Protocol
c) URL d) All of the above

58) Which is a one-way communication only between the client and the server and it is not a reliable and there is
no confirmation regarding reaching the message to the destination?
a) TCP/IP b) UDP
c) Both A & B d) None of the above

59) ----is not a protocol


a) Telnet b) TCP
c) FTP d) hit

60) Select incorrect statement about Internet Protocol


a) It is low level routing Protocol b) It breaks data into small packets
c) sends packet to an address across network d) it is higher level Protocol

61) ----- is the protocol that web browser and server use to transfer hypertext pages and images
a) FTP b) HTTP
c) telnet d) none of above

62) File transfer protocol(FTP) is used for____________


a) Speed b) Efficient
c) Security d) All of the above

63) Which of these class is necessary to implement datagrams?


a) DatagramPacket b) DatagramSocket
c) All of the mentioned d) None of the mentioned

64) Which methods are commonly used in ServerSocket class?


a) public OutputStream getOutputStream() b) public synchronized void close()
c) public Socket accept() d) none of the above

65) Which protocol is for breaking and sending packets to an address across a network.
a) UDP b) TCP/IP
c) Proxy server d) none of the above

66) UDP stands for ---------


a) User Datagram Protocol b) Uses Datagram Protocol
c) user data procedure d) user data program

67) Central Computer which is powerful than other computers in the network is called as __________.
a) client b) server
c) hub d) switch

68) Which of this class is used to create servers that listen for either local or remote client programs?
a) Server Machine b) Client Machine
c) HttpServer d) ServerSocket

69) HTTP stands for___________?


a) Hypertext transfer processor b) Hypertext Transfer Protocol
c) High transfer protocol d) hyper transfer protocol

70) import java.net.*; In above statement net is -------


a) package b) class
c) interface d) method

71) ------ is a protocol


a) netnews b) Sting
c) hit d) none of above

72) import java.net.ServerSocket; In above statement ServerSocket is -----------


a) package b) class
c) interface d) method

73) 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

74) UDP support -------


a) a simpler communication b) a faster communication
c) point to point data gram oriental model d) All of the above

75) java.net package interfaces are____________


a) URLConnection b) ContentHandlerFactory
c) DatagramSocket d) All of the above
76) DatagramPacket(byte data[ ], int size) DatagramPacket(byte data[ ], int offset, int size) are examples of----------
a) package b) class
c) Interface d) constructors

77) ContentHandlerFactory , CookiePolicy,CookieStore are examples of


a) package b) class
c) interface d) method

78) ContentHandler , MulticastSocket , URL, SocketImpl are examples of --------


a) package b) class
c) Interface d) Method

79) URLEncoder , URLConnection , URLDecoder are examples of


a) package b) class
c) Interface d) All of the above

80) What does URL stands for?


a) Uniform Resource Locator b) Uniform Resource Latch
c) Universal Resource Locator d) Universal Resource Latch

81) ContentHandler , MulticastSocket , URL, SocketImpl are included in --------package


a) .net b) .util
c) . io d) .lang

82) .com,.gov,.org are examples of--------


a) domain b) server name
c) client name d) package

83) HttpURLConnection , URLConnection , URL are included in --------package


a) .net b) .util
c) . io d) .lang

84) ContentHandlerFactory , SocketOptions , FileNameMap are included in --------package


a) .net b) .util
c) . io d) .lang

85) .net,.util,.lang,.gov, from this -----is a domain


a) .net b) .util
c) .lang d) .gov

86) From following which is package?


a) .com b) .util
c) .gov d) All of the above

87) Networking classes encapsulate the "socket" paradigm pioneered in the (BSD) Give the abbreviation of BSD?
a) Berkeley Software Distribution b) Berkeley Socket Distribution
c) Berkeley System Distribution d) None of the above
88) Datagrams are ------------------ of information passed between machines
a) bundles b) sets
c) none of A and B d) Both A and B

89) DatagramPacket has ----------- methods


a) int getPort() b) byte[] getData()
c) int getLength() d) All of the above

90) How many forms of constructors URL class have?


a) 1 b) 2
c) 3 d) 4

91) getQuery() method present in which class?


a) URL b) URLDecoder
c) URLConnection d) none of the above

92) boolean equals(Object other) will return_______


a) Returns true if object has same internet address b) Returns False if object has same internet address
as other. as other.
c) Returns true if object has not same internet d) Returns null if object has same internet address as
address as other. other.

93) What is the role of getAddress() method ?


b) Returns a byte array that represents the object's
a) returns Ip address of network.
Ip address in the network byte order.
c) Returns an array of object's that represents Ip d) Returns the a byte array of Ip address of network
address . host machine .

94) Which method does return true value if specified address is a multicast address ?
a) isMulticastHostName() b) isMulticastHostAddress()
c) isMulticastAddress() d) isMulticastIPAddress()

95) What does getHostAddress() of InetAddress class terurn?


b) Returns a string that represents ipaddresses with
a) Returns host address with ipaddress.
hostname.
c) Returns a string that represents a host address d) Returns a string that represents a host name
associated with the Inetaddress object. associated with Inetaddress object.

96) getHostName() of InetAddress class is used to_______


a) Return a string that represents host name b) Return a string that represents host address
associated with Inetaddress object. associated with Inetaddress object.
c) Return an object that represents Ipaddress d) Return Ipaddress that is associated with
associated with host name . InetAddress object .

97) Which exception will be thrown if client socket does not specify the hostname when it has created ?
a) IOException b) UnknownHostException
c) UnknownHostNameException d) UnknownPortException
98) Which of the following statement is correct ?
a) There are two kinds of sockets in java one is for
b) There is only one socket for server.
server and other for clients.
d) There is only one socket for server as well as for
c) There is only one socket for client.
client.

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

100) Which constructor will you use to create client socket using a preexsiting InetAddress object and a port ?
a) Socket (String hostname, int port ) b) Socket (Inetaddress ipAdd, int port )
c) Socket (Inetaddress ip Add, string Hostname) d) Socket ( int port, Inetaddress ipAdd )

101) Socket method called______returns the port number that socket is bound to on local machine
a) int getLocalPortt() b) int getPort()
c) InetAddress getInetAddress() d) string getHostAddress()

102) What are different factory methods of InetAddress class?


a) getByName() b) GetLocalHost()
c) getByAddress() d) both A & C

103) InetAddress class having method which returns a string that shows the host name and IP address.
a) toString() b) getHostAddress()
c) getLocalHost() d) none of the above

104) If server socket is created using serversocket () constructer then which method should we use to bind the
serve socket ?
a) isbind() b) bind()
c) bind To() d) bind ( socketAddress host , int backlog)

105) Which of the following statement is correct?


a) The input stream of socket is connected to the b) The output stream of socket is connected to the
output stream of remote socket input stream of remote socket
c) The output stream of socket is connected to the
d) A and B
output stream of remote socket

106) You can gain access to the input and output streams associated with socket by use getInputStream() and
a) getOutStream() b) setOutputStream()
c) getOutputStream() d) getOutputClass()

107) When you will use this ServerSocket(int port, int que) constructor to create server socket
b) to create ServerSocket with port number & Ip
a) to create ServerSocket with port number
address
c) to create ServerSocket with port number and
d) B & C
number of incoming client queue
108) Which class is used for connection-less socket programming ?
a) DatagramSocket b) DatagramServer
c) A and B d) None of the above

109) Which of the following constructor is used to create datagram socket with port number and host address
a) DatagramSoclet(int port) b) DatagramSoclet(int port InetAddress add)
c) DatagramSoclet() d) A & B

110) Which constructor will you use to send packet?


a) DatagramPacket(byte[] bar, int len) b) DatagramPacket(byte[] bar, int len, int port)
c) DatagramPacket(string s1, int len, InetAddress, int
d) All of the above
port)

111) Datagram Packet is a message that can be used for _________ messages
a) Connection-oriented or connection less b) send and store
c) send and receive d) receive and read

112) Which constructors are used to receive data from packet?


a) DatagramPacket(byte[] bar, int len) b) DatagramPacket(byte[] bar, int off, int len)
c) DatagramPacket(string s1, int len, InetAddress, int
d) A and B
port)

113) 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

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


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

115) The Transmission Control Protocol


a) Support fast transfer of packets b) support connectionless transport of packets
c) support unreliable transport of packets d) support connection oriented transport of packets

116) Which classes are used for connection-oriented socket programming?


a) Socket b) ServerSocket
c) Both A and B d) None of the above

117) Following are tasks of Proxy Server__________


a) Filter certain request b) cache the results of request for future use
c) provide faster access of catched pages to clients d) All of the above

118) A typical __________ program obtains a remote reference to one or more remote objects on a server and
then invokes methods on them.
a) server b) client
c) thread d) concurrent
119) Unlike Transmission Control Protocol (TCP), User Datagram Protocol (UDP) has Services which is
a) Connection Oriented b) Connectionless
c) Connection Available d) Connection Origin

120) Which of these exceptions is thrown by URL class’s constructors?


a) URLNotFound b) URLSourceNotFound
c) MalformedURLException d) URLNotFoundException

121) Which of these methods is used to know host of an URL?


a) host() b) getHost()
c) GetHost() d) gethost()

122) Which of these methods is used to know when was the URL last modified?
a) LastModified() b) getLastModified()
c) GetLastModified() d) getlastModified()()

123) Which of these methods is used to know the type of content used in the URL?
a) ContentType() b) contentType()
c) getContentType() d) GetContentType()
Ans: getContentType()

124) ------types of exceptions are occurred in networking programming


a) UnknownHostException b) MalformedURLExeption
c) Exception d) All of the above

125) .net,.util,.lang are examples of -------


a) package b) class
c) Interface d) Method

126) TCP/IP style of networking provides ------------------


a) serialized stream of packet data b) predictable stream of data
c) reliable stream of data d) All of the above

127) TCP includes many complicated algorithms for dealing with-------


a) congestion control on crowded networks b) pessimistic expectations about packet loss
c) inefficient way to transport data d) All of the above

128) -------- constructor specifies only a buffer that will receive data and the size of packet.
a) DatagramPacket(byte data[], int size) b) DatagramPacket(byte data[], int offset, int size)
c) DatagramPacket(byte data[], int offset, int size ,
d) All of the above
InetAddress ipAddress, int port)

129) Which of these transfer protocol must be used so that URL can be accessed by URLConnection class object?
a) http b) https
c) Any Protocol can be used d) None of the mentioned
130) In Uniform Resource Locator (URL), path is pathname of file where information is
a) Stored b) Located
c) to be transferred d) Transferred

131) The class ________is used for accessing the attributes of remote resource.
a) URI b) URLConnection
c) URL d) URLLoader

132) How many forms of constructors URLConnection class have?


a) 1 b) 2
c) 3 d) none of the above

133) openConnection() method present in which class?


a) URL b) URLConnection
c) InetAddress d) HTTPURLConnection

134) getExpiration( ) method present in which class?


a) URL b) URLDecoder
c) URLConnection d) none of the above

135) getContentLength() method present in which class?


a) URL b) URLConnection
c) URLDecoder d) URLNotFoundException

136) Which of these class is used to access actual bits or content information of a URL?
a) URL b) URLDecoder
c) URLConnection d) All of the mentioned

137) getConnectionTimeout() method present in which class?


a) URL b) URLDecoder
c) URLConnection d) URLNotFoundException

138) getPath() method present in which class?


a) URL b) URLDecoder
c) URLConnection d) none of the above

139) ___________method of DatagramPacket is used to find the port number.


a) port() b) GetPort()
c) getPort() d) findPort()

140) getInetAddress( ) method present in which class?


a) URL b) Socket
c) ServerSocket d) none of the above

141) getLocalPort( )method present in which class?


a) Socket b) URLDecoder
c) URLConnection d) URLNotFoundException
142) getRef() method present in which class?
a) URLNotFound b) URLDecoder
c) URLConnection d) URL

143) getProtocol() method present in which class?


a) URL b) URLDecoder
c) URLConnection d) none of the above

144) URLConnection class present in which package?


a) url b) urlconnection
c) URL d) .net

145) What is the output of following program


import java.net.*;
class Demo
{
public static void main(String arg[]) throws UnknownHostException
{
InetAddress ipa=InetAddress.getLocalHost();
System.out.println(ipa);
}
}
a) host name/IP address b) iPAddress/Host name
c) IPAddress d) Host name

146) What is the output of following program


import java.net.*;
class Demo
{
public static void main(String arg[])
{
InetAddress ip=InetAddress.getByName("www.google.com");
System.out.println(ip) ;
}
}
a) www.google.com/217.56.216.195 b) www.google.com
c) 217.56.216.195 d) All of the above

147) What is output of following program


import java.net.*;
class Demo
{
public static void main(String arg[]) throws UnKnownHostException
{
InetAddress ipa[]=InetAddress.getAllByName("www.google.com");
for(int i=0;i<ipa.length;i++)
{
System.out.println(ipa[i]);
}
}
}
a) array of hostnames b) array of hostname/IPaddress
c) array of IPaddress d) IPAddress/Hostname

148) What is output of following code?


import java.net.*;
class Inet
{
public static void main(String arg[])throws UnKnownHostException
{
InetAddress ip=InetAddress.getLocalHost();
System.out.println(ip.getHostAddress());
}
}
a) 192.168.0.100 b) localhost/192.168.0.100
c) localhost machine d) localhost//8080:

149) What is the output of following program


import java.net.*;
class Demo
{
public static void main(String arg[]) throws UnKnownHostException
{
InetAddress ipa=InetAddress.getLocalHost();
InetAddress ipa1=InetAddress.getLocalHost();
boolean b=ipa.equals(ipa1);
System.out.println(b);
}
}
a) TRUE b) FALSE
c) 0 d) 1

150) What is the output of following program


import java.net.*;
class Demo
{
public static void main(String arg[]) throws UnKnownHostException
{
InetAddress ipa=InetAddress.getByName("www.google.com");
System.out.println(ipa.getHostName());
}
}
a) www.google.com b) www.google.com/217.196.214.99
c) 217.196.214.99 d) None of the above
151) What is the output of following statements
Socket s1=new Socket("localhost",1234);
int a=s1.getPort();
System.out.println(a);
a) localhost b) localhost/1234
c) 1234 d) 1234/localhost

152) What is the output of the following statement?


ServerSocket ss=new ServerSocket(1234);
Socket s1=ss.accept();
System.out.println(s1.getPort());
a) port number of client socket b) 1234
c) local port d) All of the above

153) What will be the output of following statements


Socket s1=Socket("localhost",1349);
System.out.println(s1.getLocalPort());
a) 1349 b) port number of local machine
c) local host d) localhost/1349

154) What is the output of following code?


DatagramPacket dp =new DatagramPacket(byte[] data, 1024);
System.out.println(dp.getLength());
a) 1024 b) data, 1024
c) 1024, data d) Null

155) What is the output of this program?


import java.net.*;
class networking
{
public static void main(String[] args) throws MalformedURLException
{
URL obj = new URL("https://www.sanfoundry.com/javamcq");
System.out.print(obj.getProtocol());
}
}
a) http b) https
c) www d) com

156) What is the output of this program?


import java.net.*;
class networking
{
public static void main(String[] args) throws Exception
{
URL obj = new URL("https://www.sanfoundry.com/javamcq");
URLConnection obj1 = obj.openConnection();
System.out.print(obj1.getContentType());
}
}
a) html b) text
c) html/text d) text/html

157) What is the output of this program?


import java.net.*;
class networking
{
public static void main(String[] args) throws Exception
{
URL obj = new URL("https://www.sanfoundry.com/javamcq");
URLConnection obj1 = obj.openConnection();
int len = obj1.getContentLength();
System.out.print(len);
}
}
a) 127 b) -1
c) Compilation Error d) Runtime Error

158) What is the output of this program?


import java.net.*;
class networking
{
public static void main(String[] args) throws MalformedURLException
{
URL obj = new URL("http://www.sanfoundry.com/javamcq");
System.out.print(obj.getPort());
}
}
a) 1 b) 0
c) -1 d) garbage value

159) What is the output of following program?


import java.net.*;
class networking {
public static void main(String[] args) throws Exception {
URL obj = new URL("http://www.oracle.com");
URLConnection obj1 = obj.openConnection();
int len = obj1.getContentLength();
System.out.print(len);
}
}
a) 0 b) 127
c) compile time error d) run time error
160) Which steps occur when establishing a TCP connection between two computers using sockets?
a) The server instantiates a ServerSocket object, b) The server invokes the accept() method of the
denoting which port number communication is to ServerSocket class. This method waits until a client
occur on 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 d) All of the above
number to connect to

161) What is the output of following program?


import java.io.*;
import java.net.*;
public class URLDemo
{
public static void main(String[] args)
{
try
{
URL url=new URL("http://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 above mentioned

162) What is the output of this program?


import java.net.*;
class networking
{
public static void main(String[] args) throws Exception
{
URL obj = new URL("https://www.sanfoundry.com/javamcq");
URLConnection obj1 = obj.openConnection();
System.out.print(obj1.getLastModified);
}
}
Note: Host URL was last modified on june 18 tuesday 2018 .
a) july b) 18-Jun-13
c) Tue 18 Jun 2013 d) Tue Jun 18 2018

163) Write output of following


import java.net.*;
class networking16
{
public static void main(String[] args) throws MalformedURLException
{
URL obj = new URL("http://www.sanfoundry.com/javamcq");
System.out.print(obj.toExternalForm());
}
}
a) sanfoundry b) sanfoundry.com
c) www.sanfoundry.com d) http://www.sanfoundry.com/javamcq

164) What is the output of following program


import java.net.*;
class Demo
{
public static void main(String arg[]) throws UnKnownHostException
{
InetAddress ipa=InetAddress.getLocalHost();
InetAddress ipa1=InetAddress.getLocalHost("www.google.com");
boolean b=ipa.equals(ipa1);
System.out.println(b);
}
}
a) TRUE b) FALSE
c) compile time error d) 0

165) getContentType() method present in which class?


a) URL b) URLDecoder
c) URLConnection d) none of the above

You might also like