My Report

Java Programming Practice Test 8


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. What will be the output of the following Java program if input given is 'abcqfghqbcd'?

 
    class Input_Output
    {
        public static void main(String args[]) throws IOException
        {	 
            char c;
            BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
            do
            {
                c = (char) obj.read();
	        System.out.print(c);
            } while(c != 'q');
        }
    }

2. Which class is used to generate random number?

3. Which of the following matches end of the string using regular expression in java?

4. Which of these methods will respond when you click any button by mouse?

5. Which of these exception is thrown by close() and read() methods?

6. What will be the output of the following Java program if input given is "Hello stop World"?

 
    class Input_Output 
    {
        public static void main(String args[]) throws IOException
        {	 
            string str;
            BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
            do
            {
                str = (char) obj.readLine();
	        System.out.print(str);
            } while(!str.equals("strong"));
        }
    }

7. Which of these class is implemented by FilterInputStream class?

8. Which of these methods is used to notify observer the change in observed object?

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

 
    import java.io.*;
    class Chararrayinput
    {
        public static void main(String[] args)
        {
	    String obj  = "abcdef";
            int length = obj.length();
            char c[] = new char[length];
            obj.getChars(0, length, c, 0);
            CharArrayReader input1 = new CharArrayReader(c);
            CharArrayReader input2 = new CharArrayReader(c, 0, 3);
            int i;
            try
            {
		while((i = input2.read()) != -1)
                {
                    System.out.print((char)i);
                }
       	    } 
            catch (IOException e)
            {
                e.printStackTrace();
	    }
	}
    }

10. Which of these methods is called when observed object has changed?


 

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.