250+ TOP MCQs on HttpResponse & URLConnection Class and Answers

This set of Java Multiple Choice Questions & Answers (MCQs) 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

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

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

Answer: a
Clarification: 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()()

Answer: b
Clarification: 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()

Answer: c
Clarification: 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

Answer: d
Clarification: 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("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

Answer: d
Clarification: None.
Output:

$ javac networking.java
$ java networking 
text/html

7. 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("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

Answer: b
Clarification: 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("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

Answer: d
Clarification: None.
Output:

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

  250+ TOP MCQs on Java.lang – Character Wrapper Advance and Answers

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top