COP 2800 Final Exam 1-25

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What will be displayed after the following code is executed? String str = "abc456"; for (int i = 0; i < str.length(); i++) { char chr = str.charAt(i); if (!Character.isLetter(chr)) System.out.print(Character.toUpperCase(chr)); }

// 456

What is the result of the following expression? 10 + 5 * 3 - 20

// 5

What happens when the following code is executed? ComboBox<string> myComboBox = new ComboBox<>; myComboBox.getItems().addAll(5, 10, 15, 20);

// A compiler error will occur.

Unchecked exceptions are those that inherit from the

// Error class or the RuntimeException class.

All of the exceptions that you will handle are instances of classes that extend the ________ class.

// Exception

________ occurs when method A calls method B which in turn calls method A.

// Indirect recursion

In order for an object to be serialized, the class must implement the ________ interface.

// Serializable

The catch clause

// The catch clause does all of these.

What does the following code do, assuming there is a variable that references a Scene object? myScene.getStylesheets().add("sceneStyles.css");

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

The ________ is at least one case in which a problem can be solved without recursion.

// base case

One or more objects may be created from a(n)

// class.

A characteristic of ________ is that only an object's methods are able to directly access and make changes to an object's data.

// data hiding

Given the following statement, which statement will write the string "Calvin" to the file DiskFile.txt? PrintWriter diskOut = new PrintWriter("DiskFile.txt");

// diskOut.println("Calvin");

The ________ loop is ideal in situations where you always want the loop to iterate at least once.

// do-while

Which of the following statements is invalid?

// double r = 2.9X106;

The JVM periodically performs the ________ process to remove unreferenced objects from memory.

// garbage collection

Methods that operate on an object's fields are called

// instance methods.

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

// make sure you are in the same directory or fol

The ________ method removes an item from an ArrayList at a specific index.

// remove

Which of the following is the method you can use to determine whether a file exists?

// the File class's exists method

Given the following method header, what will be returned from the method? public Rectangle getRectangle()

// the address of an object of the Rectangle class

In order to do a binary search on an array

// the array must first be sorted.

In the following Java statement, what value is stored in the variable name? String name = "John Doe";

// the memory address where "John Doe" is located

In a class hierarchy

// the more general classes are toward the top of the tree and the more specialized classes are toward the bottom.

In order to leave 15 pixels of space in an HBox container, use which of the following statements?

//myhbox.setPadding(new Insets(15));

What will be the value of x after the following statements are executed? int x = 10; switch (x) { case 10: x += 15; case 12: x -= 5; break; default: x *= 3;

20

What will be the value of x after the following code is executed? int x, y =15; x = y--;

// 15

What will be the value of x after the following statements are executed? int x = 10; for (int y = 5; y < 20; Y += 5) x += Y

// 40

You can use the enum key word to

F Both of these

Any time a user presses a key, a ________ event occurs.

KEY_PRESSED

To combine several effects, use the Effect class's ________ method.

setInput

If a method does not handle a possible checked exception, what must the method have?

a throws clause in its header

Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList?

add

To use recursion for a binary search, what is required before the search can proceed?

// The array can only include numerical values.

What will be the result after the following code is executed? final int ARRAY_SIZE = 5; float[] x= float[ARRAY_SIZE]; for (i=1; i<ARRAY_SIZE; i++) { x[i]=10.0; }

// The code contains a syntax error and will not compile.

What will be the value of ans after the following statements are executed? int x = 40; int y = 40; if (x = y) ans = x + 10;

// The code contains an error and will not compile.

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

// The cow jumped over the moon.

What would be the result after the following code is executed? int [ ] numbers = {40, 3, 5, 7, 12, 10}; int value = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] < value) value = numbers [i]; }

// The value variable will contain the lowest value in the numbers array.

What would be the result after the following code is executed? int [] numbers = {50, 10, 15, 20, 25, 100, 30}; int value = 0; for(int i = 1; i < numbers.lenght; i++) value += numbers[i];

// The value variable will contain the sum of all the values in the numbers array.

For the following code, which statement is not true? public class Circle { Private double radius; public double x; private double y; }

// The y field is available to code written outside the Circle class.

A Java program must have at least one of the following:

// a class definition

All fields declared in an interface

// are treated as final and static.

Which of the following import statements is required in order to use the ArrayList class?

// import java.util.ArrayList;

Which of the following import statements is required to use the StringTokenizer class?

// import java.util.StringTokenizer;

