1. Which of these stream contains the classes which can work on character stream?
a) InputStream
b) OutputStream
c) Character Stream
d) All of the mentioned
2. Which of these class is used to read characters in a file?
a) FileReader
b) FileWriter
c) FileInputStream
d) InputStreamReader
3. Which of these method of FileReader class is used to read characters from a file?
a) read()
b) scanf()
c) get()
d) getInteger()
4. Which of these class can be used to implement input stream that uses a character array as the source?
a) BufferedReader
b) FileReader
c) CharArrayReader
d) FileArrayReader
5. Which of these is a method to clear all the data present in output buffers?
a) clear()
b) flush()
c) fflush()
d) close()
6. Which of these classes can return more than one character to be returned to input stream?
a) BufferedReader
b) Bufferedwriter
c) PushbachReader
d) CharArrayReader
7. What is the output of this program?
1.import java.io.*;
2.class filesinputoutput {
3. public static void main(String args[]) {
4. InputStream obj = new FileInputStream(“inputoutput.java”);
5. System.out.print(obj.available());
6. }
7.}
Note: inputoutput.java is stored in the disk.
a) true
b) false
c) prints number of bytes in file
d) prints number of characters in the file
8. What is the output of this program?
1.import java.io.*;
2.class Chararrayinput {
3. public static void main(String[] args) {
4. String obj = “abcdef”;
5. int length = obj.length();
6. char c[] = new char[length];
7. obj.getChars(0,length,c,0);
8. CharArrayReader input1 = new CharArrayReader(c);
9. CharArrayReader input2 = new CharArrayReader(c, 0, 3);
10. int i;
11. try {
12. while ((i = input1.read()) != -1) {
13. System.out.print((char)i);
14. }
15. }
16. catch (IOException e) {
17. // TODO Auto-generated catch block
18. e.printStackTrace();
19. }
20. }
21.}
a) abc
b) abcd
c) abcde
d) abcdef
9. What is the output of this program?
1.import java.io.*;
2.class Chararrayinput {
3. public static void main(String[] args) {
4. String obj = “abcdef”;
5. int length = obj.length();
6. char c[] = new char[length];
7. obj.getChars(0, length, c, 0);
8. CharArrayReader input1 = new CharArrayReader(c);
9. CharArrayReader input2 = new CharArrayReader(c, 0, 3);
10. int i;
11. try {
12. while ((i = input2.read()) != -1) {
13. System.out.print((char)i);
14. }
15. }
16. catch (IOException e) {
17. // TODO Auto-generated catch block
18. e.printStackTrace();
19. }
20. }
21.}
a) abc
b) abcd
c) abcde
d) abcdef
10. What is the output of this program?
1.import java.io.*;
2.class Chararrayinput {
3. public static void main(String[] args) {
4. String obj = “abcdefgh”;
5. int length = obj.length();
6. char c[] = new char[length];
7. obj.getChars(0, length, c, 0);
8. CharArrayReader input1 = new CharArrayReader(c);
9. CharArrayReader input2 = new CharArrayReader(c, 1, 4);
10. int i;
11. int j;
12. try {
13. while ((i = input1.read()) == (j = input2.read())) {
14. System.out.print((char)i);
15. }
16. }
17. catch (IOException e) {
18. // TODO Auto-generated catch block
19. e.printStackTrace();
20. }
21. }
22.}
a) abc
b) abcd
c) abcde
d) None of the mentioned
11. What does URL stands for?
a) Uniform Resource Locator
b) Uniform Resource Latch
c) Universal Resource Locator
d) Universal Resource Latch
12. Which of these exception is thrown by URL class’s constructors?
a) URLNotFound
b) URLSourceNotFound
c) MalformedURLException
d) URLNotFoundException
13. Which of these methods is used to know host of an URL?
a) host()
b) getHost()
c) GetHost()
d) gethost()
14. Which of these methods is used to know the full URL of an URL object?
a) fullHost()
b) getHost()
c) ExternalForm()
d) toExternalForm()
15. Which of these class is used to access actual bits or content information of a URL?
a) URL
b) URLDecoder
c) URLConnection
d) All of the mentioned
16. Which of these class is used to encapsulate IP address and DNS?
a) DatagramPacket
b) URL
c) InetAddress
d) ContentHandler
17. What is the output of this program?
1.import java.net.*;
2.class networking {
3. public static void main(String[] args) throws MalformedURLException {
4. URL obj = new URL(“http://www.sanfoundry.com/javamcq”);
5. System.out.print(obj.getProtocol());
6. }
7.}
a) http
b) https
c) www
d) com
18. What is the output of this program?
1.import java.net.*;
2.class networking {
3. public static void main(String[] args) throws MalformedURLException {
4. URL obj = new URL(“http://www.sanfoundry.com/javamcq”);
5. System.out.print(obj.getPort());
6. }
7.}
a) 1
b) 0
c) -1
d) garbage value
19. What is the output of this program?
1.import java.net.*;
2.class networking {
3. public static void main(String[] args) throws MalformedURLException {
4. URL obj = new URL(“http://www.sanfoundry.com/javamcq”);
5. System.out.print(obj.getHost());
6. }
7.}
a) sanfoundry
b) sanfoundry.com
c) www.sanfoundry.com
d) http://www.sanfoundry.com/javamcq
20. What is the output of this program?
1.import java.net.*;
2.class networking {
3. public static void main(String[] args) throws MalformedURLException {
4. URL obj = new URL(“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
21. Which of these methods of httpd class is used to read data from the stream?
a) getDta()
b) GetResponse()
c) getStream()
d) getRawRequest()
22. 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()
23. Which of these method is used to find a URL from the cache of httpd?
a) findfromCache()
b) findFromCache()
c) serveFromCache()
d) getFromCache().
24. 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
25. Which of these class is used for operating on request from the client to the server?
a) http
b) httpDecoder
c) httpConnection
d) httpd
26. Which of these method of httpd class is used to write UrlCacheEntry object into local disk?
a) writeDiskCache()
b) writetoDisk()
c) writeCache()
d) writeDiskEntry()
27. What is the output of this program?
1.import java.net.*;
2.class networking {
3. public static void main(String[] args) throws Exception {
4. URL obj = new URL(“http://www.sanfoundry.com/javamcq”);
5. URLConnection obj1 = obj.openConnection();
6. int len = obj1.getContentLength();
7. System.out.print(len);
8. }
9.}
Note: Host URL is having length of content 127.
a) 126
b) 127
c) Compilation Error
d) Runtime Error
28. Which of these method is used to start a server thread?
a) run()
b) start()
c) runThread()
d) startThread()
29. Which of these method is called when http daemon is acting like a normal web server?
a) Handle()
b) HandleGet()
c) handleGet()
d) Handleget()
30. What is the output of this program?
1.import java.net.*;
2.class networking {
3. public static void main(String[] args) throws UnknownHostException {
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
Answers
1-c | 2-a | 3-a | 4-c | 5-b |
6-c | 7-c | 8-d | 9-a | 10-d |
11-a | 12-b | 13-d | 14-d | 15-c |
16-a | 17-c | 18-c | 19-d | 20-d |
21-b | 22-c | 23-c | 24-d | 25-d |
26-a | 27-b | 28-a | 29-c | 30-b |