Java Exam Study Guide
Java Exam Study Guide
1%
1. ________ is a library of classes that do not replace ________, but provide an improved alternative for creating GUI applications. A) Swing; AWT B) JFC; Swing C) JFC; AWT D) AWT: Swing
2. Programs that operate in a GUI environment must be A) event driven B) dialog boxes C) layout managers D) in color
JOptionPane.showMessageDialog(null, "Incorrect data type", "Warning", JOptionPane.WARNING_MESSAGE); A) a dialog message box with a triangle symbol, with a title of "Warning", and a message of "Incorrect data type" B) an error message box with a triangle symbol, with a title of "Incorrect data type", and a message of "Warning" C) a dialog message box with no symbol, with a title of "Incorrect data type", and a message of "Warning" D) a warning message box with a stop sign symbol, with a title of "Incorrect data type", and message of "Warning"
4. A modal dialog box A) does not put a symbol in the message box B) displays for a short period of time and then disappears from the screen C) determines the mode your program runs in D) suspends execution of any other statements until the dialog box is closed
5. In GUI terminology, a container that can be displayed as a window is known as a A) buffer B) frame C) message dialog D) Swing package
6. To end an application, pass this as the argument to the JFrame class's setDefaultCloseOperation() method. A) END_ON_CLOSE B) JFrame.END_ON_CLOSE C) JFrame.CLOSE_NOT_HIDE D) JFrame.EXIT_ON_CLOSE
7. It is possible to write the main method directly into a GUI class. A) True B) False
8. The minimize button, maximize button, and close button on a window are sometimes referred to as A) operations buttons B) sizing buttons C) display buttons D) decorations
9. If the following statement is in a class that inherits from JFrame, what is the result?
super("My JFrame");
A) The JFrame constructor is called and "My JFrame" is passed as an argument to it. B) A class named MyJFrame will be created as a subclass of JFrame. C) The derived class's method super is called and "My JFrame" is passed as an argument to it. D) This statement is in error; super is a reserved word and cannot be used in this fashion.
10. To use the ActionListener interface, as well as other event listener interfaces, you must have the following import statement in your code: A) import java.awt.*; B) import java.swing; C) import java.awt.event.*; D) import java.awt;
11. When you write an action listener class for a JButton component, it must A) a method named buttonClicked B) implement the ActionListener interface C) have a method named actionPerformed which must take an argument of the ActionEvent type D) Both B and C
Correct Answer(s): D
12. A common technique for writing an event listener class is to write it as a private inner class inside the class that creates the GUI. A) True B) False
13. In a Swing application, you create a frame object from the A) Jlabel class B) AbstractButton class C) JFrame class D) Jpanel class
14. To use the Color class, which is used to set the foreground and background of various objects, use the following import statement A) import java.swing; B) import java.awt.*; C) import java.awt; D) import java.awt.event.*;
15. This layout manager arranges components in rows. A) RegionLayout B) BorderLayout C) GridLayout D) FlowLayout
Correct Answer(s): D
16. Layout manager arranges components in regions named North, South, East, West, and Center. A) RegionLayout B) BorderLayout C) GridLayout D) FlowLayout
17. If panel references a JPanel object, which of the following statements adds the GridLayout to it? A) panel.GridLayout(2,3); B) panel.setLayout(new GridLayout(2,3)); C) panel.attachLayout(GridLayout(2,3)); D) panel.addLayout(new GridLayout(2,3));
18. The following statement adds the FlowLayout manager to the container, centers the components, and separates the components with a gap of 10 pixels.
setLayout(new FlowLayout());
A) True B) False
19. When using the BorderLayout manager, how many components can each region hold? A) 1 B) 5 C) 2
D) No limit
20. The GridLayout manager limits each cell to only one component. To put two or more components in a cell A) resize the cells so they can hold more B) The statement is false, the GridLayout manager does not have this restriction. C) you can nest panels inside the cells, and add other components to the panels D) resize the components to fit in the cell
21. Which of the following statements is not true? A) Radio buttons are round and Check boxes are square. B) Radio buttons and Check boxes both implement the ActionListener interface.
C) Radio buttons are often grouped together and are mutually exclusive; Check boxes are not. D) They are all true.
22. How many radio buttons can be selected at the same time as the result of the following code?
hours = new JRadioButton("Hours"); minutes = new JRadioButton("Minutes"); seconds = new JRadioButton("Seconds"); days = new JRadioButton("Days"); months = new JRadioButton("Months"); years = new JRadioButton("Years"); timeOfDayButtonGroup = new ButtonGroup(); dateButtonGroup = new ButtonGroup(); timeOfDayButtonGroup.add(hours); timeOfDayButtonGroup.add(minutes); timeOfDayButtonGroup.add(seconds); dateButtonGroup.add(days); dateButtonGroup.add(months);
dateButtonGroup.add(years);
A) 1 B) 2 C) 3 D) 4
23. Although check boxes may be grouped in a ButtonGroup like radio buttons are, they are not normally grouped as such. A) True B) False
24.
To click the JRadioButton referenced by radio, write the following code. A) radio.doClick(); B) Click(radio); C) radio.Click(); D) Click(radio, true);
25. The variable panel references a JPanel object. The variable bGroup references a ButtonGroup object, which contains several button components. If you want to add the buttons to the panel A) use the statement, bGroup.add(panel); B) use the statement, panel.add(bGroup); C) add each button to panel one at a time, e.g. panel.add(button1); D) use the statement, Panel panel = new Panel(bGroup);
panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
A) The JPanel referenced by panel will have a blue line border that is 5 characters thick. B) The JPanel referenced by panel will have a blue line border that is 5 pixels thick. C) The JPanel referenced by panel will have a blue line border that is 5 inches thick. D) The JPanel referenced by panel will have a blue line border that is 5 millimeters thick.
27. When an application uses many components, rather than deriving just one class from the JFrame class, it is often better to encapsulate smaller groups of related components and their event listeners into their own class. A commonly used technique to do this is A) to derive a class from the JPanel class to contain other components and their related code B) to derive a class from the JAbstractButton class to contain other components and their related code C) to derive a class from the JFrame class to contain other components and their related code D) to derive a class from the JComponent class to contain other components and their related code
Correct Answer(s): A
28. When a splash screen is displayed, the application does not load and execute until the user clicks the splash screen image with the mouse. A) True B) False
29. A GUI program automatically stops executing when the end of the main method is reached. A) True B) False