My Report

Java I/O Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Which of these data type is returned by every method of OutputStream?

2. What will be the output of the following Java program?

 
    import java.io.*;
    public class filesinputoutput 
    {
    	public static void main(String[] args) 
        {
 	   String obj  = "abc";
           byte b[] = obj.getBytes();
           ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
           for (int i = 0; i < 2; ++ i) 
           {
               int c;
               while ((c = obj1.read()) != -1) 
               {
            	   if (i == 0) 
                   {
                       System.out.print(Character.toUpperCase((char)c)); 
            	   }
               }
           }
        }
    }

3. Which of these method of InputStream is used to read integer representation of next available byte input?

4. Which of these class is used to read and write bytes in a file?

5. What will be the output of the following Java program?

 
    import java.io.*;
    public class filesinputoutput 
    {
    	public static void main(String[] args) 
        {
 	   String obj  = "abc";
           byte b[] = obj.getBytes();
           ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
           for (int i = 0; i < 2; ++ i) 
           {
               int c;
               while ((c = obj1.read()) != -1) 
               {
            	   if(i == 0) 
                   {
            	       System.out.print((char)c); 
            	   }
               }
           }
        }
    }

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

7. Which of these is a method to clear all the data present in output buffers?

8. What will be the output of the following Java program? (Note: inputoutput.java is stored in the disk.)

 
    import java.io.*;
    class filesinputoutput 
    {
        public static void main(String args[]) 
        {
            InputStream obj = new FileInputStream("inputoutput.java");
            System.out.print(obj.available());
        }
    }

9. What will be the output of the following Java program?

 
    import java.io.*;
    public class filesinputoutput 
    {
    	public static void main(String[] args) 
        {
 	   String obj  = "abc";
           byte b[] = obj.getBytes();
           ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
           for (int i = 0; i < 2; ++ i) 
           {
               int c;
               while ((c = obj1.read()) != -1) 
               {
            	   if (i == 0) 
                   {
                       System.out.print(Character.toUpperCase((char)c));
                       obj2.write(1); 
            	   }
               }
               System.out.print(obj2);
           }
        }
    }

10. Which of these method(s) is/are used for writing bytes to an outputstream?


 

Start practicing “1000 MCQs on Java”, and once you are ready, you can take tests on all topics by attempting our “Java Test Series”.

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.