Final Prep

¡Supera tus tareas y exámenes ahora con Quizwiz!

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

What will be printed after the following code is executed? String str = "abc456"; int m = 0; while ( m < 6 ) { if (Character.isLetter(str.charAt(m))) System.out.print( Character.toUpperCase(str.charAt (m))); m++; } A) ABC B) abc456 C) 456 D) ABC456

A) ABC

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

Given the following code which of the following is true? public class ClassB implements ClassA{} A) ClassB must override each method in ClassA B) ClassA must override each method in ClassB C) ClassA is derived from ClassB D) ClassB is derived from ClassA

A) ClassB must override each method in ClassA

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 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

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

Which of the following statements will print the maximum value a double variable may have? A) System.out.println(Double.MAX_VALUE); B) System.out.println(Double.MAXIMUM_VALUE); C) System.out.println(MAX_VALUE); D) System.out.println (double.MAX_VALUE);

A) System.out.println(Double.MAX_VALUE);

What would be the results of the following code? int[ ] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if( x[2] > x[5]) a = 5; else a = 8; a) a = 5 b) a = 10 c) a = 8 d) This is a compilation error, you cannot compare array elements.

A) a = 5

A ragged array is A) a two-dimensional array when the rows are of different lengths B) a one-dimensional array for which the number of elements is unknown C) a two-dimensional array for which the number of rows is unknown D) There is no such thing as a ragged array.

A) a two-dimensional array when the rows are of different lengths

A ragged array is A) a two-dimensional arrray when the rows are of different lengths B) one-dimensional array for which the number of elements is unknown C) a two-dimensional array for which the number of rows is unknown D) There is no such thing as a ragged array

A) a two-dimensional arrray when the rows are of different lengths

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

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.*;

The ArrayList class is in this package. A) java.arraylist B) java.array C) java.lang D) java.util

A) java.arraylist

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

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

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

What would be the result after the following code was executed? int[ ] x = {23, 55, 83, 19}; int[ ] y = {36, 78, 12, 24}; for (int a = 0; a < x.length; a++) { x[a] = y[a]; y[a] = x[a]; } a) x[ ] = {36, 78, 12, 24} and y[ ] = {36, 78, 12, 24} b) x[ ] = {36, 78, 12, 24} and y[ ] = {23, 55, 83, 19} c) x[ ] = {36, 78, 12, 24} and y[ ] = {23, 55, 83, 19} d) This is a compilation error.

A) x[ ] = {36, 78, 12, 24} and y[ ] = {36, 78, 12, 24}

Look at the fellowing program and tell what the program will output when run. public class ExceptionTest { public static void main(String[] args) { int number; String str; try { str = "xyz"; number = Integer.parseInt(str); System.out.println("A"); } catch (NumberFormatException e) { System.out.println("B"); } catch(IllegalArgumentException e) { System.out.println("C"); } System.out.println("D"); } }

B D

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

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

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

B) 1

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

For the following code, how many times would the while loop execute? StringTokenizer strToken = new StringTokenizer("Cars, trucks, and SUVs " + "are all types of automobiles."); while (strToken.hasMoreTokens()) { System.out.println(strToken.nextToken()); } A) 1 B) 9 C) 7 D) 5

B) 9

What is the value of scores[2][3] in the following array? int [] [] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} }; A) 84 B) 94 C) 95 D) 93

B) 94

What is the value of the scores [2] [3] in the following array? int [ ] [ ] scores = { { 88, 80, 79, 92}, {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} }; A) 84 B) 94 C) 95 D) 93

B) 94

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

To convert the int variable, number to a string, use the following statement. A) String str = integer(number); B) String str = Integer.toString(number); C) String str = integer.toString(number); D) String str = number.Integer.toString(str);

B) String str = Integer.toString(number);

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.

Look at the following code. Integer myNumber; myNumber = 5; Which of the following is true about the second statement? A) It results in an error because you cannot assign a primitive type to a wrapper class object. B) The statement performs unboxing. C) The statement performs autowrapping. D) The statement performs autoboxing.

B) The statement performs autoboxing.

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