Which of the following import statements is required in order to write an event handler class?

// import javafx.event.EventHandler;

A class that is defined inside another class is called a(n)

// inner class.

A(n) ________ is a dialog box that prompts the user for input.

// input dialog

A method

// may have zero or more parameters.

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.

// myView.setPreserveRatio(true);

Enumerated types have the ________ method which returns the position of an enum constant in the declaration list.

// ordinal

The two primary methods of programming in use today are

// procedural and object-oriented.

A set of programming language statements that perform a specific task is a(n)

// procedure.

A(n) ________ is used to write computer programs.

// programming language

Software refers to

// programs.

All methods specified by an interface are

// public.

Byte code instructions are

// read and interpreted by the JVM.

The process of connecting an event handler object to a control is called ________ the event handler.

// registering

What will be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 100; if (purchase > 1000) discountRate = 0.05; else if (purchase > 750) discountRate = 0.03; else if (purchase > 500) discountRate = 0.01;

// 0.0

How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x > 100);

// 1

What will be the value of x after the following statements are executed? int x = 75; int y = 60; if(x > y) X = X - y;

// 15

What will be displayed after the following statements are executed? int hours = 30; double pay, payRate = 10.00; pay = hours <= 40 ? hours*payRate : hours*payrate*2.0; system.out.println(pay);

// 300.0

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? private static int factorial(int n) { if (n == 0) return 1; else return n * factorial(n - 1); }

// 5

What is the value of z after the following statements have been executed? int x = 4, y = 33; double z; z = (double) (y / x);

// 8.0

When you write an enumerated type declaration, you

// All of these

Which class specifies the amount of time an animation should last?

// Duration

To create an animation in which a node fades in or out over a period of time, use the ________ class.

// FadeTransition

Which of the following statements opens a file named MyFile.txt and allows you to read data from it? PrintWriter inputFile = new PrintWriter("MyFile.txt");

// File file = new File("MyFile.txt"); // Scanner inputFile = new Scanner(file);

To read data from a binary file, you create objects from which of the following classes?

// FileInputStream and DataInputStream

To write data to a binary file, you create objects from which of the following classes?

// FileOutputStream and DataOutputStream

The ________ layout container arranges the contents into cells, similar to a spreadsheet.

// GridPane

What does <String> specify in the following statement? ArrayList<String> nameList = new ArrayList<String>();

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

Which of the following import statements is required to use the Character wrapper class?

// No import statement is required

What would be displayed as a result of executing the following code? final int x = 22, y = 4; y += x; System.out.println("x = " + x + ", y = " + y)

// Nothing. There is an error in the code.

The original name for Java was

// Oak.

When a class does not use the extends key word to inherit from another class, Java automatically extends it from the ________ class.

// Object

Which of the following statements will create an object from the Random class?

// Random myNumber = new Random();

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?

// SavingsAccount.getNumberOfAccounts();

Which of the following statements correctly creates a Scanner object for keyboard input?

// Scanner keyboard = new Scanner(System.in);

Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 12.8%?

// "##0.0%"

Protected class members can be denoted in a UML diagram with the ________ symbol.

// #

________ is the term for the relationship created by object aggregation.

// "Has a"

If you want to use the System.out.printf method to print a string argument, use the ________ format specifier.

// %s

A Java source file must be saved with the extension

// .java

The RandomAccessFile class treats a file as a stream of

// bytes.

An array of String objects

// consists of an array of references to String objects.

A loop that repeats a specific number of times is known as a(n)

// count-controlled.

The data contained in an object is known as

// the attributes.

The boolean data type may contain which of the following range of values?

// true or false

Which of the following statements declares Salaried as a subclass of PayType?

public class Salaried extends PayType

There are ________ bits in a byte.

// 8

which mouse event occurs when the user presses and releases the mouse button?

// MOUSE_CLICKED

Which of the following statements converts an int variable named number to a string and stores the value in the String object variable named str?

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

To print "Hello, world" on the monitor, which of the following Java statements should be used?

// System.out.println("Hello, world");

Which of the following statements will display the maximum value that a double can hold?

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

Which of the following statements draws the string "Love to animate!" starting at coordinates (200, 50)?

// Text myWords = new Text(200.0, 50.0, "Love to animate!");

If the data.dat file does not exist, what will happen when the following statement is executed? RandomAccessFile randomFile = new RandomAccessFile("data.dat", "rw");

// The file, data.dat, will be created.

