Review for Final Exam (All 14 Chapters)
specific JavaFX node.
In a JavaFX CSS style definition, if a selector name starts with a period, that selector corresponds to a
the attributes.
The data contained in an object is known as
Indirect recursion
________ occurs when method A calls method B which in turn calls method A.
read and interpreted by the JVM.
Byte code instructions are
GridPane
The ________ layout container arranges the contents into cells, similar to a spreadsheet.
The array must be sorted.
To use recursion for a binary search, what is required before the search can proceed?
Nothing; the code contains a syntax error.
What does the following code do?
It creates a circle with center point (50, 50), radius = 25, and duration = 5 seconds.
What does the following code snippet do?
It loads an image file named terrier.jpg which is found in the images folder on the user's C-drive.
What does the following statement do? Image puppy = new Image("file:C:\images\terrier.jpg");
5
What is the result of the following expression? 10 + 5 * 3 - 20
The code contains a syntax error and will not compile.
What will be the result after the following code is executed?
TranslateTransition
Which class is used to move a node from one position on the screen to another?
import javafx.event.EventHandler;
Which of the following import statements is required in order to write an event handler class?
Neither of these
Which of the following is a subclass of Node?
Identifiers can contain spaces.
Which of the following is not a rule that must be followed when naming identifiers?
TextArea textArea = new TextArea();
Which of the following statements creates an empty TextArea?
ScaleTransition
Which transition class causes a node to become larger or smaller?
procedural programming, object-oriented programming
While ________ is centered on creating procedures, ________ is centered on creating objects.
"Has a"
________ is the term for the relationship created by object aggregation.
sentinel
A ________ is a value that signals when the end of a list of values has been reached.
a two-dimensional array where the rows have different numbers of columns.
A ragged array is
data types.
Variables are classified according to their
456
What will be displayed after the following code is executed?
110
What will be the value of x after the following code is executed?
0
What will the following code display?
The value variable will contain the lowest value in the numbers array.
What would be the result after the following code is executed?
The ending position for the insert is 32.
Which of the following statements is not true about the following code?
The z field is available to code written outside the Sphere class.
For the following code, which statement is not true?
It prints the error message for an exception.
In a catch statement, what does the following code do? System.out.println(e.getMessage());
char[]
In the following statement, what data type must recField be? str.getChars(5, 10, recField, 0);
variable-length argument list
Java provides a mechanism known as a ________ which makes it possible to write a method that takes a variable number of arguments.
some way to control the number of time it repeats
Like a loop, a recursive method must have which of the following?
ListView
The ________ control uses a drop-down list as its display.
if
The ________ statement is used to create a decision structure which allows a program to have more than one path of execution.
the control unit and the arithmetic and logic unit (ALU).
The central processing unit (CPU) consists of two parts which are
they cannot refer to nonstatic members of the class.
The only limitation that static methods have is
variable
The primitive data types only allow a(n) ________ to hold a single value.
setInterpolator
All the transition classes inherit a method named ________ which allows you to specify how the animation begins and ends.
using the private access specifier on the class fields.
Data hiding (which means that critical data stored inside the object is protected from code outside the object) is accomplished in Java by
ordinal
Enumerated types have the ________ method which returns the position of an enum constant in the declaration list.
scene.getStylesheets().add("javafxstyles.css");
How would a stylesheet named javafxstyles.css be applied to a JavaFX application, assuming that scene is the variable that refers to a Scene object?
class.
One or more objects may be created from a(n)
40
What will be the value of x after the following statements are executed?
aggregate
When a method in the ________ class returns a reference to a field object, it should return a reference to a copy of the field object to prevent security holes.
the exception will have a null message
When using the throw statement, if you don't pass a message to the exception object's constructor,
are actually creating a special kind of class. should use the standard convention of writing the enum constants in uppercase. do not enclose the enum constants in quotation marks. All of these
When you write an enumerated type declaration, you
int[][] ragged = new int[5][];
Which of the following is a valid declaration for a ragged array with five rows but no columns?
+
Which symbol indicates that a member is public in a UML diagram?
set
You can use the ________ method to replace an item at a specific location in an ArrayList.
KEY_PRESSED
Any time a user presses a key, a ________ event occurs.
protected
A ________ member's access is somewhere between public and private.
the methods that operate on the data.
An object typically hides its data but allows outside code access to
instance.
Another term for an object of a class is a(n)
null
By default, a reference variable that is an instance field is initialized to the value
Serializable
In order for an object to be serialized, the class must implement the ________ interface.
File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);
Which of the following statements opens a file named MyFile.txt and allows you to read data from it?
object names.
UML diagrams do not contain
Error class or the RuntimeException class.
Unchecked exceptions are those that inherit from the
evaluating conditions that are either true or false.
Variables of the boolean data type are useful for
The program is halted and the default exception handler handles the exception.
What happens if a program does not handle an unchecked exception?
7
What is the result of the following expression? 17 % 3 * 2 - 12 + 15
5.0
What is the value of z after the following code is executed? int x = 5, y = 28; float z; z = (float) (y / x);
setOnAction
What method do you call to register an event handler with a Button control?
W
What will be displayed after the following code is executed? String str = "RSTUVWXYZ"; System.out.println(str.charAt(5));
0.0
What will be the value of discountRate after the following statements are executed?
15
What will be the value of x after the following code is executed?
Unicode number
When a character is stored in memory, it is actually the ________ that is stored.
final
When a method is declared with the ________ modifier, it cannot be overridden in a subclass.
methods that use UTF-8 encoding.
When writing a string to a binary file or reading a string from a binary file, it is recommended that you use
you are performing a deep copy.
When you make a copy of the aggregate object and of the objects that it references,
RotateTransition
Which class creates an animation in which a node rotates?
.button-color { -fx- background-color: blue; -fx- text-fill: yellow; }
Which of the following creates a custom style class that will allow a Button control to appear with a blue background and yellow text?
str1.equalsIgnoreCase(str2)
Which of the following expressions could be used to perform a case-insensitive comparison of two String objects named str1 and str2?
x <= y
Which of the following expressions will determine whether x is less than or equal to y?
bytes.
The RandomAccessFile class treats a file as a stream of
Character
The ________ class is the wrapper class for the char data type.
MenuBar
The ________ class is used to create a menu bar.
do-while
The ________ loop is ideal in situations where you always want the loop to iterate at least once.
remove
The ________ method removes an item from an ArrayList at a specific index.
will cut the portion of the array being searched in half each time it fails to locate the search value.
The binary search algorithm
true or false.
The boolean expression in an if statement must evaluate to
x = 37, y = 5
What output will be displayed as a result of executing the following code? int x = 5, y = 20; x += 32; y /= 4; System.out.println("x = " + x + ", y = " + y);
jumped
What will be displayed after the following code is executed? String str1 = "The quick brown fox jumped over the lazy dog."; String str2 = str1.substring(20, 26); System.out.println(str2);
import javafx.scene.layout.BorderPane;
Which of the following import statements is required in order to create a BorderPane layout container?
defining and modeling the problem testing and debugging entering code and compiling it All of these are parts of the programming process.
Which of the following is not part of the programming process?
a case expression.
You cannot use the fully-qualified name of an enum constant for
SavingsAccount.getNumberOfAccounts();
If you have defined a class, SavingsAccount, with a public static method, getNumberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will call the getNumberOfAccounts method?
unchecked and checked.
In Java there are two categories of exceptions which are
write a method for the class that will make a field by field copy of object1 data members into object2 data members.
If object1 and object2 are objects of the same class, to make object2 a copy of object1
The file, data.dat, will be created.
If the data.dat file does not exist, what will happen when the following statement is executed? RandomAccessFile randomFile = new RandomAccessFile("data.dat", "rw");
This is a public method that accepts a Stock object as its argument and returns a boolean value.
If the following is from the method section of a UML diagram, which of the statements shown is true? + equals(object2:Stock) : boolean
a way to terminate.
In all but very rare cases, loops must contain, within themselves
the statement or block following the else is executed.
In an if-else statement, if the boolean expression is false
scene, nodes
In memory, GUI objects in a ________ are organized as ________ in a tree-like hierarchical data structure.
inheritance
In object-oriented programming, ________ allows you to extend the capabilities of a class by creating another class that is a specialized version of it.
myView.setPreserveRatio(true);
In order to preserve an image's aspect ratio (so it does not appear stretched or distorted), you should use which of the following? Assume myView references an ImageView object.
comma separated value
In the ________ file format, when data in a spreadsheet is exported, each row is written to a line and commas are used to separate the values in the cells.
recursive case
In the ________, we must always reduce the problem to a smaller version of the original problem.
the File class's exists method
Which of the following is the method you can use to determine whether a file exists?
instanceOf
Which of the following is the operator used to determine whether an object is an instance of a particular class?
int x = Integer.parseInt(str);
Which of the following statements converts a String object variable named str to an int and stores the value in the variable x?
String str = Double.toString(tax);
Which of the following statements converts a double variable named tax to a string and stores the value in the String object named str?
gridpane.add(myLabel, 0, 1);
Which of the following statements correctly adds a label to the first row and second column of a GridPane object?
double r = 2.9X106;
Which of the following statements is invalid?
braces, { }
After the header, the body of the method appears inside a set of
public.
All methods specified by an interface are
Exception
All of the exceptions that you will handle are instances of classes that extend the ________ class.
the address of an object of the Rectangle class
Given the following method header, what will be returned from the method? public Rectangle getRectangle()
18 pts
Given the following styles, what size will the text of myLabel be? .root { -fx- font-size: 12pt; } .label { -fx- font-size: 18pt; }
The numbers array has 6 rows and 9 columns.
Given the following two-dimensional array declaration, which statement is true? int[][] numbers = new int[6][9];
a throws clause in its header
If a method does not handle a possible checked exception, what must the method have?
type
In CSS, selector names that begin with a period are called ________ selectors.
HTML, CSS
On a Web page, the ________ specifies what information to display and the ________ specifies how that information should be displayed.
having two or more methods with the same name but different signatures.
Overloading is
#
Protected class members can be denoted in a UML diagram with the ________ symbol.
whole-part relationship
The "has a" relationship is sometimes called a(n) ________ because one object is part of a greater whole.
garbage collection
The JVM periodically performs the ________ process to remove unreferenced objects from memory.
with only a format string and no additional arguments.
The simplest way to use the System.out.printf method is
procedural and object-oriented.
The two primary methods of programming in use today are
create the Menu objects and register an event handler for each menu item object. Add the MenuBar object to the scene graph. create a MenuBar object. All of these are necessary steps.
To build a menu system you must
System.out.println("Hello, world");
To print "Hello, world" on the monitor, which of the following Java statements should be used?
getText
To retrieve text that a user has typed into a TextField control, you call the ________ method.
FileOutputStream and DataOutputStream
To write data to a binary file, you create objects from which of the following classes?
objects
Using the blueprint/house analogy, you can think of a class as a blueprint that describes a house and ________ as instances of the house built from the blueprint.
the equals and compareTo methods
Which of the following can you use to compare two enum data values?
public class Salaried extends PayType
Which of the following statements declares Salaried as a subclass of PayType?
in order to avoid having stale data.
You should not define a class that is dependent on the values of other class fields
Relational
________ operators are used to determine whether a specific relationship exists between two values.
Hardware
________ refers to the physical components that a computer is made of.
performs initialization or setup operations.
A constructor is a method that
pseudocode.
A cross between human language and a programming language is called
package.
A group of related classes is called a(n)
conditional
A loop that executes as long as a particular condition exists is called a(n) ________ loop.
count-controlled.
A loop that repeats a specific number of times is known as a(n)
may have zero or more parameters.
A method
recursive
A method that calls itself is a ________ method.
the method name and the parameter list.
A method's signature consists of
a logical error.
A runtime error is usually the result of
braces, { }
A block of code is enclosed in a set of
data hiding
A characteristic of ________ is that only an object's methods are able to directly access and make changes to an object's data.
abstract
A class becomes abstract when you place the ________ key word in the class definition.
inner class.
A class that is defined inside another class is called a(n)
a set of instructions that allow the computer to solve a problem or perform a task.
A computer program is
has the same name as the class.
A constructor
programming language
A(n) ________ is used to write computer programs.
abstract
A(n) ________ method is a method that appears in a superclass but expects to be overridden in a subclass.
nonletter
Any ________ argument passed to the Character class's toLowerCase method or toUpperCase method is returned as it is.
while (inputFile.hasNext())
Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops is the correct way to read data from the file until the end of the file is reached?
make sure you are in the same directory or folder where the MyClass.java file is located.
Assume you are at the operating system command line and want to use the following command to compile a program: javac MyClass.java Before entering the command you must
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?
There will be five pixels of space between the controls horizontally in the container.
Assuming three ImageView objects named puppy, kitten, and bunny have been created, what does the following statement do? HBox hbox = new HBox(5, puppy, kitten, bunny);
Class, Responsibilities, Collaborations.
CRC stands for
a UML diagram
In ________, inheritance is shown with a line that has an open arrowhead at one end that points to the superclass.
5 times
Given the following code that uses recursion to find the factorial of a number, how many times will the else clause be executed if n = 5?
12
How many times will the following for loop be executed?
infinite
If a loop does not contain, within itself, a valid way to terminate, it is called a(n) ________ loop
overrides
If a method in a subclass has the same signature as a method in the superclass, the subclass method ________ the superclass method.
file.seek(8);
If a random access file contains a stream of characters, which of the following statements would move the file pointer to the starting byte of the fifth character in the file?
a class definition
A Java program must have at least one of the following:
enum
A declaration for an enumerated type begins with the ________ key word.
tokens.
A series of words or other items of data, separated by spaces or other characters, are known as
TextField, javafx.scene.control
To create a TextField control, you use the ________ class which is in the ________ package.
include both the Image and the ImageView classes.
To display an image in a JavaFX application you must
make sure the program solves the original problem.
Validating the results of a program is important to
symbolic names made up by the programmer that represent memory locations.
Variables are
The getStylesheets method returns an object containing the scene's collection of stylesheets and that object's add method adds sceneStyles.css to the collection.
What does the following code do, assuming there is a variable that references a Scene object? myScene.getStylesheets().add("sceneStyles.css");
It will allow valid subscripts in the range of 0 through 9. It declares array1 to be a reference to an array of double values. It creates an instance of an array of ten double values. It does all of these.
What does the following statement do? double[] array1 = new double[10];
a wildcard import statement
What is the following statement an example of? import java.util.*;
ClassA
In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC
red
In the hexadecimal color value #CCAA99, the CC refers to which color component?
false
What will be displayed after the following code is executed? boolean matches; String str1 = "The cow jumped over the moon."; String str2 = "moon"; matches = str1.endsWith(str1); System.out.println(matches);
The cow jumped over the moon.
What will be displayed after the following code is executed? StringBuilder strb = new StringBuilder(12); strb.append("The cow "); strb.append("jumped over the "); strb.append("moon."); System.out.println(strb);
only one copy of the field in memory.
When a field is declared static there will be
a reference to an object of that class
When a method's type is an object, what is actually returned by the calling program?
the method has direct access to the original array. it is passed just as any other object would be passed. a reference to the array is passed. All of these are true.
When an array is passed to a method
it must be handled by the program or by the default exception handler.
When an exception is thrown
the first catch clause that can handle the exception
When an exception is thrown by code in its try block, the JVM begins searching the try statement for a catch clause that can handle it and passes control of the program to
Duration
Which class specifies the amount of time an animation should last?
import
Which is the key word used to import a class?
extends
Which key word indicates that a class inherits from another class?
Line myLine = new Line(25, 50, 100, 50); RotateTransition rtrans = new RotateTransition(new Duration(7000), myLine);
Which of the following code snippets creates a Line and uses a RotateTransition object to animate it for seven seconds?
java DoItNow
Which of the following commands will run the compiled Java program named DoItNow?
Circle blueCircle = new Circle(50, 50, 50); blueCircle.setFill(Color.BLUE);
Which of the following creates a blue circle centered at X = 50, Y = 50 with a radius of 50?
myNumber = randomNumbers.nextInt(10) + 1;
Which of the following expressions will generate a random number in the range of 1 through 10?
import java.util.ArrayList;
Which of the following import statements is required in order to use the ArrayList class?
No import statement is required
Which of the following import statements is required to use the Character wrapper class?
public static void passMyArray(int[][] myArray)
Which of the following is a correct method header for receiving a two-dimensional array as an argument?
It will allow valid subscripts in the range of 0 through 9. It creates an instance of an array of ten long values. It declares array1 to be a reference to an array of long values. All of these are true.
Which of the following statements is(are) true about this code? final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE];
FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter);
Which of the following statements opens a file named MyFile.txt and allows you to append data to its existing contents?
myComboBox.setEditable(true);
Which of the following statements will allow a user to type input into a field of a ComboBox named myComboBox?
x = (float)y;
Which of the following statements will correctly convert the data type, if x is a float and y is a double?
Random myNumber = new Random();
Which of the following statements will create an object from the Random class?
"##0.0%"
Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 12.8%?
CheckBox checkOne = new CheckBox("pizza"); checkOne.setSelected(true);
Which of the following will create a CheckBox that displays pizza and shows up as selected?
DataInputStream inputFile = new DataInputStream(new FileInputStream("info.dat"));
Which of the statements below give an alternative way to write the following: FileInputStream fstream = new FileInputStream("info.dat"); DataInputStream inputFile = new DataInputStream(fstream);
import javax.swing.JOptionPane;
Which statement tells the compiler where to find the JOptionPane class and makes it available to your program?
the memory address where "John Doe" is located
In the following Java statement, what value is stored in the variable name? String name = "John Doe";
if (n == 0) return 1;
In the following code that uses recursion to find the factorial of a number, what is the base case?
Scanner keyboard = new Scanner(System.in);
Which of the following statements correctly creates a Scanner object for keyboard input?
create your own data type. specify the values that belong to the type. Both of these
You can use the enum key word to