Java Questions & Answers – Networking – Server & Sockets

This set of Basic Java Questions and Answers focuses on “Nnetworking – Server & Sockets”.

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

Answer: b
Explanation: None.

2. Which of these is a standard for communicating multimedia content over email?
a) http
b) https
c) Mime
d) httpd
View Answer

Answer: c
Explanation: MIME is an internet standard for communicating multimedia content over email. The HTTP protocol uses and extends the notion of MIME headers to pass attribute pairs between HTTP client and server.

3. Which of these methods is used to make raw MIME formatted string?
a) parse()
b) toString()
c) getString()
d) parseString()
View Answer

Answer: a
Explanation: None.
advertisement
advertisement

4. Which of these method of MimeHeader is used to return the string equivalent of the values stores on MimeHeader?
a) string()
b) toString()
c) convertString()
d) getString()
View Answer

Answer: b
Explanation: toString() does the reverse of parse() method, it is used to return the string equivalent of the values stores on MimeHeader.

5. 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:

advertisement
$ javac networking.java
$ java networking 
text/html

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

a) sanfoundry
b) sanfoundry.com
c) www.sanfoundry.com
d) https://www.sanfoundry.com/javamcq
View Answer

Answer: d
Explanation: toExternalForm() is used to know the full URL of an URL object.
Output:

$ javac networking.java
$ java networking 
https://www.sanfoundry.com/javamcq

Sanfoundry Global Education & Learning Series – Java Programming Language.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.