What will be the result of the following statements? FileInputStream fstream = new FileInputStream("Input.dat"); DataInputStream inFile = new DataInputStream(fstream);

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

What would be displayed as a result of executing the following code? int x = 578; System.out.print("There are " + x + 5 + "\n" + "hens in the hen house.");

// There are 5785 // hens in the hen house.

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

// There will be five pixels of space between the controls horizontally in the container.

If the following is from the method section of a UML diagram, which of the statements shown is true? + equals(object2:Stock) : boolean

// This is a public method that accepts a Stock object as its argument and returns a boolean value.

Adding RadioButton controls to a ________ object creates a mutually exclusive relationship between them.

// ToggleGroup

Which class is used to move a node from one position on the screen to another?

// TranslateTransition

Given the following declaration: enum Tree ( OAK, MAPLE, PINE ) What is the fully-qualified name of the PINE enum constant?

// Tree.PINE

When a character is stored in memory, it is actually the ________ that is stored.

// Unicode number

What will be displayed after the following code is executed? String str = "RSTUVWXYZ"; System.out.println(str.charAt(5));

// W

To serialize an object and write it to the file, use the ________ method of the ObjectOutputStream class.

// WriteObject

Which of the following is a named storage location in the computer's memory?

// a variable

RAM is usually

// a volatile type of memory, used for temporary storage.

What is the following statement an example of? import java.util.*;

// a wildcard import statement

Because Java byte code is the same on all computers, compiled Java programs

// are highly portable.

A declaration for an enumerated type begins with the ________ key word.

// enum

In the following code that uses recursion to find the greatest common divisor of a number, what is the base case? public static int gcd(int x, int y) { if (x % y == 0) return y; else return gcd(y, x % y); }

// if (x % y ==) // return y;

Which of the following is the operator used to determine whether an object is an instance of a particular class?

// instanceOf

Which of the following is a valid declaration for a ragged array with five rows but no columns?

// int[][] ragged = new int[5][];

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

// jumped

Which Scanner class method reads a String?

// nextLine

Which of the following statements correctly specifies two interfaces?

// public class ClassA implements Interface1, Interface2

A method that calls itself is a ________ method.

// recursive

When an argument is passed by value

// the parameter variable holds the address of the argument.

Application software refers to

// the programs that make the computer useful to the user.

A flag may have the values

// true or false.

The "has a" relationship is sometimes called a(n) ________ because one object is part of a greater whole.

// whole-part relationship

Beginning with Java7, you can use ________ to reduce a lot of duplicated code in a try statement needs to catch multiple exceptions, but performs the same operation for each one.

// multi-catch

Which of the following statements will allow a user to type input into a field of a ComboBox named myComboBox?

// myComboBox.setEditable(true);

Which of the following expressions will generate a random number in the range of 1 through 10?

// myNumber = randomNumbers.nextInt(10) + 1;

Any ________ argument passed to the Character class's toLowerCase method or toUpperCase method is returned as it is.

// nonletter

If you don't provide an access specifier for a class member, the class member is given ________ access by default.

// package

The Application class's ________ method is the main entry point for a JavaFX application.

// start

Which of the following methods returns a string representing all of the items stored in an ArrayList object?

// toString

The following catch clause catch (Exception e)

// can handle all exceptions that are instances of the Exception class or one of its subclasses.

In the following statement, what data type must recField be? str.getChars(5, 10, recField, 0);

// char[]

Which is the key word used to import a class?

// import

When working with the PrintWriter class, which of the following import statements should you have near the top of your program?

// import java.io.*;

Which of the following import statements is required in order to create a BorderPane layout container?

// import javafx.scene.layout.BorderPane;

What will be the value of bonus after the following statements are executed? int bonus, sales = 10000; if (sales < 5000) bonus = 200; else if (sales < 7500) bonus = 500; else if (sales < 10000) bonus = 750; else if (sales < 20000) bonus = 1000; else bonus = 1250;

// 1000

CRC stands for

// Class, Responsibilities, Collaborations.

The Character wrapper class provides numerous methods for

testing and converting character data.

The ________ class is the wrapper class for the char data type.

// Character

Which effect class do you use to increase an image's brightness?

// ColorAdjust

In a UML diagram you show a realization relationship by connecting a class and an interface with a

// dashed line with an open arrowhead at one end.

Variables are classified according to their

// data types.

It is common practice in object-oriented programming to make all of a class's

// fields private.

When writing a string to a binary file or reading a string from a binary file, it is recommended that you use

