Chapter 10, 11, and 14 Exam part 2

Ace your homework & exams now with Quizwiz!

The depth of recursion is A) the number of times that a method calls itself B) the value that will terminate the recursive calls C) the value returned from the last recursive call D) There is no such term.

A) the number of times that a method calls itself

In a try/catch construct, after the catch statement is executed A) the program resumes at the statement that immediately follows the try/catch construct B) the program returns to the statement following the statement in which the exception occurred C) the program terminates D) the program resumes at the first statement of the try statement

A) the program resumes at the statement that immediately follows the try/catch construct

When using the BorderLayout manager, how many components can each region hold? A) 2 B) 1 C) 5 D) No limit

B) 1

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

B) False

The throw statement informs the compiler that a method throws one or more exception. A) True B) False

B) False

To write data to a binary file you create objects from the following classes: A) BinaryFileWriter and BinaryDataWriter B) FileOutputStream and DataOutputStream C) File and Scanner D) File and PrintWriter

B) FileOutputStream and DataOutputStream

This layout manager arranges components in rows. A) BorderLayout B) FlowLayout C) RegionLayout D) GridLayout

B) FlowLayout

What will be the result of executing the following statement? panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5)); A) The JPanel referenced by panel will have a blue line border that is 5 millimeters thick. B) The JPanel referenced by panel will have a blue line border that is 5 inches thick. C) The JPanel referenced by panel will have a blue line border that is 5 pixels thick. D) The JPanel referenced by panel will have a blue line border that is 5 characters thick.

C) The JPanel referenced by panel will have a blue line border that is 5 pixels thick.

If the IOData.dat file does not exist, what will happen when the following statement is executed? RandomAccessFile randomFile = new RandomAccessFile("IOData.dat", "rw"); A) An IOExcepton will be thrown. B) A FileNotFoundException will be thrown. C) The file IOData.dat will be created. D) This is a critical error, the program will stop execution.

C) The file IOData.dat will be created.

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, panel.add(bGroup); B) use the statement, bGroup.add(panel); C) add each button to panel one at a time, e.g. panel.add(button1); D) use the statement, Panel panel = new Panel(bGroup);

C) add each button to panel one at a time, e.g. panel.add(button1);

The IllegalArgumentException class is extends the RuntimeException class, and is therefore A) never used directly B) a checked exception class C) an unchecked exception class D) None of the above

C) an unchecked exception class

The minimize button, maximize button, and close button on a window are sometimes referred to as A) display buttons B) sizing buttons C) decorations D) operations buttons

C) decorations

Given the following constructor code, which of the statements are true? public Book(String ISBNOfBook, double priceOfBook, int numberOrderedOfBook) { if (ISBNOfBook == "") throw new BlankISBN(); if (priceOfBook < 0) throw new NegativePrice(priceOfBook); if (numberedOrderedOfBook < 0) throw new NegativeNumberOrdered(numberOrderedv); ISBN = ISBNOfBook; price = priceOfBook; numberedOrdered = numberOrderedOfBook; } A) Classes extending the Exception class should be created for each of the custom exceptions that are thrown in the constructor. B) The calling method must handle the exceptions thrown in the constructor, or have its own throws clause specifying them. C) There is an error: a throws clause should be added to the constructor header. D) All of the above

D) All of the above

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

D) Both B and C

Look at the following pseudocode algorithm. algorithm Test14(int x) if (x < 8) return (2 * x) else return (3 * Test14(x - 8) + 8) end Test14 What value is returned for Test14(7)? A) 14 B) 7 C) 0 D) -5

A) 14

Look at the following pseudocode algorithm. algorithm Test14(int x) if (x < 8) return (2 * x) else return (3 * Test14(x - 8) + 8) end Test14 What is the depth of Test14(16)? A) 2 B) 1 C) 0 D) 3

A) 2

Look at the following pseudocode algorithm. algorithm Test14(int x) if (x < 8) return (2 * x) else return (3 * Test14(x - 8) + 8) end Test14 What value is returned for Test14(16)? A) 32 B) 24 C) 16 D) 8

