A primitive data type whose value is true or false. It can be used in the declaration of a variable or as the return type of a method.
boolean
If an array, arr, contains 100 int values, write a statement that store in int n the value of the on-hundredth element of the array.
int n = arr[99];
"catastrophe".substring(4, 5);
"s"
A Java expression that has one of two values: true or false.
Boolean
If sum is an int variable whose value is 12 and if amount is a double variable with value 8, what will be returned by the following statement?
return sum / amount;
1.5
Used in the declaration of a final variable, namely, a variable whose value cannot be changed once it has been assigned.
final
Suppose a double variable, cost, has been initialized. Write a statement that truncates cost to equal the highest integer that is less than or equal to cost and that stores the result in intValue.
int intValue = (int) cost;
The index of the last element in an array with 23 elements.
22
A block of code in a class used to create an object of the class. This code has no return type and cannot be invoked by a direct method call.
constructor
What will be the effect of executing the following code segment, given that int num1 is 0 and int num2 is 10?
if (num 1 / num2 < 0) || (num1 + num2 > 0)
statement1;
else
statement2;
statement1 will be executed
A method or variable that is declared with this word is usable only in the class in which it is declared. This means that it is not accessible to client (outside) classes.
private
Write a statement that finds the real-valued average of numScores scores, given that the sum of the scores is an integer, sum. The average should be stored in a variable called average.
double average = (double) sum / numScores;
13 / 2.0
6.5
This type of method retrieves information from a class object without altering that object.
accessor
This feature of data is used for a binary search but not necessarily for a sequential search.
sorted data
This type of variable or method is shared by all instances of a class, indicating that there is just one memory slot.
static
Write the start of an IF statement that tests whether String s2 is the same reference as String s2.
if (s1 == s2)
or
if (s2 == s1)
13 / 2 + 3
9
A compact piece of code that iterates through all the elements of a collection, always from beginning to end.
OR
for-each loop
If sum is an int variable whose value is 100 and if amount is an int variable with value 0, what will be returned by the following statement?
return sum / amount;
ArithmeticException
Used to indicate that an error has occurred; execution of the program terminates and an error message is printed.
throw
Consider an ArrayList<String>strList, which contains 10 strings. Write a statement that adds the String "cat" to the end of the list.
strList.add("cat");
or
strList.add(10, "cat");
The number of comparisons required in the worst case for a binary search of 32 sorted numbers.
6
An error that occurs during the execution of a program. This error halts the execution of the program and an error-message is given.
run-time error
Suppose an array of int is to be sroted in decreasing order using the selection sort algorithm. If the array originally contains [2, 8, 10, 6, 5, 13], what will the array look like after 2 passes of the sorting loop?
[13, 10, 8, 6, 5, 2]