My Report (&Account)

Java Online Test


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

Here is the complete list of test quizzes on Java.

1. What will be the output of the following Java program if input given is "abc'def/'egh"?

 
    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 != '\'');
        }
    }

Question 1 of 50

2. Arrays in Java are implemented as?

Question 2 of 50

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

 
    import java.net.*;
    class networking
    {
        public static void main(String[] args) throws MalformedURLException 
        {
            URL obj = new URL("https://www.sanfoundry.com/javamcq");
            System.out.print(obj.getHost());
        }
    }

Question 3 of 50

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

 
    import java.text.*;
    import java.util.*;
    class Date_formatting
    {	 
        public static void main(String args[])
        {
	    Date date = new Date();
	    SimpleDateFormat sdf;
            sdf = new SimpleDateFormat("z");
            System.out.print(sdf.format(date));
        }	
    }

Note : The program is executed at 3 hour 55 minutes and 4 sec on Monday, 15 July(24 hours time).

Question 4 of 50

5. Which of the below statement about JUnit is false?

Question 5 of 50

6. Which of the below is not an implementation of List interface?

Question 6 of 50

7. What is it called where object has its own lifecycle and child object cannot belong to another parent object?

Question 7 of 50

8. What is BigDecimal.ONE?

Question 8 of 50

9. What will be the output of the following Java code snippet?

enum Enums
{
    A, B, C;
     
    private Enums()
    {
        System.out.println(10);
    }
}
 
public class MainClass
{
    public static void main(String[] args)
    {
        Enum en = Enums.B;
    }
}

Question 9 of 50

10. Which of these operators can skip evaluating right hand operand?

Question 10 of 50

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

 
    import java.io.*;
    class Chararrayinput
    {
        public static void main(String[] args)
        {
	    String obj  = "abcdefgh";
            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, 1, 4);
            int i;
            int j;
            try
            {
		while((i = input1.read()) == (j = input2.read()))
                {
                    System.out.print((char)i);
                }
       	    } 
            catch (IOException e)
            {
                e.printStackTrace();
	    }
	}
    }

Question 11 of 50

12. Which of these Exception handlers cannot be type parameterized?

Question 12 of 50

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

 
    import java.util.*;
    class Arraylist 
    {
        public static void main(String args[]) 
        {
            ArrayList obj = new ArrayList();
            obj.add("A");
            obj.add("B");
            obj.add("C");
            obj.add(1, "D");
            System.out.println(obj);
        }
    }

Question 13 of 50

14. Which of the following is not a class of java.util.regex?

Question 14 of 50

15. Which of these is returned by "greater than", "less than" and "equal to" operators?

Question 15 of 50

16. How many bits are in a single IP address?

Question 16 of 50

17. Which of these packages contain all the Java's built in exceptions?

Question 17 of 50

18. Which class provides system independent server side implementation?

Question 18 of 50

19. What will be the output of the following Java code?

 
    class exception_handling 
    {
        public static void main(String args[]) 
        {
            try 
            {
                int a = args.length;
                int b = 10 / a;
                System.out.print(a);
                try 
                {
                     if (a == 1)
                         a = a / a - a;
                     if (a == 2) 
                     {
                         int []c = {1};
                         c[8] = 9;
                     }
                }
                catch (ArrayIndexOutOfBoundException e) 
                {
                    System.out.println("TypeA");
                }
            catch (ArithmeticException e) 
            {
                    System.out.println("TypeB");
            }
        }
    }

Note: Execution command line: $ java exception_handling one two

Question 19 of 50

20. What is the value returned by function compareTo() if the invoking string is less than the string compared?

Question 20 of 50

21. Which of these method of FileReader class is used to read characters from a file?

Question 21 of 50

22. Which of these method is used to insert value and its key?

Question 22 of 50

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

    class array_output 
    {
        public static void main(String args[]) 
        {
       	    int array_variable [] = new int[10];
	    for (int i = 0; i < 10; ++i) {
                array_variable[i] = i/2;
                array_variable[i]++;
                System.out.print(array_variable[i] + " ");
                i++;
            }
                	
        } 
    }

Question 23 of 50

24. 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) 
            {
	        // TODO Auto-generated catch block
                e.printStackTrace();
	    }
	}
    }

Question 24 of 50

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

 
    class X 
    {
        int a;
        double b;
    }
    class Y extends X 
    {
	int c;
    }
    class Output 
    {
        public static void main(String args[]) 
        {
            X a = new X();
            Y b = new Y();
            Class obj;
            obj = a.getClass();
            System.out.print(obj.getName());
        }
    }

Question 25 of 50

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

    class jump_statments 
    {
        public static void main(String args[]) 
        {        
             int x = 2;
             int y = 0;
             for ( ; y < 10; ++y) 
             {
                 if (y % x == 0) 
                     continue;  
                 else if (y == 8)
                      break;
                 else
                    System.out.print(y + " ");
             }
        } 
    }

Question 26 of 50

27. Which of these standard collection classes implements a dynamic array?