A) 32

All of the exceptions that you will handle are instances of classes that extend this class. A) Exception B) RunTimeException C) Error D) IOException

A) Exception

In GUI terminology, a container that can be displayed as a window is known as a A) frame B) message dialog C) buffer D) Swing package

A) frame

An exception's default error message can be retrieved using this method. A) getMessage() B) getDefaultMessage() C) getErrorMessage() D) getDefaultErrorMessage()

A) getMessage()

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.event.*; B) import java.swing; C) import java.awt.*; D) import java.awt;

A) import java.awt.event.*;

A GUI program automatically stops executing when the end of the main method is reached. A) True B) False

B) False

A(n) ________ is an object that is generated in memory as the result of an error or an unexpected event. A) exception handler B) exception C) error message D) default exception handler

B) exception

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.event.*; D) import java.awt;

B) import java.awt.*;

In the following code, assume that inputFile references a Scanner object that has been successfully used to open a file: double totalIncome = 0.0; while (inputFile.hasNext()) { try { totalIncome += inputFile.nextDouble(); } catch(InputMismatchException e) { System.out.println("Non-numeric data encountered " + "in the file."); inputFile.nextLine(); } finally { totalIncome = 35.5; } } What will be the value of totalIncome after the following values are read from the file? A) 0.0 B) 75.0 C) 35.5 D) 19.5

C) 35.5

Layout manager arranges components in regions named North, South, East, West, and Center. A) FlowLayout B) RegionLayout C) BorderLayout D) GridLayout

C) BorderLayout

Look at the following pseudocode algorithm. Algorithm Test3(int a, int b) if (a < b) return 5 else if ( a == b) return -5; else return (a + Test3(a - 1, b) end Test3 What is the base case for the algorithm? A) a < b B) a == b C) Both A and B D) Neither A nor B

C) Both A and B

Look at the following code: FileInputStream fstream = new FileInputStream("MyInfo.dat"); DataInputStream inputFile = new DataInputStream(fstream); This code can also be written as: A) FileInputStream inputFile = new FileInputStream(new DataInputStream("MyInfo.dat")); B) DataInputStream inputFile = new DataInputStream("InputFile.txt"); C) DataInputStream inputFile = new DataInputStream(new FileInputStream("MyInfo.dat")); D) FileInputStream fstream = new DataInputStream("InputFile.txt");

C) DataInputStream inputFile = new DataInputStream(new FileInputStream("MyInfo.dat"));

When an exception is thrown, A) it may be ignored B) the program terminates even if the exception is handled C) it must be handled by the program or by the default exception handler D) it must always be handled by the method that throws it

C) it must be handled by the program or by the default exception handler

To click the JRadioButton referenced by radio, write the following code. A) Click(radio, true); B) Click(radio); C) radio.doClick(); D) radio.Click();

C) radio.doClick();

Like a loop, a recursive method must have A) a counter B) a return statement C) some way to control the number of times it repeats itself D) a predetermined number of times it will execute before terminating

C) some way to control the number of times it repeats itself

Look at the following pseudocode algorithm. algorithm Test14(int x) if (x < 8) return (2 * x) else return (3 * Test14(x - 8) + 8) end Test14 What is the base case for the algorithm? A) 3 * Test14(x - 8) + 8 B) x >= 8 C) x < 8 D) 2 * x

C) x < 8

If, within one try statement you want to have catch clauses of the following types, in which order should they appear in your program: (1) Exception (2) IllegalArgumentException (3) RuntimeException (4) Throwable A) 3, 1, 2, 4 B) 4, 1, 3, 2 C) 1, 2, 3, 4 D) 2, 3, 1, 4

D) 2, 3, 1, 4

The Towers of Hanoi is A) often used in computer science textbooks B) demonstrates the power of recursion C) a mathematical game D) All of the above

D) All of the above

How many times will the following method call itself, if 10 is passed as the argument? public static void message(int n) { if (n > 0) { System.out.println("Print this line.\n"); message(n + 1); } } A) 9 B) 10 C) 1 D) an infinite number of times

