Test Your Java 6


Test Your Java 7 and Test Your Java 8 are advanced questions. Answers are given for each question at the end of each test. Answering these questions increases your knowledge in Java and helps you a lot when you appear for interviews. Solving these basic questions is your first step for Certification Exams preparation.

  1. Java's multithreading is platform
    a) dependent b) Independent c) none
  2. Java can not run on windows 3.1 as Windows 3.1 does not support multi-threading.
    a) True b) False
  3. Method isAlive() returns true if a method stop has been called to temporarily stop the thread from execution.
    a) True b) False
  4. Which one of the following methods keeps the Thread t in run state ?
    a) t.start() b) t.run() c) t.setRun( ) d) t.stop e) when a thread is instantiated, it comes automatically into run state f) none
  5. Both the methods sleep and join throws InterruptedException.
    a) True b) False
  6. If the argument passed to the thread’s method setPriority( ) is not in the range of 1 to 10 (both inclusive), the method throws
    a) ArithmeticException b) IllegalArgumentException c) IllegalValueException d) none
  7. sleep(50);
    The above statement of a thread implies that the thread will get the processor-time
    a) any moment after 50 milliseconds b)exactly after 50 milliseconds c) even before 50 milliseconds if the processor is idle d) none
  8. If a thread is to be declared as a daemon thread, it must be declared before
    a) start method b) run method c) stop method d) a or b or c e) none
  9. If you declare an object as null, the garbage collector immediately comes into action and frees the memory occupied by the object.
    a) True b) False
  10. Mr. Vijay has written an application without using any thread priorities. When he runs the program, does JVM impose any thread priorities on the code ?
    a) imposes b) does not impose c) depends on the underlying system d) none
  11. A thread enters the dead state after completing its run method or when stop method is called. The stop method sends a ThreadDeath object on to the thread. The ThreadDeath is a subclass of _______.
    a) Exception b) Error c) both and depends on the source code d) none
  12. t1.setPriority(hread.MAX_PRIORITY);
    t2.setPriority( Thread.MIN_PRIORITY);
    In the above code t1 and t2 are two threads. Imagine only one thread either t1 or t2 runs at a time on the system. The time taken to execute a certain code by t1 is lessor than t2 as t1 is set to more priority than t2.
    a) True b) False
  13. Color clr = new Color (Color.red);
    The above statement produces same intensity of red color on any color monitor as Java is platform independent.
    a) True b) False
  14. private float red = 0.5f, green = 0.5f , blue = 0.5f ;
    public void paint( Graphics g) {
    g.setColor ( new Color ( red, green, blue) ) ;
    g.drawString ( g.getColor( ).toString( ), 50, 75 ) ; }
    What are the color values given by the drawString( ) method of the above program?
    a) 127, 127, 127 b) 0.5, 0.5, 0.5 c) depends on the underlying system d ) does not compile as the program is error prone e) none
  15. .
         public void paint(Graphics g)
         {
           g.setColor(Color.magenta);
           g.drawString("way2java.com", 0, 0);
         }

    Which statement is true of the following ?
    a) output is way2java.com in magenta color and is visible in the window.
    b) output is way2java.com in magenta color and is not visible in the window.
    c) output is way2java.com in default color and is visible in the window.
    a) Does not compile e) none

  16. .
         public void paint(Graphics g)
         {  
           g.setColor(new Color(300, 300, 300));   
         }

    The output of the above fraction of program is a color that is set implicitly to the range 255,255,255.
    a) as 255 is the maximum limit of the color range.
    b) as the values are out of the specified range ( 0 to 255 ), an exception is thrown like "IllegalArgumentException". c) does not compile d) none

  17. setFont (14);
    The above statement sets a text of size 14 points.
    a) True b) False
  18. If the font name given in the font object is not found in the font list of the system., the JVM will
    a) throw an exception b) does not compile c) substitute that system’s default font.
    d) compiles but nothing is displayed e) none
  19. .
         public void paint(Graphics g)
         {
           g.setFont(new Font("Dialog", Font.PLAIN, 20));
           g.drawString("The Ascent of the font is " + g.getAscent(), 100, 150 ) ;   
         }
    

    The above fraction of code displays the Ascent of the font.
    a) True b) False

  20. To get the font list of available fonts, we have to invoke a method defined in
    a) String b) Font c) Graphics d) FontMetrics e) Toolkit f) none
  21. .
         public void paint(Graphics g)
         {
           g.setColor(Color.red ) ;
           g.drawLine(10, 10, 200, 200);
           g.setColor(Color.green);
           g.drawLine(200, 200, 10, 10); 
    }
    

    The output of the above paint method will be
    a) two intersecting lines of red and green color. b) Two parallel lines of red and green color. c) Two coincided lines in red color. d) Two coincided lines in green color. e) Depends on the underlying system. f) none

  22. g.fillArc(30, 50, 80, 80, 30, 100);
    In the above statement, the parameter values are in pixels.
    a) True b) False
  23. What is the width of the line that drawLine() method draws?
    a) 1 pixel b) 2 pixel c) 3 pixel d) 4 pixels d) none
  24. .
         public void paint(Graphics g)
         {
    	g.setColor(Color.red);
    	drawRect(50, 50, 200, 250);
            g.setColor(Color.blue); 
         }
    

    The color of the rectangle drawn is
    a) default color b) red c) blue d) none

  25. .
         public void paint(Graphics g)  
         {
           g.setColor(Color.green);
           g.fillRect(50, 50, 200, 200);
           g.setColor(Color. red);
           g.drawRect(50, 50, 200, 200);   
         }

    The above paint method draws a rectangle filled with green color with red border.
    a) True b) False

ANSWERS

1. a 2. b 3. b 4. a 5. a
6. b 7. a 8. a 9. b 10. a
11. b 12. b 13. b 14. a 15. d
16. b 17. b 18. c 19. b 20. e
21. d 22. b 23. a 24. b 25. a

Your Rating

Correct Answers
1 to 5 : Poor
6 t0 10: Below average
11 t0 15: Average
16 to 20: Good
Above 20: Extraordinary

Pass your suggestions for the improvement of this "Test Your Java 6".

5 thoughts on “Test Your Java 6”

  1. In the above first question you mentioned answer choice is “e” but in question only three options is there. Can you help me out this.

Leave a Comment

Your email address will not be published.