// methods that use UTF-8 encoding.

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

// moon

By default, a reference variable that is an instance field is initialized to the value

// null

While ________ is centered on creating procedures, ________ is centered on creating objects.

// procedural programming, object-oriented programming

A ________ member's access is somewhere between public and private.

// protected

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?

// scene.getStylesheets().add("javafxstyles.css");

A ________ is a value that signals when the end of a list of values has been reached.

// sentinel

To get the name of a calling enum constant

// use the toString method.

The sequential search algorithm

// uses a loop to sequentially step through an array, starting with the first element.

Data hiding (which means that critical data stored inside the object is protected from code outside the object) is accomplished in Java by

// using the private access specifier on the class fields.

The String class's ________ method accepts a value of any primitive data type as its argument and returns a string representation of the value.

// valueOf

The primitive data types only allow a(n) ________ to hold a single value.

// variable

The binary search algorithm

// will cut the portion of the array being searched in half each time it fails to locate the search value.

The simplest way to use the System.out.printf method is

// with only a format string and no additional arguments.

Key words are

// words that have a special meaning in the programming language.

If object1 and object2 are objects of the same class, to make object2 a copy of object1

// write a method for the class that will make a field by field copy of object1 data members into object2 data members.

Which of the following is not a valid Java comment?

// */ Comment two /*

What will the following code display? String Input = "99#7"; int number; try { number = Integer.parseInt(input); } catch(NumberFormatException ex) { number = 0; } catch(RuntimeException ex) { number = 1; } catch(Exception ex) { number = -1; } System.out.println(numbers);

// 0

What will be the value of discountRate after the following statements are executed? double discountRate; char custType = 'B'; switch (custType) { case 'A': discountRate = .08; break; case 'B': discountRate = .06; case 'C': discountRate = .04; default: discountRate = 0.0; }

// 0.0

What will be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 1250; char cust = 'N' ; if (purchase > 1000) if (cust == 'Y') discountRate = .05; else discountRate = .04; else if (purchase > 750) if (cust == 'Y') discountRate = .04; else discountRate = .03; else discountRate = 0;

// 0.04

How many times will the following for loop be executed? for (int count = 10; count <= 21; count++) System.out.println("Java is great!");

// 12

What will be displayed after the following statements are executed? int x = 65; int y = 55; if (x>=y) { int ans = x+y; } System.out.println(ans);

// 120

What will be the value of position after the following code is executed? int position; String str = "The cow jumped over the moon."; position = str.indexOf("ov");

// 15

Given the following styles, what size will the text of myLabel be? .root { -fx- font-size: 12pt; } .label { -fx- font-size: 18pt; }

// 18 pts

What will be the value of x after the following code is executed? int X = 10, y = 20; While (Y < 100) { x += Y; Y += 20; }

// 210

What is the result of the following expression? 17 % 3 * 2 - 12 + 15 17 % 3 = 2 2 * 2 -12 + 15 4-12+15= 7

// 7

What are the tokens in the following statement? StringTokenizer st = new StringTokenizer("9-14-2018", "-", true);

// 9, 14, 2018, and -

The StringBuilder class's insert method allows you to insert a(n) ________ into the calling object's string.

// All of these

Which of the following is a CSS named color?

// All of these

Which of the following problems can be solved recursively?

// All of these

To build a menu system you must

// All of these are necessary steps.

Which of the following is not part of the programming process?

// All of these are parts of the programming process.

When an array is passed to a method

// 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];

// All of these are true.

Which of the following is not a way a user can interact with a computer?

// All of these are ways a user can interact with a computer.

What would be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5};

// An array of 6 values, ranging from 0 through 5 and referenced by the variable x will be created.

The foundation of a GUI application is the

// Application class.

The ________ class is used to create a menu bar.

// MenuBar

Assume the following declaration exists: enum Tree ( OAK, MAPLE, PINE ) What will the following code display? System.out.println(Tree.OAK);

// OAK

The type of control normally used when you want the user to only be allowed to select one option from several possible options is the

// RadioButton.

________ operators are used to determine whether a specific relationship exists between two values.

// Relational

Which class creates an animation in which a node rotates?

// RotateTransition

Which transition class causes a node to become larger or smaller?

// ScaleTransition

Which of the following statements creates a Slider with a range of 1 to 20 with a starting value of 1?

// Slider slider = new Slider(1.0, 20.0, 1.0);

Which of the following statements creates an empty TextArea?

