0% found this document useful (0 votes)
103 views

Java - Unit 4,5 Quiz

The document discusses Java collection framework and utilities. It contains 30 multiple choice questions about Java collection classes and interfaces, common collection methods like add, remove, clear, size, and more. It also covers the ArrayList class and how to manipulate ArrayList objects. The last part discusses layout managers and event handling in Java with 20 multiple choice questions about key listeners, mouse listeners, event classes, and common event types.

Uploaded by

Aditya Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views

Java - Unit 4,5 Quiz

The document discusses Java collection framework and utilities. It contains 30 multiple choice questions about Java collection classes and interfaces, common collection methods like add, remove, clear, size, and more. It also covers the ArrayList class and how to manipulate ArrayList objects. The last part discusses layout managers and event handling in Java with 20 multiple choice questions about key listeners, mouse listeners, event classes, and common event types.

Uploaded by

Aditya Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Collection Framework and Util package

1. Which of these packages contain all the collection classes?


a) java.lang
b) java.util
c) java.net
d) java.awt
2. Which of these classes is not part of Java’s collection framework?
a) Maps
b) Array
c) Stack
d) Queue
3. Which of this interface is not a part of Java’s collection framework?
a) List
b) Set
c) SortedMap
d) SortedList
4. Which of these methods deletes all the elements from invoking collection?
a) clear()
b) reset()
c) delete()
d) refresh()
5.  What is Collection in Java?
a) A group of objects
b) A group of classes
c) A group of interfaces
d) None of the mentioned
6. Which of these standard collection classes implements a dynamic array?
a) AbstractList
b) LinkedList
c) ArrayList
d) AbstractSet
7. Which of these class can generate an array which can increase and decrease in size
automatically?
a) ArrayList()
b) DynamicList()
c) LinkedList()
d) MallocList()
8. Which of these method can be used to increase the capacity of ArrayList object manually?
a) Capacity()
b) increaseCapacity()
c) increasecapacity()
d) ensureCapacity()
9. Which of these method of ArrayList class is used to obtain present size of an object?
a) size()
b) length()
c) index()
d) capacity()
10. Which of these methods can be used to obtain a static array from an ArrayList object?
a) Array()
b) covertArray()
c) toArray()
d) covertoArray()
11. Which of these method is used to reduce the capacity of an ArrayList object?
a) trim()
b) trimSize()
c) trimTosize()
d) trimToSize()

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

1. import java.util.*;
2. class Arraylist
3. {
4. public static void main(String args[])
5. {
6. ArrayList obj = new ArrayList();
7. obj.add("A");
8. obj.add("B");
9. obj.add("C");
10. obj.add(1, "D");
11. System.out.println(obj);
12. }
13. }
a) [A, B, C, D]
b) [A, D, B, C]
c) [A, D, C]
d) [A, B, C]

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

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

a)0
b)1
c)2
d) Any Garbage Value
14. What will be the output of the following Java program?

class Output
{
public static void main(String args[])
{
ArrayList obj = new ArrayList();
obj.add("A");
obj.add("D");
obj.ensureCapacity(3);
obj.trimToSize();
System.out.println(obj.size());
}
}
a)1
b)2
c)3
d) 4
15. Map implements collection interface?
a) True
b) False
16. Which of the below does not implement Map interface?
a) HashMap
b) Hashtable
c) EnumMap
d) Vector
17. How can we remove an object from ArrayList?
a) remove() method
b) using Iterator
c) remove() method and using Iterator
d) delete() method
18. How to remove duplicates from List?
a) HashSet<String> listToSet = new HashSet<String>(duplicateList);
b) HashSet<String> listToSet = duplicateList.toSet();
c) HashSet<String> listToSet = Collections.convertToSet(duplicateList);
d) HashSet<String> listToSet = duplicateList.getSet();

19. How to sort elements of ArrayList?


a) Collection.sort(listObj);
b) Collections.sort(listObj);
c) listObj.sort();
d) Sorter.sortAsc(listObj);

20. What is the difference between length() and size() of ArrayList?


a) length() and size() return the same value
b) length() is not defined in ArrayList
c) size() is not defined in ArrayList
d) length() returns the capacity of ArrayList and size() returns the actual number of
elements stored in the list