Question 27 of 50

28. Which of the below is not a valid classification of design pattern?

Question 28 of 50

29. Which of these method of HashSet class is used to add elements to its object?

Question 29 of 50

30. What does not prevent JVM from terminating?

Question 30 of 50

31. Which of these method converts radians to degrees?

Question 31 of 50

32. What is the string contained in s after following lines of Java code?

 
StringBuffer s = new StringBuffer("Hello");
s.deleteCharAt(0); 

Question 32 of 50

33. Which of these interface is not a member of java.io package?

Question 33 of 50

34. What does setAutoCommit(false) do?

Question 34 of 50

35. What will be the output of the following Java code?

public class Shape 
{
	public int area()
        {
		return 1;
	}
}
public class Square extends Shape 
{
	public int area()
        {
		return 2;
	}
}
public class Rectangle extends Shape 
{
	public int area()
        {
		return 3;
	}
}
public static void main(String[] args)
{
	 Shape shape = new Square();
   	 shape = new Rectangle();
	 System.out.println(shape.area());
}

Question 35 of 50

36. Which of the following are incorrect form of StringBuffer class constructor?

Question 36 of 50

37. What causes the program to exit abruptly and hence its usage should be minimalistic?

Question 37 of 50

38. Which of the following will ensure the thread will be in running state?

Question 38 of 50

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

    public class BoxDemo 
    {
        public static <U> void addBox(U u, 
        java.util.List<Box<U>> boxes) 
        {
           Box<U> box = new Box<>();
           box.set(u);
           boxes.add(box);
        }
        public static <U> void outputBoxes(java.util.List<Box<U>> boxes)
        {
            int counter = 0;
            for (Box<U> box: boxes) 
            {
                U boxContents = box.get();
                System.out.println("Box #" + counter + " contains [" + boxContents.toString() + "]");
                counter++;
            }
        }        
        public static void main(String[] args)
        {
            java.util.ArrayList<Box<Integer>> listOfIntegerBoxes = new java.util.ArrayList<>();
            BoxDemo.<Integer>addBox(Integer.valueOf(10), listOfIntegerBoxes);
            BoxDemo.outputBoxes(listOfIntegerBoxes);
        }
    }

Question 39 of 50

40. Which of the following statements are incorrect?

Question 40 of 50

41. What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?

Question 41 of 50

42. Which of the following is true about Java system properties?

Question 42 of 50

43. Which of these class is related to all the exceptions that cannot be caught?

Question 43 of 50

44. At line number 2 in the following code, choose 3 valid data-type attributes/qualifiers among "final, static, native, public, private, abstract, protected"

public interface Status
   {
        /* insert qualifier here */ int MY_VALUE = 10;
   }

Question 44 of 50

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

 
    class string_class 
    {
        public static void main(String args[])
        {
            String obj = "I LIKE JAVA";   
            System.out.println(obj.length());
        }
    }

Question 45 of 50

46. Which of these is not a correct statement?

Question 46 of 50

47. Which of these is a superclass of all Adapter classes?

Question 47 of 50

48. Which component can be used for sending messages from one application to another?

Question 48 of 50

49. Which of these is static variable defined in Collections?

Question 49 of 50

50. Which option is true about session scope?

Question 50 of 50


 

Topic wise Test Quizzes on Java

Java tests, quizzes, and exams are great ways to learn and test your Java programming skills. Whether you’re a beginner or experienced, challenge and boost your confidence with our engaging online quizzes on Java basics, oops, arrays, exceptions, constructors, collections, multithreading, JDBC, and advanced java. Start the Java online test now!



Java Programming Certification Test

Java Programming Certification Test is a free certification exam. However, you need to score an A grade in each of the "Certification Level Tests 1 to 10" to be eligible to take part in this certification test. So, take all the "10 Tests" starting from Certification Level 1 upto Level 10, before taking the final Certification test.


Level 1 to 10 Tests:
Total Questions: 25, Total Time: 30 min, Correct Answer: 2 points, Wrong Answer: -1 point

Certification Test:
Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

Java Programming Internship Test

If you scored either Grade A* or Grade A in our Java Programming Internship Test, then you can apply for Internship at Sanfoundry in Java Programming.


Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

Java Programming Job Test

It is designed to test and improve your skills for a successful career, as well as to apply for jobs.


Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

Note: Before you get started on these series of online tests, you should practice our collection of 1000 MCQs on Java Programming .

Sanfoundry Scoring & Grading System

Sanfoundry tests and quizzes are designed to provide a real-time online exam experience. Here is what you need to know about them.

  • Scoring System: You get 2 points for each correct answer but lose 1 point for every wrong answer.
  • Grading System: Your grade depends on your final score and can be one of the following:

    • Grade A* - Genius (100%)
    • Grade A - Excellent (80% to 99%)
    • Grade B - Good (60% to 80%)
    • Grade C - Average (40% to 60%)
    • Grade D - Poor (0% to 40%)
advertisement
advertisement
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.