// TextArea textArea = new TextArea();

To create a TextField control, you use the ________ class which is in the ________ package.

// TextField, javafx.scene.control

Assume the class BankAccount has been created and the following statement correctly creates an instance of the class. BankAccount account = new BankAccount(5000.00); What is true about the following statement? System.out.println(account);

// The account object's toString method will be implicitly called.

Which of the following statements is not true about the following code? StringBuilder strb = new StringBuilder("Total numbers of parts: "); strb.insert(23, 32);

// The ending position for the insert is 32.

What does the following code snippet do when the animation is played, given that imageView has been created? FadeTransition ftrans = new FadeTransition (new Duration(5000), imageView; ftrans.setFromValue(1.0); ftrans.setToValue(0.5); ftrans.play():

// The image will be completely opaque when displayed and will decrease to 50% opacity over the five minutes of the animation.

Given the following two-dimensional array declaration, which statement is true? int[][] numbers = new int[6][9];

// The numbers array has 6 rows and 9 columns.

In ________, inheritance is shown with a line that has an open arrowhead at one end that points to the superclass.

// a UML diagram

Enclosing a group of statements inside a set of braces creates

// a block of statements.

You cannot use the fully-qualified name of an enum constant for

// a case expression.

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

// a chain of inheritance.

Classes that inherit from the Error class are for exceptions that are thrown when

// a critical error occurs, and the application program should not try to handle them.

Which of the following is a value that is written into the code of a program?

// a literal

What will be the value of x after the following code is executed? int x = 10; while (x < 100) { x += 100; } // 110 381 A runtime error is usually the result of

// a logical error.

What does the following UML diagram entry mean? + setHeight(h : double) : void

// a public method with a parameter of data type double that does not return a value

When a method's type is an object, what is actually returned by the calling program?

// a reference to an object of that class

For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};

// a reference to the String object containing "ghi"

A computer program is

// a set of instructions that allow the computer to solve a problem or perform a task.

A file that contains raw binary data is known as a

// binary file.

Another term for an object of a class is a(n)

// instance.

Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?

// int number = inputFile.nextInt();

Which of the following statements converts a String object variable named str to an int and stores the value in the variable x?

// int x = Integer.parseInt(str);

When a class implements an interface, an inheritance relationship known as ________ inheritance is established.

// interface

A search algorithm

// is used to locate a specific item in a collection of data.

When an exception is thrown

// it must be handled by the program or by the default exception handler.

When the this variable is used to call a constructor

// it must be the first statement in the constructor making the call.

The actions performed by the JVM that take place with each method call are sometimes referred to as

// overhead.

If a method in a subclass has the same signature as a method in the superclass, the subclass method ________ the superclass method.

// overrides

A group of related classes is called a(n)

// package.

A constructor is a method that

// performs initialization or setup operations.

In the ________, we must always reduce the problem to a smaller version of the original problem.

// recursive case

In the hexadecimal color value #CCAA99, the CC refers to which color component?

// red

What will be displayed after the following statements are executed? String str = "red$green&blue#orange"; String[] tokens = str.split("[$&#]"); for (String s : tokens) System.out.print(s + " ");

// red green blue orange

To animate a node with the ScaleTransition class, you specify starting and ending

// scale factors.

What method do you call to register an event handler with a Button control?

// setOnAction

Which of the following can you use to compare two enum data values?

// the equals and compareTo methods

A method's signature consists of

// the method name and the parameter list.

To indicate the data type of a variable in a UML diagram you specify

// the variable name followed by a colon and the data type.

The only limitation that static methods have is

// they cannot refer to nonstatic members of the class.

A series of words or other items of data, separated by spaces or other characters, are known as

// tokens.

What type of relationship exists between two objects when one object is a specialized version of another object?

//"is a"

Given a window that is 640 (width) by 480 (height), which of the following represents the lowest position on the left side?

//(0, 479)

What will be the value of position after the following code is executed? int position; String str = "The cow jumped over the moon."; position = str.lastIndexOf("ov", 14);

//-1

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

//94

On a Web page, the ________ specifies what information to display and the ________ specifies how that information should be displayed.

// HTML, CSS

A ragged array is

// a two-dimensional array where the rows have different numbers of columns.

A(n) ________ method is a method that appears in a superclass but expects to be overridden in a subclass.

// abstract

The variable used to keep a running total in a loop is called a(n)

// accumulator.

A static field is created by placing the key word static

// after the access specifier and before the field's data type.

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.