D) an infinite number of times

To solve a program recursively, you need to identify at least one case in which the problem can be solved without recursionthis is known as A) the recursive case B) the terminal case C) the final case D) the base case

D) the base case

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 JAbstractButton class to contain other components and their related code B) to derive a class from the JFrame class to contain other components and their related code C) to derive a class from the JComponent class to contain other components and their related code D) to derive a class from the JPanel class to contain other components and their related code

D) to derive a class from the JPanel class to contain other components and their related code

In a Swing application, you create a frame object from the A) JFrame class B) Jlabel class C) Jpanel class D) AbstractButton class

A) JFrame class

Look at the following method. public static int test2(int x, int y) { if ( x < y) { return -5; } else { return (test2(x - y, y + 5) + 6); } } What is the recursive case for the method? A) x >= y B) x < y C) -5 D) x != y

A) x >= y

Look at the following method. public static int test2(int x, int y) { if ( x < y) { return -5; } else { return (test2(x - y, y + 5) + 6); } } What is returned for test2(10, 20)? A) 1 B) -5 C) 6 D) 10

B) -5

If the following statement is in a class that inherits from JFrame, what is the result? super("My JFrame"); A) The derived class's method super is called and "My JFrame" is passed as an argument to it. B) The JFrame constructor is called and "My JFrame" is passed as an argument to it. C) A class named MyJFrame will be created as a subclass of JFrame. D) This statement is in error; super is a reserved word and cannot be used in this fashion.

B) The JFrame constructor is called and "My JFrame" is passed as an argument to it.

A recursive method is a method that A) uses four-letter words to tell you when you have an error B) calls itself C) has a loop in it D) keeps recurring in your program code

B) calls itself

Programs that operate in a GUI environment must be A) dialog boxes B) event driven C) layout managers D) in color

B) event driven

When writing a string to a binary file or reading a string from a binary file, it is recommended that you use A) the Scanner class methods B) methods that use UTF-8 encoding C) the System.In and System.Out methods D) the FileReader and Writer class methods

B) methods that use UTF-8 encoding

The GridLayout manager limits each cell to only one component. To put two or more components in a cell A) resize the components to fit in the cell B) you can nest panels inside the cells, and add other components to the panels C) resize the cells so they can hold more D) The statement is false, the GridLayout manager does not have this restriction.

B) you can nest panels inside the cells, and add other components to the panels

Why does the following code cause a compiler error? try { number = Integer.parseInt(str); } catch (IllegalArgumentException e) { System.out.println("Bad number format."); } catch (NumberFormatException e) { System.out.println(str + " is not a number."); } A) Because NumberFormatException inherits from IllegalArgumentException. The code should handle NumberFormatException before IllegalArgumentException. B) Because the Integer.parseInt method does not throw a NumberFormatException. C) Because you can have only one catch clause in a try statement. D) Because the Integer.parseInt method does not throw an IllegalArgumentException.

A) Because NumberFormatException inherits from IllegalArgumentException. The code should handle

Any problem that can be solved recursively can also be solved iteratively. A) True B) False

A) True

Indirect recursion occurs when a method calls another method that in turn calls the first method. A) True B) False

A) True

It is possible to write the main method directly into a GUI class. A) True B) False

A) True

The call stack is an internal list of all the methods that are currently executing. A) True B) False

A) True

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

A) True

All exceptions are instances of classes that extend this class. A) RunTimeException B) Throwable C) Exception D) Error

B) Throwable

To end an application, pass this as the argument to the JFrame class's setDefaultCloseOperation() method. A) JFrame.EXIT_ON_CLOSE B) JFrame.CLOSE_NOT_HIDE C) JFrame.END_ON_CLOSE D) END_ON_CLOSE

A) JFrame.EXIT_ON_CLOSE

Which of the following statements is not true? A) Radio buttons and Check boxes both implement the ActionListener interface. B) Radio buttons are often grouped together and are mutually exclusive; Check boxes are not. C) Radio buttons are round and Check boxes are square. D) They are all true.

A) Radio buttons and Check boxes both implement the ActionListener interface.