B) Throwable

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"

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

In the following statement, what data type must recField be? str.getChars(5, 10, recField, 0); A) String B) char[ ] C) char D) int

B) char[ ]

In memory, an array of String objects A) must be initialized when the array is declared B) consists of an array of references to String objects C) consists of elements, each of which is a String D) Iist arranged the same as an array of primitive objects

B) consists of an array of references to String objects

In a string that contains a series of words or other items of data separated by spaces or other characters, the programming term for the spaces or other characters is A) buffer B) delimiter C) separator D) token

B) delimiter

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

B) event driven

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.*;

To use the StringTokenizer class you must have the following import statement. A) import java.StringTokenizer; B) import java.util.StringTokenizer; C) import java.util.String; D) import java.String;

B) import java.util.StringTokenizer;

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

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.indexOf("ov"); A) 16 B) 18 C) 15 D) 17

C) 15

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

What will be the value of x[1] after the following code is executed? int[] x = { 22, 33, 44 }; arrayProcess(x); ... public static void arrayProcess(int[] a) { for(int k = 0; k < 3; k++) { a[k] = a[k] + 5; } } A) 33 B) 49 C) 38 D) 27

C) 38

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"));

The following statement creates an ArrayList object. What is the purpose of the <String> notation? ArrayList<String> arr = new ArrayList<String>(); A) It specifies that everything stored in the ArrayList object will be converted to a String. B)It specifies the String objects may not be stored in the ArrayList object. C) It specifies that only String objects may be stored in the ArrayList object. D) It specifies that the get method will return only String objects.

C) 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>(); A) It specifies that everything stored in the ArrayList object will be converted to a String. B) It specifies that String objects may not be stored in the ArrayList object. C) It specifies that only String objects may be stored in the ArrayList object. D) It specifies that the get method will return only String objects.

C) It specifies that only String objects may be stored in the ArrayList object.

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.

Assuming that str is declared as follows, String str = "RSTUVWXYZ"; what value will be returned from str.charAt(5)? A) V B) X C) W D) U

C) W

What will be the value of str after the following statements are executed? StringBuilder str = new StringBuilder("We have lived in Chicago, " + "Trenton, and Atlanta."); str.replace(17, 24, "Tampa"); A) We have lived in Chicago, Trenton, and Tampa. B) We have lived in Chicago, Tampa, and Atlanta. C) We have lived in Tampa, Trenton, and Atlanta. D) We have lived in Chicago, Tampaon, and Atlanta.

C) We have lived in Tampa, Trenton, and Atlanta.

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

The StringBuilder constructor used in the following statement will StringBuilder str = new StringBuilder(25); A) give the object, str, 25 or more bytes of storage and store spaces in them B) give the object, str, 25 bytes of storage and store spaces in them C) give the object, str, 25 bytes of storage and not store anything in them D) give the object, str, 0 bytes of storage

C) give the object, str, 25 bytes of storage and not store anything in them

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 return an array of long values from a method, use this as the return type for the method. A) long[ARRAY_SIZE] B) [ ]long C) long[ ] D) long

C) long[ ]

You use this method to determine the number of items stored in an ArrayList object. A) size B) items C) numberItems D) capacity

C) numberItems

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

In order to do a binary search on an array, A) you must first do a sequential search of the array assure the element you looking for is there B) the values of the array must be numeric C) the array must first be sorted in ascending order D) there are no requirements

C) the array must first be sorted in ascending order

The sequential search algorithm A) returns the value it was searching for B) will not excute, if teh element is not in the array C) uses a loop to sequentially step through an array, starting with the first element D) requires the array to be ordered

C) uses a loop to sequentially step through an array, starting with the first element

The sequential search algorithm A) returns the value it was searching for B) will not execute, if the element is not in the array C) uses a loop to sequentially step through an array, starting with the first element D) requires the array to be ordered

C) uses a loop to sequentially step through an array, starting with the first element

What would be the results of the following code? int[] array1 = new int[25]; ... // Code that will put values in array1 int value = array1[0]; for (int a = 1; a < array1.length; a++) { if (array1[a] < value) value = array1[a]; } A) value contains the average of the values in array1 B) value contains the highest value in array1 C) value contains the lowest value in array1 D) value contains the sum of all the values in array1

