Java Multiple Choice Questions & Answers on Java.io Byte Streams for Freshers

1. Which of these classes is used for input and output operation when working with bytes?

a) InputStream
b) Reader
c) Writer
d) All of the mentioned
Answer: a

Explanation: InputStream & OutputStream are designed for byte stream. Reader and writer are designed for character stream.
2. Which of these class is used to read and write bytes in a file?

a) FileReader
b) FileWriter
c) FileInputStream
d) InputStreamReader
Answer: c
3. Which of these method of InputStream is used to read integer representation of next available byte input?

a) read()
b) scanf()
c) get()
d) getInteger()
Answer: a
4. Which of these data type is returned by every method of OutputStream?

a) int
b) float
c) byte
d) None of the mentioned
Answer: d

Explanation: Every method of OutputStream returns void and throws an IOExeption in case of errors.
5. Which of these is a method to clear all the data present in output buffers?

a) clear()
b) flush()
c) fflush()
d) close()
Answer: b
6. Which of these method(s) is/are used for writing bytes to an outputstream?

a) put()
b) print() and write()
c) printf()
d) write() and read()
Answer: b

Explanation: write() and print() are the two methods of OutputStream that are used for printing the byte data.
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
Answer: c

Explanation: obj.available() returns the number of bytes.
8. What is the output of this program?
  1.     import java.io.*;
  2.     public class filesinputoutput {
  3.     	public static void main(String[] args) {
  4.  	   String obj  = "abc";
  5.            byte b[] = obj.getBytes();
  6.            ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
  7.            for (int i = 0; i < 2; ++ i) {
  8.                int c;
  9.                while ((c = obj1.read()) != -1) {
  10.             	   if(i == 0) {
  11.             	       System.out.print((char)c); 
  12.             	   }
  13.                }
  14.            }
  15.         }
  16.     }
a) abc
b) ABC
c) ab
d) AB
Answer: a
9. What is the output of this program?
  1.     import java.io.*;
  2.     public class filesinputoutput {
  3.     	public static void main(String[] args) {
  4.  	   String obj  = "abc";
  5.            byte b[] = obj.getBytes();
  6.            ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
  7.            for (int i = 0; i < 2; ++ i) {
  8.                int c;
  9.                while ((c = obj1.read()) != -1) {
  10.             	   if (i == 0) {
  11.                        System.out.print(Character.toUpperCase((char)c)); 
  12.             	   }
  13.                }
  14.            }
  15.         }
  16.     }
a) abc
b) ABC
c) ab
d) AB
Answer: b
10. What is the output of this program?
  1.     import java.io.*;
  2.     public class filesinputoutput {
  3.     	public static void main(String[] args) {
  4.  	   String obj  = "abc";
  5.            byte b[] = obj.getBytes();
  6.            ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
  7.            for (int i = 0; i < 2; ++ i) {
  8.                int c;
  9.                while ((c = obj1.read()) != -1) {
  10.             	   if (i == 0) {
  11.                        System.out.print(Character.toUpperCase((char)c));
  12.                        obj2.write(1); 
  13.             	   }
  14.                }
  15.                System.out.print(obj2);
  16.            }
  17.         }
  18.     }
a) AaBaCa
b) ABCaaa
c) AaaBaaCaa
d) AaBaaCaaa
Answer: d

Related

C Programming Multiple Choice Questions and Answers on Standard Input & Output Functions for Freshers

1. Which among the following is odd one out? a) printfb) fprintfc) putchard) scanf Answer: d 2. For a typical program, the input is taken using a) scanfb) Filesc) Command-lined) All of the menti...

CSS Multiple Choice Questions & Answers on CSS3 Animations with SVG and Filters for Freshers

1. What does SVG stands for? a) Scaled Vector Graphb) Scalable Vector Graphicsc) Scaled Vector Graphicsd) None of the mentioned Answer: b 2. Which of the following element is used to begin an SVG...

Java Multiple Choice Questions & Answers on Implementing Runnable interface for Threads for Freshers

1. Which of these method is used to implement Runnable interface? a) stop()b) run()c) runThread()d) stopThread() Answer: b Explanation: To implement Runnable interface, a class needs only to impl...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item