// aggregate

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

// all of the characteristics of the general object plus additional characteristics.

To return an array of long values from a method, which return type should be used for the method?

// long[]

In CSS, selector names that begin with a period are called ________ selectors.

// type

Which of the following is not a rule that must be followed when naming identifiers?

// Identifiers can contain spaces.

An item that separates other items is known as a

// delimiter.

When you write a method that throws a checked exception, you must

// have a throws clause in the method header.

Overloading is

// having two or more methods with the same name but different signatures.

The ________ statement is used to create a decision structure which allows a program to have more than one path of execution.

// if

In Java, a reference variable is ________ because it can reference objects of types different from its own, as long as those types are related to its type through inheritance.

// polymorphic

Which of the following statements will correctly convert the data type, if x is a float and y is a double?

// x = (float)y;

When you make a copy of the aggregate object and of the objects that it references,

// you are performing a deep copy.

Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 12.8?

//"000.0"

If you have two RadioButtons ( dogRadio and catRadio), how should you code them to create a mutually exclusive relationship?

//ToggleGroup radioGroup = new ToggleGroup(); //dogRadio.setToggleGroup(radioGroup); //catRadio.setToggleGroup(radioGroup):

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.

Which of the following code snippets creates a Line and uses a RotateTransition object to animate it for seven seconds?

// Line myLine = new Line(25, 50, 100, 50); // RotateTransition rtrans = // new RotateTransition(new Duration(7000), myLine);

A protected member of a class may be directly accessed by

// any of these.

What is syntax?

// the rules that must be followed when writing a program

What will be displayed after the following statements are executed? int y = 10; if (y == 10) { int x = 30; x += y; System.out.println(x); }

// 40

What is the value of z after the following code is executed? int x = 5, y = 28; float z; z = (float) (y / x);

// 5.0

A method is called from the main method for the first time. It then calls itself seven times. What is the depth of recursion?

// 7

The ________ arc type causes a straight line to be drawn from one endpoint of the arc to the other endpoint.

// ArcType.CHORD

One important difference between the command line interface and a GUI interface is that

// in a GUI environment the user determines the order in which things happen while the user has no control over the order or events in a command line interface.

You should not define a class that is dependent on the values of other class fields

// in order to avoid having stale data.

To display an image in a JavaFX application you must

// include both the Image and the ImageView classes.

Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.

// methods

If numbers is a two-dimensional array, which of the following would give the number of columns in row r?

// numbers[r].length

UML diagrams do not contain

// object names.

When an event takes place, the control responsible for the event creates an event

// object.

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.

// objects

If you set a scene's size to a width and height that is smaller than the width and height of the image to be displayed,

// only part of the image will be displayed.

A subclass can directly access

// only public and protected members of the superclass.

A ________ loop will always be executed at least once.

// posttest

A cross between human language and a programming language is called

// pseudocode.

One type of design tool used by programmers when creating a model of a program is

// pseudocode.

Which of the following is a correct method header for receiving a two-dimensional array as an argument?

// public static void passMyArray(int[][] myArray)

Which of the following statements will set a ListView control, puppyListView, to be 300 pixels high and 200 pixels wide?

// puppyListView.setSize(200, 300);

In memory, GUI objects in a ________ are organized as ________ in a tree-like hierarchical data structure.

// scene, nodes

You can use the ________ method to replace an item at a specific location in an ArrayList.

// set

To change the alignment of an HBox you call the

// setAlignment method.

All the transition classes inherit a method named ________ which allows you to specify how the animation begins and ends.

// setInterpolator

The ________ method is used to display a message dialog.

// showMessageDialog

Character literals are enclosed in ________ and string literals are enclosed in ________.

// single quotes, double quotes

The central processing unit (CPU) consists of two parts which are

// the control unit and the arithmetic and logic unit (ALU).

In a recursive program, the number of times a method calls itself is known as

// the depth of recursion.

When using the throw statement, if you don't pass a message to the exception object's constructor,

// the exception will have a null message

If a BorderPane region does not contain anything,

// the region will not appear in the GUI.

A(n) ________ contains one or more statements that are executed and can potentially throw an exception.

// try block

In Java there are two categories of exceptions which are

// unchecked and checked.

Which of the following expressions will determine whether x is less than or equal to y?

// x <= y

What would be displayed as a result of executing the following code? int x = 15, y = 20, z = 32; x += 12; y /= 6; z -= 14; System.out.println("x = " + x + ", y = " + y + ", z = " +z);