C) value contains the lowest value in array1

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

This is an intrenal list of all the methods that are currently excuting.

Call Stack

What will be the value of x[8] after the following code has executed? final in SUB = 12; int[] x =new int[SUB]; int y = 100; for(int i = 0; i < SUB; i++); { x[i] = y; y += 10; } a) 200 b) 190 c) 170 d) 180

D) 180

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

A protected member of a class may be directly accessed by A) methods in the same package B) methods of a subclass C) methods of the same class D) All of the above

D) All of the above

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

If a class contains an abstract method, A) the method must be overridden in subclasses B) the method will have only a header, but not a body, and end with a semicolon C) you cannot create an instance of the class D) All of the above *

D) All of the above

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

Using the StringBuilder class's insert method, you can insert A) a char array B) a String object C) a primitive type D) All of the above

D) All of the above

What does the following statement do? Double number = new Double(8.8); A) It assigns the object's address to the number variable. B) It initializes that object to 8.8. C) It creates a Double object. D) All of the above

D) All of the above

When an array is passed to a method A) a reference to the array is passed B) the method has direct access to the original array C) it is passed just as an object D) All of the above

D) All of the above

What will be the result of the following code? final int ARRAY_SIZE = 5; float [] x = float [ARRAY_SIZE]; for(int i = 1; i <= ARRAY_SIZE; i++); { x[i] = 10.0; } a) All the values, except the first, are set to 10.0. b) There will be a compilation error. c) All th evalues in the array are initialized to 10.0. d) An error will occur when the program runs.

D) An error will occur when the program runs.

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

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

Look at the following code. The method in line ________ will override the method in line ________. Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public int method1(int a){} Line 5 public double method2(int b){} Line 6 } Line 7 public ClassB extends ClassA Line 8 { Line 9 public ClassB(){} Line 10 public int method1(int b, int c){} Line 11 public double method2(double c){} Line 12 } A) 11, 5 B) 10, 4 C) Both A and B D) None of the above

D) None of the above

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.

What does the following statement do? double[ ] array1 = new double[10]; a) creates an instance of an array of 10 double values b) declares array1 to be a reference to an array of double values c) will allow valid subscripts in the range of 0-9 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

You use this method to determine the number of items stored in an ArrayList object. A) size B) items C) numberItems D) capacity

D) capacity

To convert the string, str = "285.74" to a double and store it in the variable x, use the following statement A) double x = str,Double.parseDouble; B) double x = str; C) double x = Double.Double(str); D) double x = Double.parseDouble(str);

D) double x = Double.parseDouble(str);

The ArrayList class is in this package. A) java.arraylist B) java.array C) java.lang D) java.util

D) java.util

If numbers is a two-dimensional array, which of the following would give the length of row r? A) numbers.length [r] B) numbers.length C) numbers [r].length [r] D) numbers [r].length

D) numbers [r].length

If numbers is a two-dimensional array, which of the following would give the length of row r? A) numbers.length[r] B) numbers.length C) numbers[r].length[r] D) numbers[r].length

D) numbers[r].length

Which of the following is a correct method header for receiving a two-dimensional array as an argument? A) public static void passArray(int [ ], int[ ] intArray) B) public static void passArray(int [1, 2] intArray) C) public static void passArray(int [1], [2] intArray) D) public static void passArray(int [ ] [ ] intArray)

D) public static void passArray(int [ ] [ ] intArray)

Which of the following is a correct method header for receiving a two-dimensional array as an argument? A) public static void passArray(int[ ], int[ ]intArray) B) public static void passArray(int[1,2] intArray) C) public static void passArray(int[1],[2] intArray) D) public static void passArray(int [ ][ ] intArray)

D) public static void passArray(int [ ][ ] intArray)

This ArrayList class method deletes an item from an ArrayList. A) erase B) purge C) delete D) remove

D) remove

This ArrayList class method deletes an item from an ArrayList. A) erase B) purge C) delete D) remove