21. What is the relation between hashset and hashmap?


a) HashSet internally implements HashMap
b) HashMap internally implements HashSet
c) HashMap is the interface; HashSet is the concrete class
d) HashSet is the interface; HashMap is the concrete class
22. What is the difference between TreeSet and SortedSet?
a) TreeSet is more efficient than SortedSet
b) SortedSet is more efficient than TreeSet
c) TreeSet is an interface; SortedSet is a concrete class
d) SortedSet is an interface; TreeSet is a concrete class

23. What is the unique feature of LinkedHashSet?


a) It is not a valid class
b) It maintains the insertion order and guarantees uniqueness
c) It provides a way to store key values with uniqueness
d) The elements in the collection are linked to each other

24. What is the return type of Math.random() method?


a) Integer
b) Double
c) String
d) Boolean

25. Random is a final class?


a) True
b) False

26. What is the range of numbers returned by Math.random() method?


a) -1.0 to 1.0
b) -1 to 1
c) 0 to 100
d) 0.0 to 1.0

27. How many bits are used for generating random numbers?
a) 32
b) 64
c) 48
d) 8

28. What will be the output of the following Java code snippet?
int a = random.nextInt(15) + 1;
a) Random number between 1 to 15, including 1 and 15
b) Random number between 1 to 15, excluding 15
c) Random number between 1 to 15, excluding 1
d) Random number between 1 to 15, excluding 1 and 15

29. What is the signature of Math.random() method?


a) public static double random()
b) public void double random()
c) public static int random()
d) public void int random()

30. Which of the following is the default Layout Manager for an Applet?
(a) FlowLayout
(b) BorderLayout
(c) GridLayout
(d) CardLayout
31. Which Scanner class method is used to read interger values from the user?
(a) next()
(b) nextInt()
(c) readInt()
(d) nextInteger()

31. Which Scanner class method is used to read string values from the user?
(a) nextLine()
(b) next()
(c) nextString()
(d) Both a and b

32. Which of these class object has an architecture similar to that of array?
a) Bitset
b) Map
c) Hashtable
d) All of the above

33.  Which of these method is used to calculate number of bits required to hold the BitSet
object?
a) size()
b) length()
c) indexes()
d) numberofBits()

34. Which of these class object uses the key to store value?
a) Dictionary
b) Map
c) Hashtable
d) All of the mentioned

35. Which of these is the interface of legacy is implemented by Hashtable and Dictionary
classes?
a) Map
b) Enumeration
c) HashMap
d) Hashtable

36. Which of these is a method of class Date which is used to search whether object contains a
date before the specified date?
a) after()
b) contains()
c) before()
d) compareTo()

37. Which of these methods is used to retrieve elements in BitSet object at specific location?
a) get()
b) Elementat()
c) ElementAt()
d) getProperty()

38. Which of these class object can be used to form a dynamic array?
a) ArrayList
b) Map
c) Vector
d) ArrayList & Vector
39. Which of these methods is used to add elements in vector at specific location?
a) add()
b) set()
c) AddElement()
d) addElement()

40. Which of these methods can be used to delete the last element in a LinkedList object?
a) remove()
b) delete()
c) removeLast()
d) deleteLast()
Layout Manger and Event handling

1. Which of these packages contains all the classes and methods required for even handling
in Java?
a) java.applet
b) java.awt
c) java.event
d) java.awt.event

2. What is an event in delegation event model used by Java programming language?


a) An event is an object that describes a state change in a source
b) An event is an object that describes a state change in processing
c) An event is an object that describes any change by the user and system
d) An event is a class used for defining object, to create events

3. Which of these methods are used to register a keyboard event listener?


a) KeyListener()
b) addKistener()
c) addKeyListener()
d) eventKeyboardListener()

4. Which of these methods are used to register a mouse motion listener?


a) addMouse()
b) addMouseListener()
c) addMouseMotionListner()
d) eventMouseMotionListener()

5.  What is a listener in context to event handling?


a) A listener is a variable that is notified when an event occurs
b) A listener is a object that is notified when an event occurs
c) A listener is a method that is notified when an event occurs
d) None of the mentioned

6.  Event class is defined in which of these libraries?


a) java.io
b) java.lang
c) java.net
d) java.util

7. Which of these methods can be used to determine the type of event?