// x = 27, y = 3, z = 18

What will be the values of x and y as a result of the following code? int x = 25, y = 8; x += y++;

// x = 33, y = 9

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

// x = 37, y = 5

Which of the following statements opens a file named MyFile.txt and allows you to append data to its existing contents?

// FileWriter fwriter = new FileWriter("MyFile.txt", true); // PrintWriter outFile = new PrintWriter(fwriter);

What does the following code do? Scanner keyboard = new Scanner(System.in); String filename; System.out.print("Enter the filename: "); filename = keyboard.readString(); PrintWriter outFile = new PrintWriter(filename);

// It allows the user to enter the name of the file that data will be written to.

What does the following code snippet do? Circle myCircle = new Circle(50, 50, 25); TranslateTransition rtrans = new TranslateTransition(new Duration(5000), myCircle);

// It creates a circle with center point (50, 50), radius = 25, and duration = 5 seconds.

What does the following statement do? Image puppy = new Image("file:C:\\images\terrier.jpg");

// It loads an image file named terrier.jpg which is found in the images folder on the user's C-drive.

In a catch statement, what does the following code do? System.out.println(e.getMessage());

// It prints the error message for an exception.

What happens if a program does not handle an unchecked exception?

// The program is halted and the default exception handler handles the exception.

For the following code, which statement is not true? public class Sphere { Private double radius; public double x; private double y; private double z; }

// The z field is available to code written outside the Sphere class.

What will be displayed after the following statements are executed? StringBuilder strb = new StringBuilder ("We have lived in Chicago, Trenton, and Atlanta."); strb.replace(17, 24, "Tampa"); System.out.println(strb);

// We have lived in Tampa, Trenton, and Atlanta.

Which of the following is not involved in identifying the classes to be used when developing an object-oriented application?

// Write the code.

Java requires that the boolean expression being tested by an if statement be enclosed in

// a set of parentheses.

A class becomes abstract when you place the ________ key word in the class definition.

// abstract

What is the following statement an example of? import java.util.Scanner;

// an explicit import statement

What will be the values of ans, x, and y after the following statements are executed? int ans = 35, x = 50, y = 50; if (x >= y) { ans = x + 10; x -= y; } else { ans = y + 10; y += x; }

// ans = 60, x = 0, and y = 50

If you do not provide initialization values for a class's numeric fields, they will

// be automatically initialized to 0.

After the header, the body of the method appears inside a set of

// braces, { }

Which of the following expressions determines whether the char variable, chrA, is not equal to the letter 'A'?

// chrA != 'A'

Which of the following shows the inheritance relationships among classes in a manner similar to that of a family tree?

// class hierarchy

A loop that executes as long as a particular condition exists is called a(n) ________ loop.

// conditional

When recursive methods directly call themselves, it is known as

// direct recursion.

Variables of the boolean data type are useful for

// evaluating conditions that are either true or false.

A(n) ________ is an object that is generated in memory as the result of an error or an unexpected event.

// exception

A(n) ________ is a section of code that gracefully responds to exceptions when they are thrown.

// exception handler

Which key word indicates that a class inherits from another class?

// extends

When a method is declared with the ________ modifier, it cannot be overridden in a subclass.

// final

A ________ is a boolean variable that signals when some condition exists in the program.

// flag

The ________ loop is ideal in situations where the exact number of iterations is known.

// for

To replace a ListView control's existing items with a new list of items, use the ________ method.

// getItems().setAll()

An exception object's default error message can be retrieved using the ________ method.

// getMessage

To retrieve text that a user has typed into a TextField control, you call the ________ method.

// getText

Which of the following statements correctly adds a label to the first row and second column of a GridPane object?

// gridpane.add(myLabel, 0, 1);

A constructor

// has the same name as the class.

In the following code that uses recursion to find the factorial of a number, what is the base case? private static int factorial(int n) { if (n == 0) return 1; else return n * factorial(n - 1); }

// if (n == 0) // return 1;

Which statement tells the compiler where to find the JOptionPane class and makes it available to your program?

// import javax.swing.JOptionPane;

Which of the following import statements must be used in order to use the Color class?

// import.javafx.scene.paint.Color;

If a loop does not contain, within itself, a valid way to terminate, it is called a(n) ________ loop

// infinite

In object-oriented programming, ________ allows you to extend the capabilities of a class by creating another class that is a specialized version of it.

// inheritance