D) remove

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"); A) str would equal "Little Jack Horner" B) The program would crash. C) str would equal "Little Jac Horner sat on the" D) str would equal "Little Jack Horner sat on the corner"

D) str would equal "Little Jack Horner sat on the corner"

Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement: A) str.uppercase(); B) str.toUpperCase(); C) str[0].upperCase(); D) str[0].toUpperCase();

D) str[0].toUpperCase();

The Character wrapper class provides numerous methods for A) adding two char variables B) testing String objects C) converting String variables D) testing and converting char variables

D) testing and converting char variables

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

When you are writing a program with String objects that may have unwanted spaces at the beginning or end of the strings, use this method to delete them. A) replace B) substring C) valueOf D) trim

D) trim

A partially-filled array is normally used A) when you know how many elements will be in the array B) to display array elements C) with an accompanying parallel array D) with an accompanying integer value that holds the number of items stored in the array

D) with an accompanying integer value that holds the number of items stored in the array

If your code does not handle an exception when it is thrown, it is dealt with by this.

Defualt

With this type of binding, the Java Virtual Machine determines at runtime which method to call, depending on the type of the object that a variable references.

Dynamic

This key word indicates that a class inherits from another class.

Estends

This is a section of code that gracefully responds to exceptions.

Exception handler

A GUI program automatically stops executing when the end of the main method is reached. T/F

False

A class can implement only on interface. T/F

False

A problem can be solved recursively if it can be broken down into successive smaller problems that are unique within the overall problem. T/F

False

A superclass has a member with package access. A class that is outside the superclass's package but inherits from the superclass can access this member. T/F

False

A superclass reference variable can reference an object of a class that inherits from the superclass. T/F

False

An object of a superclass can access members declared in a subclass. T/F

False

Constructors are not inherited T/F

False

IOException serves as a superclass for exceptions that are related to programming errors, such as an out-of-bounds array subscript. T/F

False

If a method in a subclass has the same signature as a method in the superclass, the subclass method overloads the superclass method. T/F

False

If a subclass constructor does not explicitly call a superclass constructor, Java will not call any of the superclass's constructors. T/F

False

Java limits the number of dimensions that an array may have 15. T/F

False

Java limits the number of dimensions that an array may have to 15. T/F

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()); T/F

False

The throw statement informs the compiler that a method throws one or more exception. T/F

False

The throws clause causes an exception to be thrown. T/F

False

When a method is declared with the final modifier, it must be overridden in a subclass. T/F

False

When an exception is thrown by code inside a try block, all of the statements in the try block are always excuted. T/F

False

When in the same try statement you are handling multiple exceptions and some of the exceptions are related to each other through inheritance, you should handle the more general exception classes before the more specialized exception classes. T/F

False

You cannot have more than one catch block per try statement T/F

False

You must call a method to get the value of a wrapper class object. T/F

False

Write a statement that creates an object that can be used to write bunary data to the file Configuration.dat.

FileO utputStream fstream = new FileOutputStream("Configuration.dat");

This is one or more statements that are always executed after the try block has executed and after any catch blocks have executed if an exception was thrown.

Finally block

FileNotFoundException inherits from

IOException

Look at the following code. What is missing from ClassA? Line 1 public interface MyInterface Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double); Line 5 } Line 6 public class ClassA implements MyInterface Line 7 { Line 8 FIELDA = 60; Line 9 public int methodB(double) { } Line 10 }

It does not override methodA

Look at the following code and determine what the call to super will do. public class ClassB extends ClassA { public ClassB() { super(10); } }

It will call the constructor of ClassA that receives an integer as an argument. *

If a subclass constructor does not explicitly call a superclass constructor

Java will automatically call the superclass's default constructor just before the code in the subclass's constructor executes

Look at the following code. Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public void method1(){} Line 5 } Line 6 public class ClassB extends ClassA Line 7 { Line 8 public ClassB(){} Line 9 public void method1(){} Line 10 } Line 11 public class ClassC extends ClassB Line 12 { Line 13 public ClassC(){} Line 14 public void method1(){} Line 15 } Which method1 will be executed as a result of the following statements? ClassA item1 = new ClassC(); item1.method1();

