Test Your Java 5


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.

Test Your Java 5

  1. g.drawRoundRect(50, 50, 100, 100, 200, 200);
    The above statement produces a
    a) rectangle b) rounded rectangle c) square d) rounded square e) circle f) none
  2. Frame and panels are called containers having a title bar.
    a) True b) False
  3. MenuComponent is the subclass of Component.
    a) True b) False
  4. Which of the following uses a drop-down (popup window) list.
    a) Choice b) List c) a and b d) TextArea e) Canvas f) none )
  5. If a component is to be redrawn, ___________________ method is to be called.
    a) paint() b) repaint() c) update() d) remove() e) none
  6. Scrollbar generates _________________ event.
    a) Action b) Item c) Adjustment d) Mouse and MouseMotion e) none
  7. What is the default alignment for Label ?
    a) left b) center c) right d) none
  8. Name two components that do not generate any events?
    Your answer here ______________ and ______________ .
  9. Radio buttons are a group of buttons (created by instantiating Button class) with a distinct name.
    a) True b) False
  10. .
         public void init()   
         {
           CheckboxGroup cbg = new CheckboxGroup();
           Checkbox cb = new Checkbox("Open", cbg, true);     
           add(cbg);    
         }
    

    The above fraction of code displays the checkbox cb with the label Open.
    a) True b) False

  11. .
         Choice c1 = new Choice();
         c1.additem("White");   
         c1.add("Black");  
         c1.add("Green");  
         c1.insert("Red", 10);
         add(c1, "Center");
         System.out.println(c1.getItemCount()); 

    The output of the println statement is
    a) 4 b) 3 c) 5 d) 10 e) none

  12. We can not create a dialog box to an applet.
    State a) True b) false
  13. List method getRows() returns the total number of items in the list.
    a) True b) False
  14. The superclass of java.awt.AWTEvent is java.util.EvenObject.
    a) True b) False
  15. ActionListener interface contains _____________ number of methods.
    a) 1 b) 2 c) 3 d) more than 3 e) none
  16. Button, List, MenuItem and TextField : all are handled by ActionListener.
    a) True b) False
  17. The interface AdjustmentListener contains the method
    a) public void adjustmentValueChanged(AdjustmentEvent e);
    b) public void adjustmentStateChanged(AdjustmentEvent e);
    c) public void adjustmentChanged(AdjustmentEvent e);
    d) public void adjustmentValuePerformed(AdjustmentEvent e); e) none
  18. Button btn = new Button(“Open”);
    btn.addItemListener(this);
    In the above code, Button btn has registered with ItemListener instead of ActionListener.
    a) The code does not compile b) compiles but throws exception
    c) compiles, runs but events are not caught d) none
  19. java.awt.AWTEvent differentiates the events by their
    a) getEvent() b) EVENT_MASK c) id d) processEvent() e) none
  20. The default implementation of each method in an adapter class has an empty body.
    a) True b) False
  21. What is the default spacing (in pixels) in between the components in a FlowLayout Manager?
    a) 0 b) 5 c) 10 d) depends only on the value we give e) none
  22. A panel is placed inside a Frame container. What layout is adopted by the panel implicitly?
    a) FlowLayout b) BorderLayout c) GridLayout d) a or b e) none
  23. Which of the following layout manager honors the preferred size of the component.
    a) FlowLayout b) BorderLayout c) GridLayout d) a or b e) none
  24. Component List can listen to both ActionListener and ItemListener.
    a) True b) False
  25. Graphics g = new Graphics();
    public void paint(g) { g.drawString(“Hello”, 25, 50); }
    The above program displays Hello at co-ordinates 25, 50.
    a) True b) False

ANSWERS

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

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 comments and suggestions for the improvement of this "Test Your Java 5".

Leave a Comment

Your email address will not be published.