Java Network Programming Questions and Answers

Related Topics:

Java Programming : Java Network Programming

Here are the Java Network Programming Questions and Answers with PDF to download.
1. Which of these methods of httpd class is used to read data from the stream?
[A] getDta()
[B] GetResponse()
[C] getStream()
[D] getRawRequest()

Answer: D. getRawRequest()

Explanation:

The getRawRequest() method reads data from a stream until it gets two consecutive newline characters
2. Which of these method of httpd class is used to get report on each hit to HTTP server?
[A] log()
[B] logEntry()
[C] logHttpd()
[D] logResponse()

Answer: B. logEntry()

Explanation:

none
3. Which of these method is used to find a URL from the cache of httpd?
[A] findfromCache()
[B] findFromCache()
[C] serveFromCache()
[D] getFromCache()

Answer: C. serveFromCache()

Explanation:

serveFromCatche() is a boolean method that attempts to find a particular URL in the cache. If it is successful then the content of that cache entry are written to the client, otherwise it returns false.
4. Which of these variables stores the number of hits that are successfully served out of cache?
[A] hits
[B] hitstocache
[C] hits_to_cache
[D] hits.to.cache

Answer: D. hits.to.cache

Explanation:

none
5. Which of these class is used for operating on request from the client to the server?
[A] http
[B] httpDecoder
[C] httpConnection
[D] httpd

Answer: D. httpd

Explanation:

None.
6. Which of these method of httpd class is used to write UrlCacheEntry object into local disk?
[A] writeDiskCache()
[B] writetoDisk()
[C] writeCache()
[D] writeDiskEntry()

Answer: A. writeDiskCache()

Explanation:

The writeDiskCache() method takes an UrlCacheEntry object and writes it persistently into the local disk. It constructs directory names out of URL, making sure to replace the slash(/) characters with system dependent seperatorChar.
7. What is the output of this program?

 import java.net.*;
    class networking {
        public static void main(String[] args) throws Exception {
            URL obj = new URL("http://www.sanfoundry.com/javamcq");
            URLConnection obj1 = obj.openConnection();
            int len = obj1.getContentLength();
            System.out.print(len);
        }
    }
[A] 126
[B] 127
[C] Compilation Error
[D] Runtime Error

Answer: B. 127

Explanation:

Host URL is having length of content 127.
8. Which of these method is used to start a server thread?
[A] run()
[B] start()
[C] runThread()
[D] startThread()

Answer: A. run()

Explanation:

run() method is caleed when the server thread is started.
9. Which of these method is called when http daemon is acting like a normal web server?
[A] Handle()
[B] HandleGet()
[C] handleGet()
[D] Handleget()

Answer: C. handleGet()

Explanation:

none
10. What is the output of this program?

    import java.net.*;
    class networking {
        public static void main(String[] args) throws UnknownHostException {
            InetAddress obj1 = InetAddress.getByName("cisco.com");
            System.out.print(obj1.getHostName());
        }
    }
[A] cisco
[B] cisco.com
[C] www.cisco.com
[D] None of the mentioned

Answer: B. cisco.com

Explanation:

none

Comments: (Your feedback is valuable to us)
;