Final Review
1
How many times will the following do-while loop be executed? 0 1 4 5
frame
In GUI terminology, a container that can be displayed as a window is known as a message dialog buffer Swing package frame
-
In UML diagrams, this symbol indicates that a member is private. * # - +
Class; objects
In the cookie cutter metaphor: Think of the ________ as a cookie cutter and ________ as the cookies. Object; classes Class; objects Class; fields Field; methods
False
In the following code the setPreferredSize method sets the size of the text, "Have a good day". True False
It will call the constructor of ClassA that receives an integer as an argument
In the following code, what will the call to super do? This cannot be determined form the above code It will call the method super and pass the value 40 to it as an argument It will call the constructor of ClassA that receives an integer as an argument The method super will have to be defined before we can say what will happen
False
In the for loop, the control variable cannot be initialized to a constant value and tested against a constant value. True False
True
It is not possible for a superclass to call a subclass's method. True False
1
Look at the following declaration. What is the ordinal value of the MAPLE enum constant? 0 1 2 Tree.MAPLE
Break a problem down into small manageable pieces
Methods are commonly used to speed up the compilation of a program Break a problem down into small manageable pieces Emphasize certain parts of the logic Document the program
Event driven
Programs that operate in a GUI environment must be Event driven In color Dialog boxes Layout managers
False
StringBuilder objects are immutable. You Answered True False
java.awt package
The Dimension class is part of the javax.swing.event package java.awt.menu package javax.swing package java.awt package
A String argument, which is the name of the image file
The ImageIcon class constructor accepts An integer that references the image A String argument, which is the name of the image file A String argument, which is the name of the image It does not accept any arguments
BMP
The ImageIcon class supports all the following file types, except BMP JPEG GIF PNG
True
The System.exit method will end the application. True False
False
The contents of a variable cannot be changed while the program is running. True False
True
The do-while loop must be terminated with a semicolon. True False
true or false
The expression in an if statement must evaluate to 0 or 1 +1 or -1 true or false t or f
Sets the textList component to single interval selection mode
The following statement Sets the textList component to single selection mode Sets the textList component to ListSelectModel Sets the textList component to single interval selection mode Sets the value of textList to SINGLE_INTERVAL_SELECTION
False
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()); True False
False
The this key word is the name of a reference variable that is available to all static methods. True False
An accompanying integer value that holds the number of items stored in the array
What do you normally use with a partially-filled array? A class that does nothing but manage the array An accompanying parallel array An accompanying integer value that holds the number of items stored in the array An accumulator
All of these
What does the following statement do? Double number = new Double(8.8); You Answered It creates a Double object It initializes that object to 8.8 It assigns the object's address to the number variable All of these
0.01
What would be the value of discountRate after the following statements are executed? 0.05 0.03 0.01 0
To extend a class from the JPanel class to contain other components and their related code
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 To extend a class from the JAbstractButton class to contain other components and their related code To extend a class from the JComponent class to contain other components and their related code To extend a class from the JPanel class to contain other components and their related code To extend a class from the JFrame class to contain other components and their related code
All of these
When an array is passed to a method A reference to the array is passed It is passed just as an object The method has direct access to the original array All of these
True
When an object reference is passed to a method, True False
True
You can create a label with an image, or with both an image and text. True False
add
You can use this ArrayList class method to replace an item at a specific location in an ArrayList. insert add store set
False
A GUI program automatically stops executing when the end of the main method is reached. True False
Both The things a class is responsible for doing and The things a class is responsible for knowing
A class's responsibilities include The things a class is responsible for doing The things a class is responsible for knowing Both The things a class is responsible for doing and The things a class is responsible for knowing Neither The things a class is responsible for doing nor The things a class is responsible for knowing
True
A class's static methods do not operate on the fields that belong to any instance of the class. True False
True
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. True False
True
A file must always be opened before using it and closed when the program is finished using it. True False
0 and 1
A flag may have the values 0 and 1 +1 and -1 true or false Of any character
True
A local variable's scope always ends at the closing brace of the block of code in which it is declared. True False
Combo box menu item
A menu system may consist of each of the following, except Check box menu item Combo box menu item Radio button menu item Menu item
True
An enumerated data type is actually a special type of class. True False
False
An important style rule you should follow when writing if statements is to line up the conditionally executed statement with the if statement. True False
Both Handle the potential exception and Have the same throws clause
Any method that calls a method with a throws clause in its header must Handle the potential exception Have the same throws clause Both Handle the potential exception and Have the same throws clause Do nothing, the called program will take care of the throws clause
if (checkBox.isSelected()) {/*code to execute, if selected*/}
Assume that the variable checkbox references a JCheckBox object. To determine whether the check box has been selected, use the following code. if (isSelected(checkBox)) {/*code to execute, if selected*/} if (checkBox.isSelected()) {/*code to execute, if selected*/} if (checkBox) {/*code to execute, if selected*/} if (checkBox.doClick()) {/*code to execute, if selected*/}
The account object's toString method will be implicitly called.
Assume the class BankAccount has been created, and the following statement correctly creates an instance of the class: BankAccount account = new BankAccount(5000.0); What is true about the following statement? System.out.println(account); The method will display unreadable binary data on the screen. A compiler error will occur. The account object's toString method will be implicitly called. A runtime error will occur.
int number = inputFile.nextInt();
Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file? int number = inputFile.nextInt(); int number = inputFile.next(); int number = inputFile.readInt(); int number = inputFile.integer();
False
By default the scroll bars are always displayed. True False
True
Check boxes may be grouped in a ButtonGroup like radio buttons are. True False
True
Every class is either directly or indirectly derived from the Object class. True False
an ActionEvent object as an argument
When an item in the combo box is selected, the combo box executes its action event listener's actionPerformed method, passing an ItemEvent object as an argument a SelectionEvent object as an argument an ActionEvent object as an argument the combo box as an argument
JFrame. HIDE_ON_CLOSE
When this is the argument passed to the JFrame class's setDefaultCloseOperation() method, the application is hidden, but not closed. HIDE_ON_CLOSE JFrame. HIDE_ON_CLOSE JFrame.EXIT_ON_CLOSE JFrame.HIDE_NOT_CLOSE
1
When using the BorderLayout manager, how many components can each region hold? 1 2 5 No limit
True
When you open a file with the PrintWriter class, the class can potentially throw an IOException. True False
True
When you write a change listener class method for a slider, it must implement the ChangeListener interface which is in the javax.swing.event package. True False
clearButton.setMnemonic(KeyEvent.VK_C);
Which of the following assigns ALT+C as a mnemonic key for the JButton object, clearButton? clearButton.addMnemonic(KeyEvent.VK_C); clearButton.setMnemonic(KeyEvent.C); clearButton.setMnemonic(KeyEvent.VK_C); clearButton.assignMnemonic(KeyEvent.VK_C);
Class, Responsibilities, Collaborations
CRC stands for Code, Reuse, Constancy Class, Responsibilities, Collaborations Class, Redundancy, Collections Class, Recyclability, Collaborations
Methods
Class objects normally have ________ that perform useful operations on their data, but primitive variables do not. Fields Instances Methods Relationships
9
For the following code, how many times would the while loop execute? 1 5 7 9
A reference to the String "ghi"
For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"}; "ghi" "def" A reference to the String "ghi" A reference to the String "def"
The process of breaking a problem down into smaller pieces
Functional decomposition is The backbone of the scientific method The process of decomposing functions The process of breaking a problem down into smaller pieces The process of dead plants decomposing and turning back into soil
r = 2.9X106;
Given the declaration double r;, which of the following statements is invalid? r = 326.75; r = 9.4632e15; r = 9.4632E15; r = 2.9X106;
522.00
Given the following code, what will be the value of finalAmount when it is displayed? 528.00 580.00 522.00 There is no value because the object order has not been created.
diskOut.println("Calvin");
Given the following statement, which statement will write "Calvin" to the file DiskFile.txt? PrintWriter diskOut = new PrintWriter("DiskFile.txt"); System.out.println(diskOut, "Calvin"); DiskFile.println("Calvin"); PrintWriter.println("Calvin"); diskOut.println("Calvin");
The array numbers has 6 rows and 9 columns
Given the following two-dimensional array declaration, which statement is true? int [][] numbers = new int [6] [9]; The array numbers has 6 columns and 9 rows The array numbers has 6 rows and 9 columns The array numbers has 15 rows The array numbers has 54 rows
Public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA
If ClassA is derived from ClassB, then Public and private members of ClassB are public and private, respectively, in ClassA Public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA Neither public or private members in ClassB can be directly accessed in ClassA Private members in ClassB are changed to protected members in ClassA
A chain of inheritance
If ClassC is derived from ClassB, which is derived from ClassA, this would be an example of Multiple inheritance A chain of inheritance A family tree Packaging
False
If a method in a subclass has the same signature as a method in the superclass, the subclass method overloads the superclass method. You Answered True False
Describes the return value
In a @return tag statement the description Cannot be longer than one line Describes the return value Must be longer than one line Describes the parameter values
JFrame class
In a Swing application, you create a frame object from the Jlabel class JFrame class Jpanel class AbstractButton class
Public access
In an interface all methods have Private access Protected access Public access Packaged access
Java Foundation Classes
JFC stands for You Answered Java Fundamental Classes Java Foundation Classes Java Fundamental Core Java Frame Class
BorderLayout
Layout manager arranges components in regions named North, South, East, West, and Center. GridLayout BorderLayout FlowLayout RegionLayout
They may initialized with any of these
Local variables can be initialized with Constants Parameter values The results of an arithmetic operation They may initialized with any of these
None of these
Look at the following code. The method in line ________ will override the method in line ________. 10, 4 11, 5 Both 10, 4 and 11, 5 None of these
10, 4
Look at the following code. The method in line ________ will override the method in line ________. 4, 10 5, 11 10, 4 11, 5
Tree.PINE
Look at the following declaration. What is the fully-qualified name of the PINE enum constant? PINE enum.PINE Tree.PINE Tree.MAPLE
True
No statement outside the method in which a parameter variable is declared can access the parameter by its name. True False
import
Quite often you have to use this statement to make a group of classes available to a program. import use link assume
You can nest panels inside the cells, and add other components to the panels
The GridLayout manager limits each cell to only one component. To put two or more components in a cell Resize the cells so they can hold more You can nest panels inside the cells, and add other components to the panels The statement is false, the GridLayout manager does not have this restriction Resize the components to fit in the cell
javax.swing package
The JComboBox class is in the javax.swing package java.awt package java awt.event package java.swing.event package
garbage collection
The JVM periodically performs this process to remove unreferenced objects from memory. memory sweeping garbage collection memory shuffling system restore
True
The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line. True False
Performs initialization or setup operations
A constructor is a method that Returns an object of the class Never receives any arguments With the name ClassName.constructor Performs initialization or setup operations
False
A method that gets a value from a class's field but does not change it is known as a mutator method. True False
Procedure
This is a set of programming language statements that, together, perform a specific task. Object Compiler Procedure Pseudocode
Running total
This is a sum of numbers that accumulates with each iteration of a loop. Running total Final total Grand total Galloping total
Method body
This part of a method is a collection of statements that are performed when the method is executed. Method header Return type Method body Method modifier
Void
This type of method performs a task and then terminates. Value-returning Void Local Simple
The setToolTipText method
To add a tool tip to a component use The setToolTipText method The addToolTipText method The toolTipText method The appendToolTipText method
A two-dimensional array when the rows are of different lengths
A ragged array is A two-dimensional array for which the number of rows is unknown A one-dimensional array for which the number of elements is unknown A two-dimensional array when the rows are of different lengths There is no such thing as a ragged array
Any valid data type
A value-returning method must specify this as its return type in the method header. An integer A double A boolean Any valid data type
JScrollPane scrollPane = new JScrollPane(addressList);
To add the JList object addressList to a scroll pane referenced by scrollPane, use the following JScrollPane scrollPane = new JScrollPane(addressList); scrollPane.add(addressList); addressList.add(scrollPane); addressList.addScrollPane(scrollPane);
double x = Double.parseDouble(str);
To convert the string, str = "285.74" to a double and store it in the variable x, use the following statement double x = str; double x = Double.parseDouble(str); double x = Double.Double(str); double x = str,Double.parseDouble;
import java.awt.event.*;
To use the ActionListener interface, as well as other event listener interfaces, you must have the following import statement in your code: import java.swing; import java.awt; import java.awt.*; import java.awt.event.*;
-1
What will be the value of loc after the following code is executed? int loc; String str = "The cow jumped over the moon."; loc = str.lastIndexOf("ov", 14); 15 You Answered 16 0 -1
We have lived in Tampa, Trenton, and Atlanta.
What will be the value of str after the following statements are executed? We have lived in Tampa, Trenton, and Atlanta. We have lived in Chicago, Tampa, and Atlanta. We have lived in Chicago, Trenton, and Tampa. We have lived in Chicago, Tampaon, and Atlanta.
ans = 35, x = 15, y = 40
What will be the values of ans, x, and y after the following statements are executed? ans = 0, x = 15, y = 25 ans = 25, x = -10, y = 25 ans = 35, x = 15, y = 40 ans = 25, x = 15, y = 40
x = 33, y = 9
What will be the values of x and y as a result of the following code? int x = 25, y = 8; x += y++; x = 25, y = 8 x = 33, y = 8 x = 33, y = 9 x = 34, y = 9
A button with the text "It is a beautiful morning." to the right of the SunnyFace image
What will display when the following code is executed: A button with the text "It is a beautiful morning." to the left of the SunnyFace image A button with the text "It is a beautiful morning." to the right of the SunnyFace image A button with the text "It is a beautiful morning." below the SunnyFace image A button with the text "It is a beautiful morning." above the SunnyFace image
A label with the text "It is a beautiful day." to the right of the SunnyFace image
What will display when the following code is executed: JLabel label = new JLabel ("It is a beautiful morning."); labed.setIcon(SunnyFace.gif); A label with the text "It is a beautiful day." to the left of the SunnyFace image A label with the text "It is a beautiful day." to the right of the SunnyFace image A label with the text "It is a beautiful day." below the SunnyFace image A label with the text "It is a beautiful day." above the SunnyFace image
The JFrame that encloses the window will resize itself to accommodate the SunnyFace image
What will display when the following code is executed? The JFrame that encloses the window will resize itself to accommodate the SunnyFace image imagePanel will resize itself to accommodate the SunnyFace image The SunnyFace image will resize itself to fit on imageLabel The SunnyFace image will resize itself to fit on imagePanel
A Color Chooser will be displayed in the center of the screen with "Select color" in its Title Bar and blue pre-selected
What will happen when the following code is executed? A Color Chooser will be displayed in the upper, left-hand corner of the screen with "Select color" in its Title Bar and blue pre-selected A Color Chooser will be displayed in the center of the screen with "Select color" in its Title Bar and blue pre-selected A Color Chooser will be displayed in the center of the screen with "Select color" as the OK button's text and blue pre-selected A Color Chooser will be displayed in the lower, right-hand corner of the screen with "Select color" in its Title Bar and blue pre-selected
str would equal "Little Jack Horner sat on the corner"
What would be the results of executing the following code? StringBuilder str = new StringBuilder("Little Jack Horner "); str.append("sat on the "); str.append("corner"); The program would crash str would equal "Little Jack Horner" str would equal "Little Jac Horner sat on the" str would equal "Little Jack Horner sat on the corner"
List selection event
When an item in a Jlist object is selected it generates a(n) You Answered Action listener event Action performed event List selection listener event List selection event
public static void passArray(int [ ][ ] intArray)
Which of the following is a correct method header for receiving a two-dimensional array as an argument? public static void passArray(int[1,2] intArray) public static void passArray(int [ ][ ] intArray) public static void passArray(int[1],[2] intArray) public static void passArray(int[ ], int[ ]intArray)
JButton
Which of the following is not a class used in constructing a menu system? JMenuItem JCheckBoxMenuItem JButton JRadioButtonMenuItem
JComboBoxMenuItem
Which of the following is not a class used in constructing a menu system? JMenuItem JCheckBoxMenuItem JComboBoxMenuItem JRadioButtonMenuItem
String
Which of the following is not a primitive data type? short long float String
All these are parts of the programming process
Which of the following is not part of the programming process? Design/model Testing Debugging/correcting errors All these are parts of the programming process
Scanner keyboard = new Scanner(System.in);
Which of the following statements correctly creates a Scanner object for keyboard input? Scanner kbd = new Scanner(System.keyboard); Scanner keyboard(System.in); Scanner keyboard = new Scanner(System.in); Keyboard scanner = new Keyboard(System.in);
public class DerivedClass extends JFrame { }
Which of the following statements creates a class that derived from the JFrame class? JFrame DerivedClass = new JFrame(); class JFrame DerivedClass; JFrame(DerivedClass); public class DerivedClass extends JFrame { }
Radio buttons and Check boxes both implement the ActionListener interface
Which of the following statements is not true? Radio buttons are round and Check boxes are square Radio buttons are often grouped together and are mutually exclusive; Check boxes are not Radio buttons and Check boxes both implement the ActionListener interface They are all true
System.out.println(Double.MAX_VALUE);
Which of the following statements will print the maximum value a double variable may have? System.out.println(MAX_VALUE); System.out.println(double.MAX_VALUE); System.out.println(Double.MAX_VALUE); System.out.println(Double.MAXIMUM_VALUE);
All of these
Which of the statements are true about the following code? Declares array1 to be a reference to an array of long values Creates an instance of an array of 10 long values Will allow valid subscripts in the range of 0-9 All of these
The itemStateChanged method cannot be coded here
Why doesn't the following code compile correctly? ColorCheckBoxWindow is not implementing the correct listener The button cannot be added to the content pane The itemStateChanged method cannot be coded here greenCheckBox should not be a private member
False
You can declare an enumerated data type inside of a method. True False
The File class's exists method
You can use this method to determine whether a file exists. The Scanner class's exists method The File class's exists method The File class's canOpen method The PrintWriter class's fileExists method
False
You cannot assign a value to a wrapper class object. True False
False
You must call a method to get the value of a wrapper class object. You Answered True False
Swing, AWT
________ is a library of classes that do not replace ________, but provide an improved alternative for creating GUI applications. AWT, Swing Swing, AWT JFC, AWT JFC, Swing
Are final and static
All fields declared in an interface Are final and static Have protected access Must be initialized in the class implementing the interface Have private access
Java will automatically call the superclass's default constructor just before the code in the subclass's constructor executes
If a subclass constructor does not explicitly call a superclass constructor, It must include the code necessary to initialize the superclass fields The superclass fields will be set to the default values for their data types Java will automatically call the superclass's default constructor immediately after the code in the subclass's constructor executes Java will automatically call the superclass's default constructor just before the code in the subclass's constructor executes
The value that appears in the text field, even if it is not in the combo box's list
If a user enters a value in the text box of an editable combo box and the value is not in the list, what will the method getSelected Item return? The value that the user replaced The index of the item the user entered The value that appears in the text field, even if it is not in the combo box's list Nothing, since the item is not in the list
False
If a[] and b[] are two integer arrays, the expression a == b compares the array contents. True False
numbers[r].length
If numbers is a two-dimensional array, which of the following would give the length of row r? numbers.length numbers.length[r] numbers[r].length[r] numbers[r].length
f
If str is declared as String str = "ABCDEFGHI"; what will be returned from Character.toLowerCase(str.charAt(5))? e E f F
Because the return type of the method is an Object
If the combo box addressBox contains a list of strings, why is the returned value of getSelectedItem method in the following code cast to String? String selectedAddress; selectedAddress = (String)addressBox.getSelectedItem(); This is not necessary Because the syntax of the method requires it It makes the program more readable Because the return type of the method is an Object
Package
If you do not provide an access specifier for a class member, the class member is given this access by default. Private Public Protected Package
numAccounts = SavingsAccount.numberOfAccounts;
If you have defined a class named SavingsAccount with a public static data member named numberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will assign numberOfAccounts to numAccounts? numAccounts = account20.numberOfAccounts; numAccounts = numberOfAccounts; numAccounts = SavingsAccount.numberOfAccounts; None of these, you cannot reference a static data member.
120
What will be the value of ans after the following code has been executed? 10 120 100 No value, there is a syntax error
It specifies that only String objects may be stored in the ArrayList object
The following statement creates an ArrayList object. What is the purpose of the <String> notation? ArrayList<String> arr = new ArrayList<String>(); It specifies that only String objects may be stored in the ArrayList object It specifies that the get method will return only String objects It specifies that String objects may not be stored in the ArrayList object It specifies that everything stored in the ArrayList object will be converted to a String
The data type of the return value
The header of a value-returning method must specify this. The method's local variable name The name of the variable in the calling program that will receive the returned value The data type of the return value All of these
True
The key word this is the name of a reference variable that an object can use to refer to itself. True False
variable
The primitive data types only allow a(n) ________ to hold a single value. variable object class literal
False
The purpose of the sequential search algorithm is to rearrange the elements of an array so they appear in order from the lowest value to the highest value. True False
To determine if the program solves the original problem
The purpose of validating the results of the program is To create a model of the program To correct syntax errors To correct runtime errors To determine if the program solves the original problem
The instance methods of the same class
The scope of a private instance field is The instance methods of the same class Inside the class, but not inside any method Inside the parentheses of a method header The method in which they are defined
add each button to panel one at a time, e.g. panel.add(button1);
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 use the statement, panel.add(bGroup); use the statement, bGroup.add(panel); use the statement, Panel panel = new Panel(bGroup); add each button to panel one at a time, e.g. panel.add(button1);
Heavyweight
These types of components are coupled with their underlying peers. You Answered Lightweight Featherweight Middleweight Heavyweight
Frame
This is a basic window that has a border around it, a title bar, and a set of buttons for minimizing, maximizing, and closing the window. Pane Container Frame Dialog box
Flag
This is a boolean variable that signals when some condition exists in the program Sentinel Block Flag Case
Pseudocode
This is a cross between human language and a programming language. Pseudocode Java The Java Virtual Machine The compiler
Package
This is a group of related classes. Archive Package Collection Attachment
It creates a text area with 25 rows and 15 columns that will initially display the text stored in the String object message
What does the following statement do? JTextArea textField = JTextArea(message, 25, 15); It creates a text area with 25 columns and 15 rows that will initially display the text stored in the String object message It creates a text area with 25 columns and 15 rows that will initially display the text stored in the text area textField It creates a text area with 25 rows and 15 columns that will initially display the text stored in the String object message It creates a text area with 25 rows and 15 columns that will initially display the text "message"
Creates an AddButtonListener object and registers the AddButtonListener object with the addButton
What does the following statement do? addButton.addActionListener(new AddButtonListener()); Creates an AddButtonListener object Registers the addButton object as an ActionListener with the AddButtonListener object Creates an AddButtonListener object and registers the AddButtonListener object with the addButton Nothing, the statement is invalid
7
What is the result of the following statement? 25/4 + 4 * 10 % 3 19 5.25 3 7
Nothing is wrong with the code
What is wrong with the following code? Nothing is wrong with the code The method super is not defined The call to the method super must be the first statement in the constructor No values may be passed to super
45,678.26
What will be printed when the following code is executed? 45678.259 0,045,678.26 45,678.26 45,678.3
x = 40
What will be printed when the following code is executed? x = 30 x = 40 x = 20 x is unknown when the last statement is executed
The foreground color will be set to blue
What will be the results of executing the following code, if the user simply clicks OK? The foreground color will remain unchanged The foreground color will be set to white The foreground color will be set to black The foreground color will be set to blue
123, 456, 7890, and -
What will be the tokens in the following statement? 123, 456, and 7890 - 123, 456, 7890, and - None of these