Thursday, March 3, 2016

MCQ Questions & Answers – HttpResponse & URLConnection Class


This set of Java Multiple Choice Questions & Answers (MCQs) focuses on “HttpResponse & URLConnection Class”.

1. Which of these is a wrapper around everything associated with a reply from an http server?
a) HTTP
b) HttpResponse
c) HttpRequest
d) httpserver
View Answer

Answer: b
Explanation: HttpResponse is wrapper around everything associated with a reply from an http server.
advertisement

2. 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
View Answer

Answer: a
Explanation: For a URL to be accessed from remote location http protocol must be used.

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

Answer: b
Explanation: None.

4. Which of these methods is used to know the type of content used in the URL?
a) ContentType()
b) contentType()
c) getContentType()
d) GetContentType()
View Answer

Answer: c
Explanation: None.

5. Which of these data member of HttpResponse class is used to store the response from an http server?
a) status
b) address
c) statusResponse
d) statusCode
View Answer

Answer: d
Explanation: When we send a request to an http server it responds with a status code this status code is stored in statusCode and a textual equivalent which is stored in reasonPhrase.

6. 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 Exception
  5.         {
  6.             URL obj = new URL("https://www.sanfoundry.com/javamcq");
  7.             URLConnection obj1 = obj.openConnection();
  8.             System.out.print(obj1.getContentType());
  9.         }
  10.     }

Note: Host URL is written in html and simple text.
a) html
b) text
c) html/text
d) text/html
View Answer

Answer: d
Explanation: None.
Output:

$ javac networking.java
$ java networking 
text/html

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

advertisement
  1.     import java.net.*;
  2.     class networking
  3.     {
  4.         public static void main(String[] args) throws Exception 
  5.         {
  6.             URL obj = new URL("https://www.sanfoundry.com/javamcq");
  7.             URLConnection obj1 = obj.openConnection();
  8.             int len = obj1.getContentLength();
  9.             System.out.print(len);
  10.         }
  11.     }

Note: Host URL is having length of content 127.
a) 126
b) 127
c) Compilation Error
d) Runtime Error
View Answer

Answer: b
Explanation: None.
Output:

$ javac networking.java
$ java networking 
127

8. 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 Exception
  5.         {
  6.             URL obj = new URL("https://www.sanfoundry.com/javamcq");
  7.             URLConnection obj1 = obj.openConnection();
  8.             System.out.print(obj1.getLastModified);
  9.         }
  10.     }

Note: Host URL was last modified on july 18 tuesday 2013 .
a) july
b) 18-6-2013
c) Tue 18 Jun 2013
d) Tue Jun 18 2013
View Answer

Answer: d
Explanation: None.
Output:

advertisement
$ javac networking.java
$ java networking 
Tue Jun 18 2013

No comments:

Post a Comment

Configure LOG4J in INTELLIJ in Windows.

IntelliJ debugger for temporary logging In this video, it is shown how to use Log4j in Intellij. Sorry for the audio quality :) Log4j zip fi...