When an object is created, the attributes associated with the object are called

// instance fields.

Which of the following commands will run the compiled Java program named DoItNow?

// java DoItNow

Which package contains the Insets class?

// javafx.geometry

Validating the results of a program is important to

// make sure the program solves the original problem.

Before entering a loop to compute a running total, the program should first

// set the accumulator variable to an initial value, often zero.

Which method is used to determine the number of items stored in an ArrayList object?

// size

In a JavaFX CSS style definition, if a selector name starts with a period, that selector corresponds to a

// specific JavaFX node.

If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?

// str1.equals(str2)

Which of the following expressions could be used to perform a case-insensitive comparison of two String objects named str1 and str2?

// str1.equalsIgnoreCase(str2)

A(n) ________ is used as an index to pinpoint a specific element within an array.

// subscript

The term ________ is commonly used to refer to a string that is part of another string.

// substring

Variables are

// symbolic names made up by the programmer that represent memory locations.

In general, there are two types of files which are

// text and binary.

Which CSS type selector corresponds with the TextField JavaFX class?

// text-field

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

// the first catch clause that can handle the exception.

When an exception is thrown by code in the try block, the JVM begins searching the try statement for a catch clause that can handle it and passes control of the program to

// the first catch clause that can handle the exception.

In an if-else statement, if the boolean expression is false

// the statement or block following the else is executed.

The ________ method returns a copy of the calling String object with all leading and trailing whitespace characters deleted.

// trim

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?

//file.seek(8);

Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 12.8%? Select one:

// "##0.0%"

Which of the following is(are) used as delimiters if the StringTokenizer class's constructor is called and a reference to a String object is passed as the only argument?

// All of these

The key word new

// creates an object in memory.

A(n) ________ is a software entity that contains data and procedures.

// object

Like a loop, a recursive method must have which of the following?

some way to control the number of time it repeats

A class's responsibilities include

// both of these.

The end of a Java statement is indicated by a

// semicolon (;)

The scope of a local variable is

// the method in which it is defined.

An object typically hides its data but allows outside code access to

// the methods that operate on the data.

Which of the following creates a custom style class that will allow a Button control to appear with a blue background and yellow text?

// .button-color { // -fx- background-color: blue; // -fx- text-fill: yellow;

Which of the following is a subclass of Node?

// Both of these

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.

// comma separated value

You can concatenate String objects by using the

// concat method or the + operator.

An action that takes place while a program is running is a(n)

// event.

When a field is declared static there will be

// only one copy of the field in memory.

Computers can do many different jobs because they are

// programmable.

Of the following, which would be considered the no-arg constructor for the Rectangle class?

// public Rectangle()

Java provides a mechanism known as a ________ which makes it possible to write a method that takes a variable number of arguments.

// variable-length argument list

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?

// while (inputFile.hasNext())

A partially filled array is normally used

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

The control that displays a list of items and allows the user to select an item from the list is the ________ control.

ListView

Which symbol indicates that a member is private a UML diagram?

// -

To apply specific styles to all of the nodes in a scene, use the ________ selector.

// .root

Which symbol indicates that a member is public in a UML diagram?

// +

Given the following code, how many times will the while loop be executed? StringTokenizer st = new StringTokenizer("Java programming is fun!"); while (st.hasMoreTokens()) System.out.println(st.nextToken());

// 4

How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x <= 100);

// 5

In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC

// ClassA

In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC

// ClassB

In the following statement, which is the interface? public class ClassA extends ClassB implements ClassC

// ClassC

Which of the statements below give an alternative way to write the following: FileInputStream fstream = new FileInputStream("info.dat"); DataInputStream inputFile = new DataInputStream(fstream);

// DataInputStream inputFile = new DataInputStream(new FileInputStream("info.dat"));

Which of the following will create a CheckBox that displays pizza and shows up as selected?

// CheckBox checkOne = new CheckBox("pizza"); // checkOne.setSelected(true);

Which of the following creates a blue circle centered at X = 50, Y = 50 with a radius of 50?

// Circle blueCircle = new Circle(50, 50, 50); // blueCircle.setFill(Color.BLUE);


Set pelajaran terkait

Foundations of Economics Vocabulary

View Set

在邮局寄信(in the post office)

View Set

Nouns, verbs, adjectives, adverbs, etc..

View Set

last chance to get it right before the big day

View Set

Module 17: Ionic and Covalent Bonds and Compounds

View Set

Ecce Romani Chapter 25 Translation

View Set