Line 14

Look at the following code. Which line has an error? Line 1 public interface Interface1 Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double){} Line 5 }

Line 4

Look at the following code. Which line in ClassA has an error? Line 1 public interface MyInterface Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double); Line 5 } Line 6 public class ClassA implements MyInterface Line 7 { Line 8 FIELDA = 60; Line 9 public int methodA(double) { } Line 10 }

Line 8

The numeric wrapper classes' "parse" methods all throw an exception of this type.

NumberFormatException

All classes directly or indirectly inherit form this class.

Object

A method in a subclass having the same name as a method in the superclass but a different signature, is an example of

Overloading

A method in a subclass having the same signature as a method in the superclass is an example of

Overriding

If you do not provide an access specifier for a class member, the class member is given this access by default.

Package

This method can be called from any exception object, and it shows the chain of methods that were called when the exception was thrown.

PrintStackTrace

A subclass does not have access to these superclass members.

Private

When declaring class data members, it is best to declare them as

Private members

These superclass members are accessible to subclasses and classes in the same package

Protected

All exceptions that do not inherit from the Error class or the RuntimeException class are

Recoverable exceptions

This is the process of converting an object to a series of bytes that represent the object's data.

Serialization

In an inheritance relationship, this is the specialized class.

Subclass

This key word refers to an object's superclass.

Super

In an inheritance relationship, this is the general class.

Superclass

What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { int init = 10; super(40); } }

The call to the method super must be the first statement in the constructor.

Find the Error try { number = Integer.parseInt(str); } catch (Exception e) { System.out.println(e.getMessage()); } catch (IllegalArgumenrException e) { System.out.println("Bad number format"); } catch (numberFormatException e) { System.out.println(str + " is not a number."); }

The catch (Exception e) statement and its block should appear after the other catch blocks, because this is a more general exception than the others.

Find the Error catch (FileNotFoundException e) { System.out.println("File not found"); } try { File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file); }

The try block must appear first.

This informs the compiler of the exception that could get thrown from a method.

This informs the compiler of the exception that could get thrown from a method.

Look at the following code. Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public void method1(int a){} Line 5 } Line 6 public class ClassB extends ClassA Line 7 { Line 8 public ClassB(){} Line 9 public void method1(){} Line 10 } Line 11 public class ClassC extends ClassB Line 12 { Line 13 public ClassC(){} Line 14 public void method1(){} Line 15 } Which method will be executed as a result of the following statements? ClassB item1 = new ClassA(); item1.method1();

This is an error and will cause the program to crash

You use this statment to manually throw an exception.

Throw

All exception classes inherit from this class.

Throwable

When an exception is generated, it is said to have been____

Thrown

A class must implement the Serializable interface in order for objects of the class to be serialized. T/F

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. T/F

True

A sorting algorithm is a techique for scanning through an array and rearranging its contents in some specific order. T/F

True

A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order. T/F

True

A subclass reference variable can reference an object of the superclass. T/F

True

Although check boxes may be grouped in a ButtonGroup like radio buttons are, they are not normally grouped as such. T/F

True

An abstract class is not instantiated, but serves as a superclass for other classes. T/F

True

Any items typed on the command-line, separated by space, after the name of the class are considered to be one or more arguments that are to be passed into the main method. T/F

True

Any problem that can be solved recursively can also be solved iteratively. T/F

True

By default all members of an interface are public. T/F

True

Every class is either directly or indirectly derived from the Object class. T/F

True

If a non-letter is passed to the toLowerCase or toUpperCase method, it is returned unchanged. T/F

True

If you are using characters other than whitespaces as delimiters, you will probably want to trim the string before tokenizing; otherwise, the leading and/or following whitespaces will become part of the first and/or last token. T/F

True

In a subclass, a call to the superclass constructor can be written only in the subclass constructor T/F

True

Indirect recursion occurs when a method calls another method that in turn calls the first method. T/F

True

It is not possible for a superclass to call a subclass's method. T/F

True

