CIS 2600
if (quotaAmt > 100 || sales > 100 && productCode == "C") bonusAmt = 50;
&&
Which of the following is NOT a valid method to increase a variable named score by 1?
++score = score + 1
The ____ option must be used when running a program in order to see the results of assert statements.
-ea
What is the value of result after the following statement is executed?int result = 2 + 3 * 4;
14
int[][] myVals = {2, 4, 6},{1, 3, 5, 7};Using the above array, what is the value of myVals.length?
2
How many times will outputLabel be called?for(customer = 1; customer <= 20; ++customer)for(color = 1; color <= 3; ++color)outputLabel();
60
In the expressions b = 8 and c = --b, what value will be assigned to the variable c?
7
You use a ____ following the closing brace of an array initialization list.
;
The ____ operator is always evaluated before the OR operator.
AND
____ are pieces of information that are sent into, or passed to, a method, usually because the method requires the information to perform its task or carry out its purpose.
Arguments
You can add an item at any point in a(n) ____ container and the array size expands automatically to accommodate the new item.
Array
____ refers to the order in which values are used with operators.
Associativity
When you execute an if...else statement, only one of the resulting actions takes place depending on the evaluation of the ____ following the if.
Boolean expression
When you use the && operator, you must include a complete _____ on each side.
Boolean expression
Which of the following statements will write a line separator?
BufferedWriter.newline();
A(n) ____ is a holding place for bytes that are waiting to be read or written.
ByteBuffer
Which statement correctly declares a sedan object of the Car class?
Car sedan = new Car();
____ variables are variables that are shared by every instantiation of a class.
Class
The ____ class represents more serious errors from which your program usually cannot recover.
Error
Although a method can throw any number of ____ types, many developers believe that it is poor style for a method to throw and catch more than three or four types.
Exception
Which method constructor constructs a new exception with the specified detail message and cause?
Exception(String message, Throwable cause)
You can use Java's ____ class to create your own random access files.
FileChannel
It is a tradition among programmers that the first program you write in any language produces "____" as its output.
Hello, world!
Use the above code and sections labeled 1, 2, and 3 to answer the following:Identify the labeled section that is the constructor for the Bicycle class, identify the section of fields of the Bicycle class, and identify the Bicycle class methods.
Hide Feedback Section 1 identifies the three fields of the Bicycle class: public int cadence, public int gear, and public int speed. Section 2 identifies the single class constructor of the Bicycle class. Section 3 identifies the four methods of the Bicycle class: setCadence, setGear, applyBrake, and speedUp.
Using the above code, describe what will happen if a user enters two usable integers. What will happen if a user enters an invalid noninteger value? What will happen if the user enters 0 for the denominator? Write one more catch that will handle any exception and note where it should be placed.
If the user enters two usable integers, the result is calculated, normal output is displayed, and neither catch block executes. If the user enters an invalid (noninteger) value for either the numerator or the denominator, an InputMismatchException object is created and thrown. When the program encounters the first catch block (that catches an ArithmeticException), the block is bypassed because the Exception types do not match. When the program encounters the second catch block, the types match, and the "Wrong data type" message is displayed. If the user enters 0 for denominator, the division statement throws an ArithmeticException, and the try block is abandoned. When the program encounters the first catch block, the Exception types match, the value of the getMessage() method is displayed, and then the second catch block is bypassed.
import java.util.*; public class DivisionMistakeCaught3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int numerator, denominator, result; try { System.out.print("Enter numerator >> "); numerator = input.nextInt(); System.out.print("Enter denominator >> "); denominator = input.nextInt(); result = numerator / denominator; System.out.println(numerator + " / " + denominator + " = " + result); } catch(ArithmeticException mistake) { System.out.println(mistake.getMessage()); } catch(InputMismatchException mistake) { System.out.println("Wrong data type"); } } } Using the above code, describe what will happen if a user enters two usable integers. What will happen if a user enters an invalid noninteger value? What will happen if the user enters 0 for the denominator? Write one more catch that will handle any exception and note where it should be placed.
If the user enters two usable integers, the result is calculated, normal output is displayed, and neither catch block executes. If the user enters an invalid (noninteger) value for either the numerator or the denominator, an InputMismatchException object is created and thrown. When the program encounters the first catch block (that catches an ArithmeticException), the block is bypassed because the Exception types do not match. When the program encounters the second catch block, the types match, and the "Wrong data type" message is displayed. If the user enters 0 for denominator, the division statement throws an ArithmeticException, and the try block is abandoned. When the program encounters the first catch block, the Exception types match, the value of the getMessage() method is displayed, and then the second catch block is bypassed.
____ is a mechanism that enables one class to acquire all the behaviors and attributes of another class.
Inheritance
Java contains a class named ____ that allows you to produce dialog boxes.
JOptionPane
import java.nio.file.*;import java.io.*;import static java.nio.file.StandardOpenOption.*;public class WriteFile{public static void main(String[] args){Path myFile = Paths.get("C:\\Java\\Input.Output\\myNumbers.txt");String nums = "12345";byte[] data = nums.getBytes();OutputStream output = null;try{ -----Code here------ output.write(data)output.flush();output.close();}catch(Exception badNums){System.out.println("My numbers: " + badNums);}}}Using the above code, add a statement on the indicated line that will create a writeable file by constructing a BufferedOutputStream object and assigning it to the OutputStream. No output should appear on the monitor, but a file should be created. - No text entered - This question has not been graded. The correct answer is not displayed for Written Response type questions. View Feedback Question 320 / 1 point import java.nio.file.*; public class PathDemo { public static void main(String[] args) { Path filePath = Paths.get("C:\\Java\\Input.Output\\LessonInfo.txt"); int count = filePath.getNameCount(); System.out.println("Path is " + filePath.toString()); System.out.println("File name is " + filePath.getFileName()); System.out.println("There are " + count + " elements in the file path"); for(int x = 0; x < count; ++x) System.out.println("Element " + x + " is " + filePath.getName(x)); } } The above code demonstrates the creation of a Path and its method. Describe the output that will display when the code is executed.
Path is C:\Java\Input.Output\LessonInfo.txt File name is LessonInfo.txt There are 3 elements in the file path Element 0 is Java Element 1 is Input.Output Element 2 is LessonInfo.txt
____ is the process of arranging a series of objects in some logical order.
Sorting
In Java, ____ is a built-in class that provides you with the means for storing and manipulating character strings.
String
You can tell that the equals() method takes a ____ argument because parentheses are used in the method call.
String
Which of the following correctly declares and initializes a String object?
String greeting = "Hello";
____ polymorphism is the ability of one method to work appropriately for subclasses of the same parent class.
Subtype
Using the example code above, complete the statement of the catch block to generate the message that comes with the caught ArithmeticException
System.out.println(mistake.getMessage());
Which of the following println statements will display the last myScores element in an array of 10?
System.out.println(vals[9]);
public static void main(String args[]) { int a, b; try { a = 0; b = 42 / a; System.out.println("This will not be printed."); } catch (ArithmeticException e) { System.out.println("Division by zero."); } System.out.println("After catch statement."); } The program above includes a try block and a catch clause that processes the ArithmeticException generated by the division-by-zero error. Explain how the try and catch blocks operate, and what the output will be following program execution. Rewrite the catch area so that the actual exception message with output.
The call to the println() statement inside the try block is never executed. Once an exception is thrown, program control transfers out of the try block into the catch block. The catch is not "called," so execution never "returns" to the try block from a catch. Thus, the line "This will not be printed." is not displayed. Once the catch statement has executed, program control continues with the next line in the program following the entire try/catch pair.
The figure above represents code that executes in the try block any statements that might throw exceptions, along with a catch and finally block. Explain three different outcomes of the try block that would cause the code in the finally block to execute.
The code in the finally block executes no matter which of the following outcomes of the try block occurs: The try ends normally. The catch executes. An uncaught exception causes the method to abandon prematurely. The uncaught exception does not allow the try block to finish, nor does it cause the catch block to execute.
import java.nio.file.*; public class PathDemo { public static void main(String[] args) { Path filePath = Paths.get("C:\\Java\\Input.Output\\LessonInfo.txt"); int count = filePath.getNameCount(); System.out.println("Path is " + filePath.toString()); System.out.println("File name is " + filePath.getFileName()); System.out.println("There are " + count + " elements in the file path"); for(int x = 0; x < count; ++x) System.out.println("Element " + x + " is " + filePath.getName(x)); } } The above code demonstrates the creation of a Path and its method. Describe the output that will display when the code is executed.
The following will be output when the code is executed: Path is C:\Java\Input.Output\LessonInfo.txt File name is LessonInfo.txt There are 3 elements in the file path Element 0 is Java Element 1 is Input.Output Element 2 is LessonInfo.txt
Line comments start with ____.
Two forward slashes ( // )
Arrows used in a ____ to show inheritance relationships extend from the descendant class and point to the original class.
UML diagram
To declare a two-dimensional array in Java, you type two sets of ____ after the array type.
[ ]
When a method returns an array reference, you include ____ with the return type in the method header.
[ ]
The characters ____ move the cursor to the next line when used within a println() statement.
\n
BasketBall Player - Will the above code compile correctly? Why or why not? Explain your answer. Revise the code so that it will compile and work as intended.
a subclass cannot override methods that are declared final in the supercass. when attempting to compile the professionalbasketballplayer class, you receive a compile error because the class cannot override the final display method in the parent class.
Methods that retrieve values are called ____ methods.
accessor
The process of repeatedly increasing a value by some amount is known as ____.
accumulating
The arguments in a method call are often referred to as ____.
actual parameters
A literal string is a(n) ____ object.
anonymous
Data items you use in a call to a method are called ____.
arguments
You use ____ operators to perform calculations with values in your programs.
arithmetic
When you use a(n) ____ statement, you state a condition that should be true, and Java throws an AssertionError when it is not.
assert
What is the correct syntax of an assert statement?
assert booleanExpression : optionalErrorMessage
A(n) ____ is a Java language feature that can help you detect logic errors that do not cause a program to terminate, but nevertheless produce incorrect results.
assertion
Because the backslash character starts the escape sequence in Java, you must use two ____ in a string that describes a Path in the DOS operating system.
backslashes
The class used as a basis for inheritance is the ____ class.
base
Programmers often refer to a ____ search as a "divide and conquer" procedure.
binary
Within any class or method, the code between a pair of curly braces is called a(n) ____.
block
A(n) ____ variable can hold only one of two values: true or false.
boolean
Which of the following is NOT an initial value assigned to an object's data field by a default constructor?
boolean fields set to true
In a(n) ____, you repeatedly compare pairs of items, swapping them if they are out of order, eventually creating a sorted list.
bubble sort
An ArrayList's ____ is the number of items it can hold without having to increase its size.
capacity
When a program contains multiple ____ blocks, they are examined in sequence until a match is found for the type of exception that occurred.
catch
You can store any character, including nonprinting characters such as a backspace or a tab, in a(n) ____ variable.
char
You use the ____ data type to hold any single character.
char
____ exceptions are the type that programmers should anticipate and from which programs should be able to recover.
checked
Create a class named Employee with a name and a salary. Make a class named Manager that inherits from Employee with an instance field named department. Supply a toString() method that prints the manager's name, department, and salary. Make another class named Director that inherits from Manager with an instance field named stipendAmount. Supply the toString() method for Director that prints all of its instance variables. Also, write a program named myOutput that instantiates an object of each of the classes and invokes the toString() method of each of the objects.
class Employee{ private String name = "John Doe"; private int Salary = 2000; public String toString() { return "Name: " + name + "\nSalary: " + salary; }}class Manager extends Employee{ private String departmentName = "College of Arts and Science"; public String toString() { return super.toString() + "\nDepartment Name: " + departmentName; }}class Director extends Manager{ private int stipendAmount = 800; public String toString() { return "Stipend amount is: " + stipendAmount; }}public class myOutput{ public static void main(String args[]) {Manager managerOut = new Manager();System.out.println(managerOut.toString();Director directorOut = new Director();System.out.println(directorOut.toString(); }}
In the case where a method might throw more than one exception type, you can specify a list of potential exceptions in the method header by separating them with ____ .
commas
Whenever a method requires multiple arguments, the arguments are always separated with ____.
commas
When the String class ____ method is used to compare two Strings, it provides additional information to the user in the form of an integer value.
compareTp()
It is a good programming practice to ensure that a subscript to an array does not fall below zero, causing a(n) ____.
compiling error
When an object of one class is a data field within another class, they are related by ____.
composition
System.out.println("Your name is " + yourName);The above statement is an example of ____, which is used to join Strings.
concatenation
You can use the ____, which is written as ||, if you want some action to occur when at least one of two conditions is true.
conditional OR operator
A(n) ____ dialog box typically displays the options Yes, No, and Cancel.
confirm
Regarding enumerations, the ____ method returns the name of the calling constant object.
constName
A data item is ____ when it cannot be changed while a program is running. variable constant primitive literal
constant
A(n) ____ method is a method that creates and initializes class objects.
constructor
The name of the ____ is always the same as the name of the class whose objects it constructs.
constructor
When you create a class and do not provide a(n) ____, Java automatically supplies you with a default one.
constructor
A for loop provides a convenient way to create a(n) ____ loop.
counter-controlled
When you place a block within an if statement, it is crucial to place the ____ correctly.
curly braces
Some text files are ____ files that contain facts and figures, such as a payroll file that contains employee numbers, names, and salaries.
data
By convention, a class diagram contains the ____ following each attribute or method.
data type
Locating and repairing all syntax errors is part of the process of ____ a program.
debugging
A ____ checks a value, and based on the result performs one of two actions.
decision structure
A method header is also called a(n) _____
declaration
A(n) ____ constructor is one that requires no arguments.
default
Assertions are meant to be helpful in the ____ stage of a program.
development
A(n) ____ loop is one that performs no actions other than looping.
do nothing
The ____ loop checks the value of the loop control variable at the bottom of the loop after one repetition has occurred.
do...while
A ____ data type can hold 14 or 15 significant digits of accuracy.
double
Due to automatic type promotion, when a method with a double parameter is passed an integer, the integer will be promoted to a(n) ____.
double
Which Java statement creates a ragged array with six rows?
double [][] sales = new double[6][]
Which of the following statements correctly declares and creates an array to hold five double scores values?
double[] scores = new double[5]
Just as you can block statements that depend on an if, you can also block statements that depend on a(n) ____.
else
___ refers to the hiding of data and methods within an object.
encapsulation
A(n) ____ loop allows you to cycle through an array without specifying the starting and ending points for the loop control variable.
enhanced for
The ____ class represents more serious errors from which your program usually cannot recover.
error
An indefinite loop is a(n) ____ loop.
event-controlled
Although a method can throw any number of ____ types, many developers believe that it is poor style for a method to throw and catch more than three or four types.
exception
The parent class of Error is ____.
exception
If you want to ensure that a user enters numeric data, you should use ____ techniques that provide the means for your program to recover from the mistake.
exception handling
You use the keyword ____ to achieve inheritance in Java.
extends
FileSystems is a class that contains ____ methods, which assist in object creation.
factory
In Java, boolean array elements automatically are assigned the value ____.
false
FileChannel fc = null; Path file =Paths.get("C:\\Java\\Chapter.13\\RandomEmployees.txt"); Given the two declarations above, write a Java statement that creates a ByteChannel that is cast to a FileChannel. The file shoould be open for read and write operations.
fc = (FileChannel)Files.newByteChannel(file, READ, WRITE);
A ____ is a group of characters that has some meaning.
field
The length ____ contains the number of elements in the array.
field
The Arrays class ____ method puts a particular value in each element of the array.
fill
If you want all objects to share a single nonchanging value, then the field is static and ______.
final
You can use the ____ modifier with methods when you don't want the method to be overridden.
final
When you have actions you must perform at the end of a try...catch sequence, you can use a ____ block.
finally
public class exceptions { public static void main(String Args[]) { int[] array = new int[3]; try { for(int a=0;a<4;++a) { array[a] = a; } System.out.println(array); } catch(ArrayIndexOutOfBoundsException e) { System.out.println("Out of bounds"); } } } In the above code, the line System.out.println(array); gets skipped when an exception occurs. Write a finally block that will execute, and will execute a System.out.println(array); if there is an exception
finally { System.out.println(array); }
public class exceptions { public static void main(String Args[]) { int[] array = new int[3]; try { for(int a=0;a<4;++a) { array[a] = a; } System.out.println(array); } catch(ArrayIndexOutOfBoundsException e) { System.out.println("Out of bounds"); } } } In the above code, the line System.out.println(array); gets skipped when an exception occurs. Write a finally block that will execute, and will execute a System.out.println(array); if there is an exception.
finally { System.out.println(array); }
When calling this() from a constructor, it must be the ____ statement within the constructor.
first
public class First{ public static void main(String[] args) { System.out.println("First Java application"); }}given the code above, which term identifies the name of the class
first
A ____ consists of written steps in diagram form, as a series of shapes connected by arrows.
flowchart
A(n) ____ loop is a special loop that is used when a definite number of loop iterations is required.
for
When creating a for loop, which statement will correctly initialize more than one variable?
for(a=1, b=2)
____ parameters are variables in a method declaration that accept the values from the actual parameters.
formal
Method names that begin with ____ and set are very typical.
get
The ArrayList class ____ method retrieves an item from a specified location in an ArrayList.
get
The ____ method returns the last Path element in a list of pathnames.
getFileName()
After you create a FileSystem object, you can define a Path using the ____ method with it.
getPath()
When a variable ceases to exist at the end of a method, programmers say the variable ____.
goes out of scope
Using the flowchart above, which decision statement will correctly check that hoursWorked is greater than or equal to the FULL_WEEK constant?
hoursWorked >= FULL_WEEK
import java.nio.file.*;import java.io.*;import java.nio.channels.FileChannel;import java.nio.ByteBuffer;import static java.nio.file.StandardOpenOption.*;import java.util.Scanner;public class CreateEmployeesRandomFile{public static void main(String[] args){Scanner input = new Scanner(System.in);Path file =Paths.get("C:\\Java\\Chapter.13\\RandomEmployees.txt");String s = "000, ,00.00" +System.getProperty("line.separator");final int RECSIZE = s.length();FileChannel fc = null;String delimiter = ",";String idString;int id;String name;String payRate;final String QUIT = "999";try{fc = (FileChannel)Files.newByteChannel(file, READ, WRITE);System.out.print("Enter employee ID number >> ");idString = input.nextLine();while(!(idString.equals(QUIT))){ ----Code here----- System.out.print("Enter name for employee #" +id + " >> ");name = input.nextLine();System.out.print("Enter pay rate >> ");payRate = input.nextLine();s = idString + delimiter + name + delimiter +payRate + System.getProperty("line.separator");byte[] data = s.getBytes();ByteBuffer buffer = ByteBuffer.wrap(data); ----Code here----- fc.write(buffer);System.out.print("Enter next ID number or " +QUIT + " to quit >> ");idString = input.nextLine();}fc.close();}catch (Exception e){System.out.println("Error message: " + e);}The above program will accept any number of employee records as user input and write the records to a file in a loop. In the first indicated line, create the statement to accept the employee data value from the keyboard as a String and convert it to an integer using the parseInt() method. In the second indicated line, create the statement to compute the record's desired position by multiplying the ID number value by the record size.
id = Integer.parseInt(idString); fc.position(id * RECSIZE);
import java.nio.file.*;import java.io.*;import java.nio.channels.FileChannel;import java.nio.ByteBuffer;import static java.nio.file.StandardOpenOption.*;import java.util.Scanner;public class CreateEmployeesRandomFile{public static void main(String[] args){Scanner input = new Scanner(System.in);Path file =Paths.get("C:\\Java\\Chapter.13\\RandomEmployees.txt");String s = "000, ,00.00" +System.getProperty("line.separator");final int RECSIZE = s.length();FileChannel fc = null;String delimiter = ",";String idString;int id;String name;String payRate;final String QUIT = "999";try{fc = (FileChannel)Files.newByteChannel(file, READ, WRITE);System.out.print("Enter employee ID number >> ");idString = input.nextLine();while(!(idString.equals(QUIT))){ ----Code here----- System.out.print("Enter name for employee #" +id + " >> ");name = input.nextLine();System.out.print("Enter pay rate >> ");payRate = input.nextLine();s = idString + delimiter + name + delimiter +payRate + System.getProperty("line.separator");byte[] data = s.getBytes();ByteBuffer buffer = ByteBuffer.wrap(data); ----Code here----- fc.write(buffer);System.out.print("Enter next ID number or " +QUIT + " to quit >> ");idString = input.nextLine();}fc.close();}catch (Exception e){System.out.println("Error message: " + e);}The above program will accept any number of employee records as user input and write the records to a file in a loop. In the first indicated line, create the statement to accept the employee data value from the keyboard as a String and convert it to an integer using the parseInt() method. In the second indicated line, create the statement to compute the record's desired position by multiplying the ID number value by the record sizeimport java.nio.file.*;import java.io.*;import java.nio.channels.FileChannel;import java.nio.ByteBuffer;import static java.nio.file.StandardOpenOption.*;import java.util.Scanner;public class CreateEmployeesRandomFile{public static void main(String[] args){Scanner input = new Scanner(System.in);Path file =Paths.get("C:\\Java\\Chapter.13\\RandomEmployees.txt");String s = "000, ,00.00" +System.getProperty("line.separator");final int RECSIZE = s.length();FileChannel fc = null;String delimiter = ",";String idString;int id;String name;String payRate;final String QUIT = "999";try{fc = (FileChannel)Files.newByteChannel(file, READ, WRITE);System.out.print("Enter employee ID number >> ");idString = input.nextLine();while(!(idString.equals(QUIT))){ ----Code here----- System.out.print("Enter name for employee #" +id + " >> ");name = input.nextLine();System.out.print("Enter pay rate >> ");payRate = input.nextLine();s = idString + delimiter + name + delimiter +payRate + System.getProperty("line.separator");byte[] data = s.getBytes();ByteBuffer buffer = ByteBuffer.wrap(data); ----Code here----- fc.write(buffer);System.out.print("Enter next ID number or " +QUIT + " to quit >> ");idString = input.nextLine();}fc.close();}catch (Exception e){System.out.println("Error message: " + e);}The above program will accept any number of employee records as user input and write the records to a file in a loop. In the first indicated line, create the statement to accept the employee data value from the keyboard as a String and convert it to an integer using the parseInt() method. In the second indicated line, create the statement to compute the record's desired position by multiplying the ID number value by the record size.
id = Integer.parseInt(idString); fc.position(id * RECSIZE);
After an object has been instantiated, its methods can be accessed using the object's _____, a dot, and a method call.
identifier
The simplest statement you can use to make a decision is the ____ statement.
if
Strings and other objects that can't be changed are known as ____.
immutable
____ is a principle of object-oriented programming that describes the encapsulation of method details within a class
implementation hiding
The ____ statement notifies the program that you will be using the data and method names that are part of the imported class or package.
import
A loop controlled by the user is a type of ____ loop.
indefinite
A loop that never ends is called a(n) ____ loop.
infinite
When you employ ____, your data can be altered only by the methods you choose and only in ways that you can control.
information hiding
You are never aware that ____ is taking place; the compiler chooses to use this procedure to save the overhead of calling a method.
inlining
Another name for a nonstatic member class is a(n) ____.
inner class
import java.nio.file.*;import java.io.*;public class ReadFile{public static void main(String[] args){Path file = Paths.get("C:\\Java\\Input.Output\\Grades.txt");InputStream input = null;try{ ----Code here-----------Code here------- String grade = null;grade = reader.readLine();System.out.println(grade);input.close();}catch (IOException e){System.out.println(e);}} }In the code above, a ReadFile class reads from the Grades.txt file. A path is declared, and an InputStream is declared using the Path. In the first indicated line, create the statement to assign a stream to the InputStream reference. In the second indicated line, declare a BufferedReader that reads a line of text from a character-input stream that buffers characters for more efficient reading
input = Files.newInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(input));
import java.nio.file.*;import java.io.*;public class ReadFile{public static void main(String[] args){Path file = Paths.get("C:\\Java\\Input.Output\\Grades.txt");InputStream input = null;try{ ----Code here-----------Code here------- String grade = null;grade = reader.readLine();System.out.println(grade);input.close();}catch (IOException e){System.out.println(e);}} }In the code above, a ReadFile class reads from the Grades.txt file. A path is declared, and an InputStream is declared using the Path. In the first indicated line, create the statement to assign a stream to the InputStream reference. In the second indicated line, declare a BufferedReader that reads a line of text from a character-input stream that buffers characters for more efficient reading.
input = Files.newInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(input));
In Java, you use variables of type ____ to store integers, or whole numbers.
int
In which of the following statements is the value of myVals null?
int [] myVals;
A method can receive ____ arguments, even if it is defined as needing double arguments.
integer
To convert a String to an integer, you use the ____ class, which is part of java.lang and is automatically imported into programs you write.
integer
____ occurs when both of the operands are integers.
integer division
After a successful compile, you can run the class file on any computer that has a ____.
java language interpreter
When you use the BufferedReader class, you must import the ____ package into your program.
java.io
The ____ package contains is implicitly imported into Java programs and is the only automatically imported, named package.
java.lang
If jrStudent is an object of Student, which of the following statements will result in a value of true?
jrStudent instanceof Student
A(n) ____ field is the field in a record that makes the record unique from all others.
key
With a two-dimensional array, the ____ field holds the number of rows in the array.
length
The ____ method returns the length of a String.
length()
A(n) ____ comparison is based on the integer Unicode values of the characters.
lexicographical
A variable declared within a try or catch block is ____ to that block.
local
A(n) ____ variable is known only within the boundaries of the method.
local
The compiler does not take indentation into account when compiling code, but consistent indentation can help readers understand a program's ____.
logic
A ____ is a structure that allows repeated execution of a block of statements.
loop
As long as methods do not depend on one another, ____ is a technique that can improve loop performance by combining two loops into one.
loop fusion
If a compiler detects a violation of language rules, it refuses to translate the class to ____.
machine code
The ____ method executes first in an application, regardless of where you physically place it within its class.
main()
When an application is run, the method that must be executed first must be named ____.
main()
A locally declared variable always ____ another variable with the same name elsewhere in the class.
masks
When mathematicians use a two-dimensional array, they often call it a ____.
matrix
Every object is a _____ of a more general class.
member
When you instantiate an object from a class, ____ is reserved for each instance field in the class.
memory
When using equals and not equals for comparisons with objects, you compare the objects' ____ instead of actual values.
memory addresses
A(n) ____ is a program module that contains a series of statements that carry out a task.
method
Usually, the subclass constructor only needs to initialize the ____ that are specific to the subclass.
methods
When they have the same name, variables within ____ of a class override the class's fields.
methods
When you create a class by making it inherit from another class, the new class automatically contains the data fields and _____ of the original class.
methods
You use a unary minus sign preceding a value to make the value ____.
negative
Statements in which an if structure is contained inside another if structure are commonly called ____ if statements.
nested
The order of the conditional expressions in the following is most important within a(n) ____ loop. while(requestedNum > LIMIT || requestedNum < 0)...
nested
The BufferedWriter class contains a ____ method that uses the current platform's line separator.
newLine()
You can create a writeable file by using the Files class ____ method.
newOutputStream()
When you create an array of objects, each reference is assigned the value ____.
null
When you declare an array name, no computer memory address is assigned to it. Instead, the array variable name has the special value ____, or Unicode value '\u0000'.
null
If a class's only constructor requires an argument, you must provide an argument for every ____ of the class that you create.
object
InputStream and OutputStream are subclasses of the ____ class.
object
String oneStr = "Welcome Jim"String twoStr = "Welcome Joe"Given the lines of code above, which of the following regionMatches() expressions will result in a value of true?
oneStr.regionMatches(0, twoStr, 0, 7)
Regarding enumerations, the ____ method returns an integer that represents the constant's position in the list of constants; as with arrays, the first position is 0.
ordinal
import java.nio.file.*;import java.io.*;import static java.nio.file.StandardOpenOption.*;public class WriteFile{public static void main(String[] args){Path myFile = Paths.get("C:\\Java\\Input.Output\\myNumbers.txt");String nums = "12345";byte[] data = nums.getBytes();OutputStream output = null;try{ -----Code here------ output.write(data)output.flush();output.close();}catch(Exception badNums){System.out.println("My numbers: " + badNums);}}}Using the above code, add a statement on the indicated line that will create a writeable file by constructing a BufferedOutputStream object and assigning it to the OutputStream. No output should appear on the monitor, but a file should be created.
output = new BufferedOutputStream(Files.newOutputStream(file, CREATE));
When you properly ____ a method, you can call it providing different argument lists, and the appropriate version of the method executes.
overload
____ involves using one term to indicate diverse meanings, or writing multiple methods with the same name but with different parameter lists.
overloading
Object-oriented programmers use the term ____ when a child class contains a field or method that has the same name as one in the parent class.
override
Sometimes the superclass data fields and methods are not entirely appropriate for the subclass objects; in these cases, you want to ____ the parent class members.
override
A ____ array is one with the same number of elements as another, and for which the values in corresponding elements are related.
parallel
The Arrays class ____ methods are a new feature in Java 8 that makes sorting more efficient when thousands or millions of objects need to be sorted.
parallelSort
A(n) ____ defines the circumstances under which a class can be accessed and the other classes that have the right to use a class.
parameter
When working with logical operators, you can always use ____ to change precedence.
parentheses
The ____ method takes a String argument and returns its double value.
parseDouble()
____ is the process the compiler uses to divide your source code into meaningful portions; the message means that the compiler was in the process of analyzing the code when the end of the file was encountered prematurely.
parsing
Individual array elements are ____ by value when a copy of the value is made and used within the receiving method.
passed
You can use Java's ____ class to create objects that contain information about files or directories, such as their locations, sizes, creation dates, and whether they even exist.
path
If a programming language does not support ____, the language is not considered object-oriented.
polymorphism
____ describes the feature of languages that allows the same word to be interpreted correctly in different situations based on the context.
polymorphism
Providing values for all the elements in an array is called ____ the array.
populating
When you want to increase a variable's value by exactly 1, use the ____.
prefix increment operator
Before entering a loop, the first input statement, or ____, is retrieved.
priming read
When any ____ type (boolean, char, byte, short, int, long, float, or double) is passed to a method, the value is passed.
primitive
The methods in a subclass can use all of the data fields and methods that belong to its parent, with one exception: ____ members of the parent class are not accessible within a child class's methods.
private
Assigning ____ to a field means that no other classes can access the field's values.
private access
____ are also called modules, methods, functions, and subroutines. Java programmers most frequently use the term "method."
procedures
You would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would achieve this?
protected
{public static void main(String[] args){System.out.println("First Java application");}}Given the above code, which item identifies the access specifier?
public
The method header of the equals() method within the String class is ____.
public boolean equals(String s)
Which of the following statements will create a class named Red that is based on the class Color?
public class Red extends Color
Create a class named Student that contains methods getGPA(), setIDNum(), and setGPA(). Be sure to declare variables and methods appropriately as public or private.
public class Student{ private int idNum; private double gpa; public int getIdNum() { return idNum; } public double getGpa() { return gpa; } public void setIdNum(int num) { idNum = num; } public void setGpa(double gradePoint) { gpa = gradePoint; } }
The true benefit of using a(n) ____ file is the ability to retrieve a specific record from a file directly, without reading through other records to locate the desired one.
random access
A(n) ____ is a series of if statements that determine whether a value falls within a specified range.
range check
When you perform a ____, you compare a value to the endpoints of numerical ranges to find the category in which a value belongs.
range match
____ is an abstract class for reading character streams.
reader
____ applications require that a record be accessed immediately while a client is waiting.
real time
A(n) ____ is a variable that holds a memory address.
reference
Primitive types serve as the building blocks for more complex data types, called ____ types.
reference
The percent sign is the ____ operator.
remainder
The ArrayList class ____ method removes an item from an ArrayList at a specified location.
remove
The ____ method allows you to replace all occurrences of some character within a String.
replace()
After you create an array variable, you still need to ____ memory space.
reserve
A(n) ____ causes a value to be sent from a called method back to the calling method.
return statement
Placing a file in the ____ directory of your storage device is equivalent to tossing a loose document into a drawer.
root
A ____ is an error not detected until the program asks the computer to do something wrong, or even illegal, while executing.
run-time error
Programs would be less clear if you had to account for ____ exceptions in every method declaration.
runtime
The Java compiler does not require that you catch or specify ____ exceptions.
runtime
import java.nio.file.*;import java.io.*;public class ReadEmployeeFile{public static void main(String[] args){Path file =Paths.get("C:\\Java\\Chapter.13\\Employees.txt");String s = "";try{InputStream input = newBufferedInputStream(Files.newInputStream(file));BufferedReader reader = newBufferedReader(new InputStreamReader(input)); -----Code here----- while(s != null){System.out.println(s); -----Code here----- }reader.close();}catch(Exception e){System.out.println("Message: " + e);}} }The above code represents a program that reads an Employees text file. An InputStream is declared for the file, and a BufferedReader is created using the InputStream. On the indicated lines, write a statement that will read the first line into the String. Likewise, in the while statement, write the statement to display the String and read a new line as long as the readLine() method does not return a null value.
s = reader.readLine(); s = reader.readLine();
Comparing a variable to a list of values in an array is a process called ____ an array.
searching
A file channel is ____, meaning you can search for a specific file location and operations can start at any specified position.
seekable
A logical structure called a(n) ____ structure is when one step follows another unconditionally.
sequence
A data file can be used as a(n) ____ file when each record is accessed one after another in the order in which it was stored.
sequential access
The ____ method lets you add characters at a specific location within a StringBuilder object.
setCharAt()
To alter just one character in a StringBuilder, you can use the ____ method, which allows you to change a character at a specified position within a StringBuilder object.
setCharAt()
The compiler determines which version of a method to call by the method's ____.
signature
An array that you can picture as a column of values, and whose elements you can access using one subscript, is a ____ array.
single dimensional
When an expression containing a ____ is part of an if statement, the assignment is illegal.
single equal sign
The ArrayList class ____ method returns the current ArrayList size.
size
The negative integer returned by the binarySearch() method when the value is not found is the negative equivalent of the array ____.
size
When you initialize parallel arrays, it is convenient to use ____ so that the values that correspond to each other visually align on the screen or printed page.
spacing
The String class ____ method accepts an argument that identifies the field delimiter and returns an array of Strings.
split()
In Java, the reserved keyword ____ means that a method is accessible and usable even though no objects of the class exist.
static
It is not necessary to create an instance of the Math class because the constants and methods of the class are ____.
static
public class First{public static void main(String[] args){System.out.println("First Java application");}}Given the above code, which item identifies that the method will work without instantiating an object of the class?
static
Java lets you assign a file to a(n) ____ object so that screen output and file output work in exactly the same manner.
stream
When a numeric variable is concatenated to a String, the entire expression becomes a(n) ____.
string
A(n) ____ is an integer contained within square brackets that indicates one of an array's variables.
subscript
Which of the following statements depicts the valid format to call a superclass constructor from a subclass constructor?
super(name, score);
The ____ statement is useful when you need to test a single variable against a series of exact integer, character, or string values.
switch
Which of the following is NOT a component of a variable declaration statement?
symbolic constant
In a do...while loop, the loop will continue to execute until ____.
the loop control variable is false
You may declare an unlimited number of variables in a statement as long as the variables are ____.
the same data type
The reference to an object that is passed to any object's nonstatic class method is called the ____.
this reference
A(n) ____ statement is one that sends an Exception object to a catch block.
throw
A(n) ____ clause is used in the method header so that applications that use your methods are notified of the potential for an exception.
throws
If a method throws an exception that it will not catch but that will be caught by a different method, you must also use the keyword ____ followed by an Exception type in the method header.
throws
The methods of the Character class that begin with ____ return a character that has been converted to the stated format.
to
The figures above show the HighBalanceException and CustomerAccount classes. Explain what is involved in creating your own throwable Exceptions. Explain what will happen if the CustomerAccount throws a HighBalanceException.
to create your own throwable exception class, you must extend a subclass throwable. throwable has two subclasses exception ad error, which are used to distinguish between recoverable and nonrecoverable errors. Because you always want to create your own exceptions for recoverable errors, your classes should extend the Exception class.The CustomerAccount class uses a HighBalanceException. The CustomerAccount constructor header indicates that it might throw a HighBalanceException (see the first shaded statement); if the balance used as an argument to the constructor exceeds a set limit, a new, unnamed instance of the HighBalanceException class is thrown (see the second shaded statement).
The ____ method converts any object to a String.
toString()
Any of the file input or output methods in a Java program might throw an exception, so all the relevant code in the class is placed in a ____ block.
try
In order to use a variable both with a try or catch block and afterward, you must declare the variable before the ____ block begins.
try
Which of the following describes a data type for which only appropriate behaviors are allowed?
type safe
Each primitive type in Java has a corresponding class contained in the java.lang package. These classes are called ____ classes.
type writer
____ statements are program statements that can never execute under any circumstances.
unreachable
When you declare a variable of a basic, primitive type, such as int x = 10;, the memory address where x is located holds the ____.
value of 10
Besides Double and Integer, other wrapper classes such as Float and Long also provide ____ methods that convert Strings to the wrapper types.
valueOf()
A ____ is a named memory location that you can use to store a value.
variable
When you block statements, you must remember that any ____ you declare within a block is local to that block.
variable
public class First { public static void main(String[] args) { System.out.println("First Java application"); } } Given the above code, which item identifies the method's return type?
void
Use a(n) ____ loop to execute a body of statements continually as long as the Boolean expression that controls entry into the loop continues to be true.
while
An array of bytes can be wrapped, or encompassed, into a ByteBuffer using the ByteBuffer ____ method.
wrap