________ is a library of classes that do not replace ________, but provide an improved alternative for creating GUI applications. A) Swing; AWT B) JFC; AWT C) AWT: Swing D) JFC; Swing

A) Swing; AWT

A class must implement the Serializable interface in order for objects of the class to be serialized. A) True B) False

A) 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. A) True B) False

A) True

Although check boxes may be grouped in a ButtonGroup like radio buttons are, they are not normally grouped as such. A) True B) False

A) True

When deserializing an object using the readObject method, you must cast the return value to the desired class type. A) True B) False

A) True

When the code in a try block may throw more than one type of exception, you need to write a catch clause for each type of exception that could potentially be thrown. A) True B) False

A) True

The following catch statement catch (Exception e) {...} A) can handle all exceptions that are instances of the Exception class or a subclass of Exception B) can handle all exceptions that are instances of the Exception class, but not a subclass of Exception C) is an error since no objects are instantiated in the Exception class D) can handle all throwable objects by using polymorphic reference as a parameter in the catch clause

A) can handle all exceptions that are instances of the Exception class or a subclass of Exception

The actions that the JVM must performed any time a method is called is called A) overhead B) housekeeping C) method calls D) stack frame

A) overhead

If panel references a JPanel object, which of the following statements adds the GridLayout to it? A) panel.setLayout(new GridLayout(2,3)); B) panel.attachLayout(GridLayout(2,3)); C) panel.addLayout(new GridLayout(2,3)); D) panel.GridLayout(2,3);

A) panel.setLayout(new GridLayout(2,3));

A modal dialog box A) suspends execution of any other statements until the dialog box is closed B) does not put a symbol in the message box C) determines the mode your program runs in D) displays for a short period of time and then disappears from the screen

A) suspends execution of any other statements until the dialog box is closed

Look at the following pseudocode algorithm. algorithm Test14(int x) if (x < 8) return (2 * x) else return (3 * Test14(x - 8) + 8) end Test14 What is the depth of Test14(7)? A) 1 B) 0 C) 6 D) 7

B) 0

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

B) 2

A problem can be solved recursively if it can be broken down into successive smaller problems that are unique within the overall problem. A) True B) False

B) False

What will be displayed when the following statement is executed? JOptionPane.showMessageDialog(null, "Incorrect data type", "Warning", JOptionPane.WARNING_MESSAGE); A) an error message box with a triangle symbol, with a title of "Incorrect data type", and a message of "Warning" B) a dialog message box with a triangle symbol, with a title of "Warning", and a message of "Incorrect data type" 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"

B) a dialog message box with a triangle symbol, with a title of "Warning", and a message of "Incorrect data type"

If the code in a method can potentially throw a checked exception, then that method must A) have a throws clause listed in the method header B) handle the exception C) Neither A nor B D) Either A or B

D) Either A or B

To read data from a binary file you create objects from the following classes: A) BinaryFileReader and BinaryDataReader B) File and PrintWriter C) File and Scanner D) FileInputStream and DataInputStream

D) FileInputStream and DataInputStream

What will be the result of the following statements? FileInputStream fstream = new FileInputStream("DataIn.dat"); DataInputStream inFile = new DataInputStream(fstream); A) The inFile variable will reference an object that is able to write binary data to the Input.dat file. B) The inFile variable will reference an object that is able to read random access data from the Input.dat file. C) The inFile variable will reference an object that is able to read text data from the Input.dat file. D) The inFile variable will reference an object that is able to read binary data from the Input.dat file.

D) The inFile variable will reference an object that is able to read binary data from the Input.dat file.


Related study sets

Prioritizing client care practice questions

View Set

Prep U--Ch. 47: Mgmt of Patients With Intestinal and Rectal Disorders

View Set

Unit 2: Buying and Selling in a Flood Zone

View Set

2.5 The Structure and Function of Arteries, Capillaries and Veins

View Set

Питання для підготовки до модульної контрольної роботи з ЦНС (теми 4-7)

View Set

Quiz 10 Unemployment- Macroeconomics

View Set