It is possible to write the main method directly into a GUI class. T/F

True

Not including polymorphic references, a try statement can have only have one catch clause for each specific type of exception. T/F

True

The call stack is an internal list of all the methods that are currently executing. T/F

True

The superclass constructor always executes before the subclass constructor. T/F

True

To compare the contents of two arrays, you must compare the elements of the two arrays. T/F

True

What will be the value of matches after the following code is executed? boolean matches; String[] productCodes = {"456HI345", "3456hj"}; matches = productCodes[0].regionMatches(true, 1, productCodes[1], 2, 3); A) 56H B) 56h C) false D) true

True

When a class contains an abstract method, the class cannot be instantiated. T/F

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. T/F

True

When an array of objects is declared, but not initialized, the array values are set to null. T/F

True

When an exception is thrown, the JVM searches the try statement's catch clauses fromt top to bottom and passes control of the program to the first catch clause with a parameter that is compatible with the exception. T/F

True

When deserializing an object using the readObject method, you must cast the return value to the desired class type. T/F

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. T/F

True

X StringBuilder objects are immutable. T/F

True

X The String class's valueOf() method accepts a string representation as an argument and returns its equivalent integer value. T/F

True

You are not required to catch exceptions that inherit from the RuntimeException class. T/F

True

You can think of this code as being "protected" because the application will not halt if it throws an exception.

Try block

These are exception that inherit from Error class or the RuntimeException class.

Unchecked exceptions

If ClassC is derived from ClassB, which is derived from ClassA, this would be an example of

a chain of inheritance

When an "is a" relationship exists between objects, it means that the specialized object has

all the characteristics of the general object, plus additional characteristics

In a subclass constructor, a call to the superclass constructor must

appear as the very first statement

All fields declared in an interface

are final and static

Feilds in an interface are

are final and static

Abstract classes cannot

be instantiated

This method can be used to retrieve the error message from an exception object

getMessage

Look at the following code. Which line will cause a compiler error? Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public final int method1(int a){} Line 5 public double method2(int b){} Line 6 } Line 7 public ClassB extends ClassA Line 8 { Line 9 public ClassB(){} Line 10 public int method1(int b){} Line 11 public double method2(double c){} Line 12 }

line 10

Abstract methods must be

must be overriden

When a class implements an interface it must

provide all of methods that are listed in the interface, with exact signatures specified.

Write an exception class that can be thrown when a negative number is passed to a method.

public class NegativeNumber extends Exception { /** * No-Arg constructor */ public NegativeNumber() { super("Error: Negative number"); } /** * The following constructor accepts the number that * caused the exception. */ public NegativeNumber(int n) { super("Error: Negative number: " + n); } }

How would you declare Salaried as a subclass of PayType?

public class Salaried extends PayType

Write a method that searches a numeric array for a specified value. The method should return the subscript of the element containing the value if it is found in the array. If the value is not found, the method should throw an exception of the Exception class with the error message "Element not found".

public static int arraySearch( int[] array, int value) throws Exception { int i; // Loop control variable int element; // Element the value is found at boolean found; // Flag indicating search results // Element 0 is the starting point of the search. i = 0; // Store the default values element and found. element = -1; found = false; // Search the array. while (!found && i < array.length) { if (array[i] == value) { found = true; element = i; } i++; } if (element == -1) throw new Exception("Element not found."); else return element; }

The following is an explicit call to the superclass's defualt constructor.

super();

In UML diagrams, inheritance is shown

with a line that has an open arrowhead at one end that points to the superclass


Conjuntos de estudio relacionados

Video Quizzes and Section Tests/Quizzes up to u7ch3, Life Span Development: A Topical Approach Chapter 12, Life-Span Development Chapter 10, Life-Span Development Chapter 10, Life Span Development Possible ch 10, life span development: A topical appr...

View Set

Managerial Accounting Chapter 17

View Set

Breast and Testicular Evolve EAQ Chap 70 & 72

View Set

CH. 14 - Franchising and Purchasing an Existing Business

View Set

Learning System 3.0 NCLEX Maternal

View Set

chapter five: control of microbial growth

View Set