a) getID()
b) getSource()
c) getEvent()
d) getEventObject()

8. Which of these class is super class of all the events?


a) EventObject
b) EventClass
c) ActionEvent
d) ItemEvent

9. Which of these events will be notified if scroll bar is manipulated?


a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent

10. Which of these events will be generated if we close an applet’s window?


a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent

11. Which of these events is generated when a button is pressed?


a) ActionEvent
b) KeyEvent
c) WindowEvent
d) AdjustmentEvent

12. Which of these methods can be used to obtain the command name for invoking
ActionEvent object?
a) getCommand()
b) getActionCommand()
c) getActionEvent()
d) getActionEventCommand()

13. Which of these methods can be used to know which key is pressed?
a) getKey()
b) getModifier()
c) getActionKey()
d) getActionEvent()

14. Which of these events is generated by scroll bar?


a) ActionEvent
b) KeyEvent
c) WindowEvent
d) AdjustmentEvent

15. Which of these events is generated when the window is closed?


a) TextEvent
b) MouseEvent
c) FocusEvent
d) WindowEvent

16. Which of these methods can be used to obtain the coordinates of a mouse?
a) getPoint()
b) getCoordinates()
c) getMouseXY()
d) getMouseCordinates()

17. Which of these are integer constants of TextEvent class?


a) TEXT_CHANGED
b) TEXT_FORMAT_CHANGED
c) TEXT_VALUE_CHANGED
d) TEXT_sIZE_CHANGED

18. Which of these methods is used to obtain the object that generated a WindowEvent?
a) getMethod()
b) getWindow()
c) getWindowEvent()
d) getWindowObject()

19.  MouseEvent is subclass of which of these classes?


a) ComponentEvent
b) ContainerEvent
c) ItemEvent
d) InputEvent

20. Which of these methods is used to get x coordinate of the mouse?


a) getX()
b) getXCoordinate()
c) getCoordinateX()
d) getPointX()

21. Which of these are constants defined in WindowEvent class?


a) WINDOW_ACTIVATED
b) WINDOW_CLOSED
c) WINDOW_DEICONIFIED
d) All of the mentioned

22. Which of these is superclass of WindowEvent class?


a) WindowEvent
b) ComponentEvent
c) ItemEvent
d) InputEvent

23. Which of these packages contains all the event handling interfaces?
a) java.lang
b) java.awt
c) java.awt.event
d) java.event

24. Which of these interfaces handles the event when a component is added to a container?
a) ComponentListener
b) ContainerListener
c) FocusListener
d) InputListener

25. Which of these interfaces define a method actionPerformed()?


a) ComponentListener
b) ContainerListener
c) ActionListener
d) InputListener
 
26. Which of these interfaces define four methods?
a) ComponentListener
b) ContainerListener
c) ActionListener
d) InputListener

27. Which of these interfaces define a method itemStateChanged()?


a) ComponentListener
b) ContainerListener
c) ActionListener
d) ItemListener

28. Which of these methods will respond when you click any button by mouse?
a) mouseClicked()
b) mouseEntered()
c) mousePressed()
d) all of the mentioned

29. Which of these methods will be invoked if a character is entered?


a) keyPressed()
b) keyReleased()
c) keyTyped()
d) keyEntered()

30. Which of these methods is defined in MouseMotionAdapter class?


a) mouseDragged()
b) mousePressed()
c) mouseReleased()
d) mouseClicked()

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


a) Applet
b) ComponentEvent
c) Event
d) InputEvent

32. Classes that provides an empty implementation of all methods in an event listener
Interface
a) Adaptor class
b) SubClass
c) Inner Class
d) None of the above

33.  How do you change the current layout manager for container?
a) use setLayout()
b) once created you cannot change it
c) you set setLayoutManager()
d) use updateLayout()

34. The layout manager object is an implementation of which interface


a) JPanel
b) BorderLayout
c) Container layout manager
d) LayoutManager interface

35.  What method is used to initialize the size of a Frame() object?


a) setsize(int width, int height)
b) setsize(int height, int width)
c) setSize(int width, int height)
d) setSize(int height, int width)

36. What method is used to prevent a user from changing the size of a Frame() object?
a) setResizable(true)
b) setResizable(false)
c) setEditable(true)
d) setEditable(false)

