Unit 4
Unit 4
(a) 21 (b) 23
(d) 79 (c) 25
a) 0
b) 1
c) true
d) false
Q.18 What is the output of this program?
1. importjava.net.*;
2. class networking {
3. publicstaticvoid main(String[]args)throwsUnknownHostException{
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
Q.19. What is the output of this program?
1. Import java.net.*;
2. class networking {
3. public static void main(String[]args) throwsUnknownHostException{
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
Q.20. What is the output of this program?
1. importjava.net.*;
2. class networking {
3. publicstaticvoid main(String[]args)throwsException{
4. URLobj=newURL("http://www.sanfoundry.com/javamcq");
5. URLConnection obj1 =obj.openConnection();
6. System.out.print(obj1.getContentType());
7. }
8. }
Note: Host URL is written in html and simple text.
a) html
b) text
c) html/text
d) text/html
Q.21. What is the output of this program?
1. importjava.net.*;
2. class networking {
3. publicstaticvoid main(String[]args)throwsMalformedURLException{
4. URLobj=newURL("http://www.sanfoundry.com/javamcq");
5. System.out.print(obj.toExternalForm());
6. }
7. }
a) sanfoundry
b) sanfoundry.com
c) www.sanfoundry.com
d) http://www.sanfoundry.com/javamcq
Q.22.What is the output of this program?
1. importjava.net.*;
2. class networking {
3. publicstaticvoid main(String[]args)throwsMalformedURLException{
4. URLobj=newURL("http://www.sanfoundry.com/javamcq");
5. System.out.print(obj.getProtocol());
6. }
7. }
a) http
b) https
c) www
d) com
Q.23. What is the output of this program?
1. importjava.net.*;
2. class networking {
3. publicstaticvoid main(String[]args)throwsMalformedURLException{
4. URLobj=newURL("http://www.sanfoundry.com/javamcq");
5. System.out.print(obj.getPort());
6. }
7. }
a) 1
b) 0
c) -1
d) garbage value
(a) URL
(c) URLConnection
(b) URLDecoder
(d) All of the mentioned
(a) portO
(c) GetPortO
(b) getPortO (d) findPortO
Q. 35 Which of these tranfer protocol must be used so that URL
can be accessed by URLConnectionclass object?
(a) LastModifiedO
(c) getlastModifiedO
(b) getLastModifiedO
(d) GetLastModifiedO
Q. 37 __ method is used to know the type of content used in
theURL.
(a) ContenttypeO (b) contentTypeO
(c) getContentTypeO (d) GetContentTypeO
Q. 38 Which package is used for handling security related issues
in a program ?
(a) java.security (b) java.lang.security
(c) java.awt.image (d) java.io.security
Q. 39 Class which allows us to get real time data about private
and protected member of a class is __ .
(a) java.io.security
(b) java.GetInformation
(c) ReflectPermission
(d) MembersPermission
Q. 40 The packages contain classes and interfaces used for input
and output operations of a program is __ .
(a) java.util (b) java.lang
(c) java.io (d) java.file.io
Q. 41 __ class is not a member class of java.io package.
(a) File (b) StringReader
(c) Writer (d) String