A step by step process to solve a problem or achieve a goal.
What is an algorithm?
Given an array arr[] of ints {3, 5, 4, 7}, what value is in arr[2]?
What is 4?
These two arguments are used with the overloaded form of the substring method.
What are the starting index and the ending index?
A collection of abstract methods and final static variables.
What is an interface?
What statement produces a random integer from 0 to 50, inclusive? Your statement should store the number in an integer variable, randInt.
What is randInt = (int)(Math.random() * 51);
A run-time error that is thrown to indicate that the index for an array is illegal or outside the range of the array.
What is an ArrayIndexOutOfBoundsException?
Given an ArrayList arr of ints {3, 5, 4, 7, 6, 9, 2}, what statement would be made to return the value "7"?
What is "arr.get(3);"?
If String s1 = "abc"; and if String s2 = new String("abc"); what is the value of the expression if (s1 == s2)?
What is false?
[NOTE: What is the value of if (s1.equals(s2))?]
A cat ____ an animal, A cat ____ a color.
What are Is-a and Has-a?
What statement finds the real-values average of numScores, given that the sum of the scores is an integer, sum? The average should be stored in a double variable, average.
What is
double average = (double) sum / numScores
OR
double average = sum / (double) numScores;?
A method without an implementation that acts as a placeholder.
What is an abstract method?
To get the number of elements in an array, you use ____; to get the number of elements in an ArrayList you use ____. (Make sure to include parentheses where necessary)
What are "length" and "size()"?
"abcdefgh".substring(2, 4)
What is "cd"?
This keyword is used in the declaration of a class when the class is going to use an interface.
What is implements?
Declare a two-dimensional array, mat, that can store 4 rows and 3 columns of boolean values.
What is
boolean[][] mat = new boolean[4][3];
Used in object-oriented programming, this is the mechanism for combining data (variables) and behaviors (methods) into a single unit (a class).
What is encapsulation?
When constructing an ArrayList, you cannot use this type of variable for the ArrayList's type.
What is a primitive variable?
If String s1 = "car"; and if String s2 = "cat"; what is the value of the following expression:
if (s1.compareTo(s2) < 0)
[NOTE: Both the boolean value and the numeric value must be given!]
What is true (-2)?
[114 - 116 = -2 OR 18 - 20 = -2]
[This expression evaluates to true if the left-hand operand ("car") precedes the right-hand operand ("cat") in dictionary order.]
Given that Ship is a class with a default constructor and that Cruiser is a subclass of Ship, what is the declaration in a client class that creates a Ship object, shipObj, whose actual type is a Cruiser?
What is Ship shipObj = new Cruiser();
Suppose an array of ints is to be sorted in decreasing order using the insertion 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?
What is 10, 8, 2, 6, 5, 13?
The insertion sort starts with the 2nd element!
Pass 1: 8, 2, 10, 6, 5, 13
Pass 2: 10, 8, 2, 6, 5, 13
The process whereby the appropriate the appropriate overridden method is called, not during compile time, but during run time for a particular object.
What is dynamic binding?
This is the primary reason one would use an ArrayList over an Array.
What is dynamic resizing? (Or the ability to add elements/remove elements/change size/etc.)
If String s1 = "brouhaha"; then the expression
str.indexOf("ha")
will return what value?
What is 6?
[NOTE: indexOf() returns the index of the first occurrence in the string or -1 if the string is not found.]
If an array, arr, contains 100 Book objects and if the Book class has a getAuthor accessor method, what is the statement that stores in String str the author of the Book object in the first element of arr?
What is String str = arr[0].getAuthor();?
In the worst case, what is the maximum number of comparisons to search an array of 1,000 sorted integers for a given key if the most efficient sorting method is used?
What is 10?
Because the integers are sorted, the most efficient searching algorithm is the binary search. Worst case, the key is not in the list or on an end. Binary search repeatedly cuts the list into two...round up to the nearest power of 2: 1,000 ~ 1,024 = 210