37.  What pattern does the FlowLayout layout manager use to add components to a container
a) Left to right, top to bottom
b) bottom to top, right to left
c) top to bottom, centered in each row
d) setSize(int height, int width

38.  Which of the following are container classes?


a) Frame and Button
b) Button and Label
c) Frame and TextField
d) Frame and Panel

39.  What layout manager do Panels use by default?


a) Gridayout
b) FlowLayout
c) no default layout manager
d) the same layout manager as the Frame

40.  After adding components to the Panels of a GUI, what must be done next?
a) Nothing – the GUI work is done
b) The components must be instantiated
c) The Panels must be added to the Frame
d) The layout manager must now be set
41.  Can GUI components inside of a Panel have a registered listener?
a) No – only those components directly added to a Frame can have listeners
b) No – only Frames can have listeners
c) Yes – it doen’t matter if a component is contained in a Panel
d) Yes – but the Panel must be the listener

42.  Say that a Frame contains three Panels. Could each Panel have a different layout manager
a) No – they must all use the default layout manager
b) No – they must all use the same layout manager
c) Yes – each one must be different
d) Yes – each one use setLayout() with any layout manager

43.  Which of the following commands will set a layout manager that divides the container into
3 rows and 4 columns?
a) setLayout(new GridLayout(3,4));
b) setLayout(new GridLayout(4,3));
c) setLayout(4,3)
d) setLayout(new FlowLayout(4,3));

44.  How many GUI components can go into each cell with GridLayout?
a) None
b) 1
c) Only one Panel per cell
d) As many as you need

45.  Which layout manager places the components in one of the five regions : north, south,
east, west and centre
a) Gridayout
b) FlowLayout
c) BorderLayout
d) CardLayout

46.  Which of the following steps are must for any kind of event handling?
a) Implement the listener method to receive and process event related notifications
b) Adding mouse listener in the init() method.
c) Register the source to receive notifications about specific type of events.
d) Adding mouse motion listener in the main() method

47.  Which of the following packages supports event handling routine, when we use swing
component in GUI programming?
a) javax.swing
b) java.awt
c) java,applet
d) java.util

48.  Which of the following displays components row-by-row in the order in which they were
added to the JFrame
a) Gridayout
b) BorderLayout
c) FlowLayout
d) CardLayout
49.  Using the FlowLayout manager, which is the correct way to add elements to a container?
a) add(component);
b) add(“Center”,component);
c) add(s,y,component);

50.  which of the following class is used to create a pop-up list of items from which a user may
choose?
a) JComboBox
b) JList
c) JLabel
d) JCheckBox

51.  Which of the following method is used to set a frame say f, with size 300 x 200 pixels
a) f.setSize(300,200);
b) f.setSize(200,300);
c) f.paint(300,200);
d) f.setVisible

52.  What is (are) the way(s) to create a Frame using Java Swing?
a) by creating the object of the Frame class (association)
b) by extending the Frame class (inheritance)
c) by importing a package named JFrame
d) by declaring a class with the name JFrame

53.  In Java AWT, TextArea and TextField are the subclass of
a) List
b) Label
c) TextComponent
d) TextBox

54.  The class at top of the AWT hierarchy is


a) Window
b) Container
c) Component
d) Frame

55. Which of the following package provides many methods for graphics programming?
a) java.awt
b) java.Applet
c) java.Graphics
d) java.io

56. Which of the following statement is correct?


a) Swing follows MVC (Model View Controller)
b) AWT components are platform-independent
c) AWT follows MVC (Model View Controller/0
d) Swing components are platform-dependent

57. Give the abbreviation of AWT


a) Applet Windowing Tool Kit
b) Absolute Windowing Tool Kit
c) Abstract Window Tool Kit
d) None of the above
58. Which of the following methods is called only once in the run time of an applet?
a) init()
b) stop()
c) paint()
d) destroy()

59.  Which of the following classes can be used to represent checkbox with a textual label that
can appear in a menu?
a) MenuBar
b) MenuItem
c) CheckBoxMenuItem
d) Menu

60.  When we invoke repaint() for java.awt.Component object, the AWT invokes which of the
following methods
a) draw()
b) show()
c) update()
d) paint()

You might also like