Final Exam
To create a method, you must write its ________.
Definition
A Java program will not compile unless it contains the correct line numbers.
False
All it takes for an AND expression to be true is for one of the subexpressions to be true.
False
In the method header the static method modifier means the method is available to code outside the class.
False
Programs never need more than one path of execution.
False
Which of the following is the not equal operator?
!=
Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000?
((x > 500 && x < 650) || (y != 1000))
Which of the following is not a valid Java comment?
*/ Comment two /*
Which symbol indicates that a member is public in a UML diagram?
+
By default, Java initializes array elements to ________.
0
Java automatically stores a ________ value in all uninitialized static member variables.
0
What would 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
Given the following declaration: enum Tree ( OAK, MAPLE, PINE )What is the ordinal value of the MAPLE enum constant?
1
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 are the tokens in the following code?String str = "123-456-7890";String[] tokens = str.split("-");
123, 456,7890
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
What will be the value of x after the following code is executed? int x, y = 15;x = y--;
15
What will be printed after the following code is executed? for (int number = 5; number <=15; number +=3) System.out.print(number +" , ");
5, 8, 11, 14
Which of the following is not one of the major components of a typical computer system?
All of these are major components
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
In the following code, what values could be read into number to terminate the while loop?Scanner keyboard = new Scanner (System.in);System.out.print ("Enter a number:");int number = keyboard.nextInt () ;while (number < 100 || number > 500){System. out.print ("Enter another number:number = keyboard. nextInt () ;");}
Numbers in the range 100 - 500
Byte code instructions are ________.
Read and interpreted by the JVM
________ operators are used to determine whether a specific relationship exists between two values.
Relational
Which of the following will format 12.78 to display as 12.8%?
System.out.printf("%.1f%%", 12.78);
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.
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.
If you are using characters other than whitespaces as delimiters, you will probably want to trim the string before tokenizing; otherwise, the leading and/or following whitespaces will become part of the first and/or last token.
True
Methods are commonly used to break a problem into small manageable pieces.
True
Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.
True
The System.out.printf method allows you to format output in a variety of ways.
True
In Java, when a character is stored in memory, it is actually the ________ that is stored.
Unicode number
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.
A group of related classes is called a(n) ________.
archive
Because Java byte code is the same on all computers, compiled Java programs ________.
are highly portable
Values stored in local variables ________.
are lost between calls to the method in which they are declared
Values that are sent into a method are called ________.
arguments
In the following statement, what data type must recField be?str.getChars(5, 10, recField, 0);
char[]
Which of the following expressions determines whether the char variable, chrA, is not equal to the letter 'A'?
chrA != 'A'
A(n) ________ can be thought of as a blueprint that can be used to create a type of ________.
class, object
You can concatenate String objects by using the ________.
concat method or the + operator
This String class method returns true if the calling String object contains a specified substring.
contains
In the following code, what values could be read into number to terminate the while loop?Scanner keyboard = new Scanner(System.in);System.out.print("Enter a number: ");int number = keyboard.nextInt();while (number < 100 && number > 500){System.out.print("Enter another number: ");number = keyboard.nextInt();}
Impossible - the boolean condition can never be true
This is an interactive program that lets you enter Java programming statements and immediately see each statement's results.
JShell
Which of the following import statements is required to use the Character wrapper class?
No import statement is required
What would be printed out as a result of the following code?System.out.println("The quick brown fox" +"jumped over the \n""slow moving hen.");
Nothing - this is an error
A class specifies the ________ and ________ that a particular type of object has.
fields, methods
The ________ loop is ideal in situations where the exact number of iterations is known.
for
Which of the following for loops is valid, given the following declaration?String[] names = {"abc", "def", "ghi", "jkl"};
for (int i = 0; i < names.length; i++) System.out.println(names[i].length());
If numbers are a two-dimensional int array that has been initialized and total is an int that has been set to 0, which of the following will sum all the elements in the array?
for (int row = 0; row < numbers.length; row++){for (int col = 0; col < numbers[row].length; col++)total += numbers[row][col];}
A constructor ________.
has the same name as the class
A class whose internal state cannot be changed is known as a(n) ________ class.
immutable
You should not define a class that is dependent on the values of other class fields ________.
in order to avoid having stale data
In Java, you do not use the new operator when you use a(n) ________.
initialization list
Another term for an object of a class is a(n) ________.
instance
Methods that operate on an object's fields are called ________.
instance methods
Assume that the following method header is for a method in class A.public void displayValue(int value)Assume that the following code segments appear in another method, also in class A. Which contains a legal call to the displayValue method?
int x = 7;displayValue(x);
A search algorithm ________.
is used to locate a specific item in a collection of data
This String class method returns true if the calling string's length is 0 or it contains only whitespace characters.
isEmpty
Which of the following will compile a program called ReadIt?
javac ReadIt.java
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
A value that is written into the code of a program is a(n) ________.
literal
A runtime error is usually the result of ________.
logical error
To return an array of long values from a method, which return type should be used for the method?
long[]
Each different type of CPU has its own ________.
machine language
A ________ is a part of a method that contains a collection of statements that are performed when the method is executed.
method body
Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.
methods
A class that provides mutators to change the values of the class's fields is known as a(n) ________ class.
mutable
You can use the ________ method to replace an item at a specific location in an ArrayList.
set
________ works like this: If the expression on the left side of the && operator is false, the expression the right side will not be checked.
short-circuit evaluation
Character literals are enclosed in ________ and string literals are enclosed in ________.
single quotes, double quotes
The scope of a private instance field is ________.
the instance methods of the same class
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
An object typically hides its data but allows outside code access to ________.
the methods that operate on the data
When an object is passed as an argument to a method, what is passed into the method's parameter variable?
the object's memory address
What will be the value of x after the following code is executed? int x = 10; y= 20 while (y < 100) { x+y;}
this is an infinite loop
The process of breaking a string down into tokens is known as ________.
tokenizing
The do-while loop is ideal in situations where you always want the loop to iterate at least once.
true
The primitive data types only allow a(n) ________ to hold a single value.
variable
If a case section in a switch expression has more than one statement, you must use the ________ keyword to return a value from that case section.
yield
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();
Given the following, which of the statements below is not true?str.insert(8, 32);
The insert will start at position 32
What would be the result after the following code is executed? int[] numbers = {40, 3, 5, 7, 8, 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.length; i++)value += numbers[i];
The value variable will contain the sum of all the values in the numbers array.
Given the following code, what will be the value of finalAmount when it is displayed? public class Order{private int orderNum;private double orderAmount;private double orderDiscount;public Order(int orderNumber, double orderAmt,double orderDisc){orderNum = orderNumber;orderAmount = orderAmt;orderDiscount = orderDisc;}public int getOrderAmount(){return orderAmount;}public int getOrderDisc(){return orderDisc;}}public class CustomerOrder{public static void main(String[] args){int ordNum = 1234;double ordAmount = 580.00;double discountPer = .1;Order order;double finalAmount = order.getOrderAmount() —order.getOrderAmount() * order.getOrderDisc();System.out.printf("Final order amount = $%,.2f\n",finalAmount);}}
There is no value because the object order has not been created
Both instance fields and instance methods are associated with a specific instance of a class, and they cannot be used until an instance of the class is created.
True
Constants, variables, and the values of expressions may be passed as arguments to a method.
True
Each byte is assigned a unique number known as an address.
True
If a class has a method named finalize, it is called automatically just before an instance of the class is destroyed by the garbage collector.
True
If the compiler encounters a statement that uses a variable before the variable is declared, an error will result.
True
If the expression on the left side of the && operator is false, the expression on the right side will not be checked.
True
If you are using a recent version of Java, you can specify multiple values in a case statement.
True
If you write a toString method for a class, Java will automatically call the method any time you concatenate an object of the class with a string.
True
If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statements are equivalent:System.out.println(object1);System.out.println(object1.toString());
True
In a switch statement, each of the case values must be unique.
True
Instance methods do not have the keyword static in their headers.
True
Instance methods should be declared static.
True
Java provides a set of simple unary operators designed just for incrementing and decrementing variables.
True
Most of the String comparison methods are case sensitive.
True
Named constants are initialized with a value and that value cannot change during the execution of the program.
True
No statement outside the method in which a parameter variable is declared can access the parameter by its name.
True
Programming style includes techniques for consistently putting spaces and indentation in a program to help create visual cues.
True
StringBuilder objects are not immutable.
True
The Java API provides a class named Math that contains numerous methods which are useful for performing complex mathematical operations.
True
The Java Virtual Machine is a program that reads Java byte code instructions and executes them as they are read.
True
The String class's isBlank method returns true if the calling string's length is 0, or it contains only whitespace characters.
True
The String class's isEmpty method returns true if the length of the calling string is 0.
True
The String class's regionMatches method performs a case-insensitive comparison.
True
The String.format method works exactly like the System.out.printf method, except that it does not display the formatted string on the screen.
True
The System.out.printf method formats a string and displays it in the console window.
True
The expression in a return statement can be any expression that has a value.
True
The if-else statement will execute one group of statements if its boolean expression is true or another group if its boolean expression is false.
True
The java.lang package is automatically imported into all Java programs.
True
The key word this is the name of a reference variable that an object can use to refer to itself.
True
The term "no-arg constructor" is applied to any constructor that does not accept arguments.
True
The wrapper classes in Java are immutable, which means that once you create an object, you cannot change the object's value.
True
Trying to extract more tokens than exist from a StringTokenizer object will cause an error.
True
Two general categories of methods are void methods and value-returning methods.
True
Unicode is an international encoding system that is extensive enough to represent all the characters of all the world's alphabets.
True
When an object is passed as an argument to a method, the object's address is passed into the method's parameter variable.
True
When an object is passed as an argument, it is actually a reference to the object that is passed.
True
When an object reference is passed to a method, the method may change the values in the object.
True
When an object's internal data is hidden from outside code and access to that data is restricted to the object's methods, the data is protected from accidental corruption.
True
When working with the String and StringBuilder classes' getChars method, the character at the start position is included in the substring but the character at the end position is not included.
True
When you call one of the Scanner class's methods to read a primitive value, such as nextInt or nextDouble, and then call the nextLine method to read a string, an annoying and hard-to-find problem can occur.
True
When you open a file with the PrintWriter class, the class can potentially throw an IOException.
True
When you pass the name of a file to the PrintWriter constructor and the file already exists, it will be erased and a new empty file with the same name will be created.
True
Without programmers, the users of computers would have no software, and, without software, computers would not be able to do anything.
True
You can change the contents of a StringBuilder object, but you cannot change the contents of a String object.
True
You must have a return statement in a value-returning method.
True
enum constants have a toString method.
True
A flag may have the values ________.
True or False
What will be displayed after the following code is executed?String str = "RSTUVWXYZ";System.out.println(str.charAt(5));
W
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 ragged array is ________.
a two-dimensional array where the rows have different numbers of columns
In the following code, Math.Pow(a, b) is an example of ________.double a = 2.0, b = 2.0, result;result = Math.pow(a, b) + 1;
a value-returning method
In all but very rare cases, loops must contain, within themselves ________.
a way to terminate
The following statement is an example of ________.import java.util.*;
a wildcard import statement
Local variables can be initialized with ________.
any of these
All @param tags in a method's documentation must ________.
appear after the general description of the method
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);
false
It is common practice to use a ________ variable as a size declarator.
final
The JVM periodically performs the ________ process to remove unreferenced objects from memory.
garbage collection
Which of the following statements determines whether the variable temp is within the range of 0 through 100 (inclusive)?
if (temp >= 0 && temp <= 100)
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);
Which of the following is a valid declaration for a ragged array with five rows but no columns?
int[][] ragged = new int[5][];
A random number, created as an object of the Random class, is always a(n) ________.
integer
A deep copy of an object ________.
is an operation that copies an aggregate object and all the objects that it references
This String class method returns true if the calling string's length is 0, but returns false if the calling string contains only whitespace characters.
isBlank
Each repetition of a loop is known as a(n) ________.
iteration
Which of the following will run the compiled program called ReadIt?
java ReadIt
The ________ package is automatically imported into all Java programs.
java.lang
To compile a program named First you would use which of the following commands?
javac First.java
Each array in Java has a public field named ________ that contains the number of elements in the array.
length
Which is a control structure that causes a statement or group of statements to repeat?
loop
A method ________.
may have zero or more parameters
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
A(n) ________ is a software entity that contains data and procedures.
object
Most of the programming languages used today are ________.
object-oriented
When a field is declared static there will be ________.
only one copy of the field in memory
The lifetime of a method's local variable is ________.
only while the method is executing
Enumerated types have the ________ method which returns the position of an enum constant in the declaration list.
ordinal
Which of the following statements correctly creates a Scanner object for keyboard input?
Scanner keyboard = new Scanner(System.in);
If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?
Str1 == str2
Which of the following statements will convert the double variable, d = 543.98 to a string?
String str = Double.toString(d);
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);
Variables are ________.
Symbolic names made up by the programmer that represents locations in the computer's RAM
Which of the following will format 12.7801 to display as $12.78?
System.out.printf("$%,.2f", 12.7801);
Which of the following statements will display the maximum value that a double can hold?
System.out.println(Double.MAX_VALUE);
When an individual element of an array is passed to a method, ________.
The Method does not have access to the original array
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.
The whole-part relationship created by object aggregation is more often called a(n) ________ relationship.
"has a"
Which of the following is the correct boolean expression to test for: int x being a value less than or equal to 500 or greater than 650, or int y not equal to 1000?
((x <= 500 || x > 650) && !(y == 1000))
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 would 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=0.05;elsediscountRate=0.04;else if (purchase>750)if (cust == 'Y')discountRate=0.04;elsediscountRate=0.03;elsediscountRate=0.0;
0.04
How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x > 100);
1
What is the value of ans after the following code has been executed?int x = 35;int y = 20, ans = 80;if (x < y)ans += y;
100
What would be the value of bonus after the following statements are executed? int bonus, sales = 85000;char dept = 'S';if (sales > 100000)if (dept == 'R')bonus = 2000;elsebonus = 1500;else if (sales > 75000)if (dept == 'R')bonus = 1250;elsebonus = 1000;elsebonus = 0;
1000
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 the value of x[8] after the following code has been executed? final int SUB = 12;int[] x = new int[SUB];int y = 100;for(int i = 0; i < SUB; i++){x[i] = y;y += 10;}
180
What would be the value of x after the following statements were executed? int x = 10; switch (x) { case 10: x += 15; break; case 12: x -= 5; break; default: x *= 3; }
20
What would be the value of bonus after the following statements are executed? int bonus, sales = 1250; if (sales > 1000) bonus = 100; if (sales > 750) bonus = 50; if (sales >500) bonus = 25; else bonus = 0
25
What will be the values of x and y after the following code is executed?int x, y = 15, z = 3;x = (y--) / (++z);
3
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
For the following code, how many times would the for loop execute? String str = ("Ben and Jerry's ice cream is great."); String[] tokens = str.split(" "); for (String s : tokens) System.out.println(s);
7
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
What does the following code display? int d = 9, e = 12; System.out.printf("%d %d ", d, e);
9 12
What are the tokens in the following statement? StringTokenizer st = new StringTokenizer("9-14-2018", "-", true);
9, 14, 2018, -
What is the value of the scores [2][3] in the following array? int [][] scores = { {88, 80, 79, 92}, {75, 84, 93, 80},{98, 95, 92, 94}, {91, 84, 88, 96} };
94
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) ;
= 27, y = 3, z = 18
When writing documentation comments for a method, you can provide a description of each parameter by using a ________.
@param tag
RAM is usually ________.
A volatile type of memory, used only for temporary storage
What will be printed after the following code is executed? String str = "abc456"; int m = 0; while ( m < 6 ) { if (Character.isLetter(str.charAt(m))) System.out.print( Character.toUpperCase(str.charAt(m))); m++; }
ABC
A method that gets a value from a class's field but does not change it is known as a mutator method.
False
Colons are used to indicate the end of a Java statement.
False
Compiled byte code is also called source code.
False
If a class has a method named finalize, it is called automatically just before a data member that has been identified as final of the class is destroyed by the garbage collector.
False
If a non-letter argument is passed to the toLowerCase or toUpperCase method, the boolean value false is returned.
False
If a string has more than one character used as a delimiter, you must write a loop to determine the tokens, one for each delimiter character.
False
If a switch expression is not exhaustive, an error will occur while the program is running.
False
If an immutable class has a mutable object as a field, it is permissible for a method in the immutable class to return a reference to the mutable field.
False
If you use the var keyword to declare a variable, you cannot initialize the variable with a value.
False
In a for loop, the control variable cannot be initialized to a constant value and tested against a constant value.
False
In a for loop, the control variable is always incremented.
False
In the method header, the method modifier public means that the method belongs to the class, not a specific object.
False
Java is not case sensitive.
False
Java source files end with the .class extension.
False
Only constants and variables may be passed as arguments to methods.
False
The Double.parseDouble method converts a double to a string.
False
The String class's valueOf method accepts a string representation as an argument and returns its equivalent integer value.
False
The following statement correctly creates a StringBuilder object. StringBuilder str = "Tuna sandwich";
False
The key word this is the name of a reference variable that is available to all static methods.
False
The names of the enum constants in an enumerated data type must be enclosed in quotation marks.
False
The public access specifier for a field indicates that the field may not be accessed by statements outside the class.
False
The term "default constructor" is applied to the first constructor written by the author of the class.
False
The while loop is always the best choice in situations where the exact number of iterations is known.
False
When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.
False
When testing for character values, the switch statement does not test for the case of the character.
False
When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.
False
When two strings are compared using the String class's compareTo method, the comparison is not case sensitive.
False
You can declare an enumerated data type inside a method.
False
You cannot assign a value to a wrapper class object.
False
A special variable that holds a value being passed into a method is called a(n) ________.
parameter
In the header, the method name is always followed by ________.
parentheses
When you work with a ________, you are using a storage location that holds a piece of data.
primitive variable
All fields in an immutable class should be declared ________.
private and final
The two primary methods of programming in use today are ________.
procedural and object-oriented
Computers can do many different jobs because they are ________.
programmable
A(n) ________ is used to write computer programs.
programming language
Software refers to ________.
programs
A cross between human language and a programming language is called ________.
pseudocode
Which of the following is a correct method header for receiving a two-dimensional array as an argument?
public static void passArray(int[], int[])
Which of the following is not a primitive data type?
string
When the + operator is used with strings, it is known as the ________.
string concatenation operator
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
The Character wrapper class provides numerous methods for ________.
testing and converting character data
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
Internally, the central processing unit (CPU) consists of two parts which are ________.
the control unit and the arithmetic/logic unit (ALU)
The process of breaking a problem down into smaller pieces is sometimes called ________.
the divide and conquer method
A UML diagram does not contain ________.
the object names
When you pass an argument to a method you should be sure that the argument's type is compatible with ________.
the parameter variable's data type
If you attempt to perform an operation with a null reference variable ________.
the program will terminate
To indicate the data type of a variable in a UML diagram, you enter ________.
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
An expression tested by an if statement must evaluate to ________.
true or false
The boolean data type may contain which of the following range of values?
true or false
The boolean expression in an if statement must evaluate to ________.
true or false
Which if the following correctly uses the try-with-resources statement to open a file?
try (PrintWriter outputFile = new PrintWriter("myfile.txt")) { }
The ________ statement is used to automatically close resources, such as files.
try-with-resources
The process of converting a wrapper class object to a primitive type is known as ________.
unboxing
The sequential search algorithm ________.
uses a loop to sequentially step through an array, starting with the first element
What would be the results of the following code? int [ ] array1 = new int[25]; ... // Code that will put values in array1 int value = [0];for (int a = 1; a < array1.length; a++){if (array1[a] < value)value = array1[a];}
value contains the lowest value in array1
What would be the result after the following code is executed? final int SIZE = 25; int[] array1 = new int[SIZE]; ... // Code that will put values in array1 int value = array1[0]; for (int a = 0; a <= array1.length; a++) { if array1[a] < value; { value = array1[a];
value contains the lowest value in array1.
Which type of method performs a task and sends a value back to the code that called it?
value-returning
If you use this keyword to declare a local variable, you do not have to specify the variable's data type.
var
How would you rewrite the following statement using the word var to declare the variable?int value = 99;
var value = 99;
In Java, ________ must be declared before they can be used.
variables
A ________ type of method performs a task and then terminates.
void
Which of the following are pre-test loops?
while, for
The "has a" relationship is sometimes called a(n) ________ because one object is part of a greater whole.
whole-part relationship
The binary search algorithm ________.
will cut the portion of the array being searched in half each time it fails to locate the search value
A partially filled array is normally used ________.
with an accompanying integer value that holds the number of items stored in the array
Given the following code, what will be the value of finalAmount when it is displayed? public class Order{private int orderNum;private double orderAmount;private double orderDiscount;public Order(int orderNumber, double orderAmt,double orderDisc){orderNum = orderNumber;orderAmount = orderAmt;orderDiscount = orderDisc;}public double finalOrderTotal(){return orderAmount - orderAmount *orderDiscount;}}public class CustomerOrder{public static void main(String[] args){Order order;int orderNumber = 1234;double orderAmt = 580.00;double orderDisc = .1;order = new Order(orderNumber, orderAmt, orderDisc);double finalAmount = order.finalOrderTotal();System.out.println("Final order amount = $" +finalAmount);}} 522.00
522.00
What will be the value of x[8] after the following code has been executed? final int SUB = 12;int[] x = new int[SUB];int y = 20;for(int i = 0; i < SUB; i++){x[i] = y;y += 5;}
60
A value-returning method must specify ________ as its return type in the method header.
Any valid data type
The ________ class is the wrapper class for the char data type.
Character
CRC stands for ________.
Class, Responsibilities, Collaborations
If a non-letter is passed to the toLowerCase or toUpperCase method, it is returned unchanged.
True
Which of the following is not true about static methods?
They are called from an instance of the class.
If the following is from the method section of a UML diagram, which of the statements below is true? + add(object2:Stock) : Stock
This is a public method named add that accepts and returns references to objects in the Stock class.
What will the following code display? String str = "a".repeat(3).replace("a", "z").toUpperCase();System.out.println(str);
ZZZ
What would be the results of the following code? int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if(x[2] > x[5]) a = 5; else a = 8;
a = 5
When a method tests an argument and returns a true or false value, it should return ________.
a boolean value
You cannot use the fully-qualified name of an enum constant for ________.
a case expression
A Java program must have at least one of the following:
a class definition
Which of the following is a value that is written into the code of a program?
a literal
Every Java application program must have ________.
a method named main
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 return type is a class, what is actually returned to the calling program?
a reference to an object of that class
After the header, the body of the method appears inside a set of ________.
braces, { }
Methods are commonly used to ________.
break a program down into small manageable pieces
Which of the following is a software entity that contains data and procedures?
an object
Which of the following would contain the translated Java byte code for a program named Demo?
Demo.class
________ refers to combining data and code into a single object.
Encapsulation
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);
Which of the following is not a rule that must be followed when naming identifiers?
Identifiers can contain spaces.
This method converts a string to an int and returns the int value.
Integer.parseInt
What does <String> specify in the following statement? ArrayList<String> nameList = new ArrayList<String>();
It creates an instance of an array of ten long values.
What does <String> specify in the following statement?ArrayList<String> nameList = new ArrayList<String>();
It creates an instance of an array of ten long values.
What does the following statement do?double[] array1 = new double[10];
It does all of these.
Given the following declaration: enum Tree ( OAK, MAPLE, PINE )What is the fully-qualified name of the PINE enum constant?
Tree.PINE
A class is not an object. It is a description of an object.
True
A class's static methods do not operate on the fields that belong to any instance of the class.
True
A constructor is a method that is automatically called when an object is created.
True
A file must always be opened before using it and closed when the program is finished using it.
True
A local variable's scope always ends at the closing brace of the block of code in which it is declared.
True
A parameter variable's scope is the method in which the parameter is declared.
True
A procedure is a set of programming language statements that, together, perform a specific task.
True
A single copy of a class's static field is shared by all instances of the class.
True
A solid-state drive has no moving parts and operates faster than a traditional disk drive.
True
A value-returning method can return a reference to a non-primitive type.
True
All it takes for an OR expression to be true is for one of the subexpressions to be true.
True
An access specifier indicates how a class may be accessed.
True
An enumerated data type is actually a special type of class.
True
An instance of a class does not have to exist in order for values to be stored in a class's static fields.
True
Any method that calls a method with a throws clause in its header must either handle the potential exception or have the same throws clause.
True
Application software refers to programs that make the computer useful to the user.
True
The ________ method is used to insert an item into an ArrayList.
add
Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList?
add
A static field is created by placing the key word static ________.
after the access specifier and before the field's data type
The following statement is an example of ________.import java.util.Scanner;
an explicit import statement
Given the following method header, which of these method calls is incorrect?public void displayValue(double x, int y);
displayValue(a, b); // where a is a short and b is a long
A declaration for an enumerated type begins with the ________ key word.
enum
Variables are classified according to their ________.
data types
When an argument value is passed to a method, the receiving parameter variable is ________.
declared in the method header inside the parentheses
An item that separates other items is known as a ________.
delimiter
The term used for the character that separates tokens is ________.
delimiter
What is the value of str after the following code has been executed?String str;String sourceStr = "Hey diddle, diddle, the cat and the fiddle";str = sourceStr.substring(12,17);
diddl
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 ________ method removes an item from an ArrayList at a specific index.
remove
A(n) ________ is caused by a program not closing its resources.
resource leak
What will be the result after the following code executes?double a = 2.0, b = 2.0, result;result = Math.pow(a, b) + 1;
result will be assigned 5.
Which of the following is not a part of a method call?
return type
When using the String class's trim method, a ________ cannot be trimmed.
semicolon
Which of the following is not part of a method header?
semicolon
A ________ is a value that signals when the end of a list of values has been reached.
sentinel
Given the following method, which of these method calls is valid? public static void showProduct (int num1, double num2){int product;product = num1 * (int)num2;System.out.println("The product is " + product);
showProduct(10, 4.5);
An object's ________ is simply the data that is stored in the object's fields at any given moment.
state
Instance methods do not have the ________ keyword in their headers.
static
what would be the results of executing the following code? StringBuilder str = new StringBuilder ("Little Jack Horner "); str.append("sat on the "); str.append("corner");
str would reference "Little Jack Horner sat on the corner".
Which of the following statements will correctly convert the data type, if x is a float and y is a double?
x = (float)y;
If x has been declared an int, which of the following statements is invalid?
x = 1,000;
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
What would be the result after the following code is executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24};x = y; y = x;
x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
What would be the result after the following code is executed? int[] x = {23, 55, 83, 19};int[] y = {36, 78, 12, 24};x = y;y = x;
x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
When you make a copy of the aggregate object and of the objects that it references, ________.
you are performing a deep copy