CPS 181 Review Questions
To read data from a binary file, you create objects from which of the following classes?
FileInputStream and DataInputStream
To write object data to a binary file, you create objects from which of the following classes?
FileOutputStream and DataOutputStream
The call stack is an internal list of all the methods that are currently executing.
True
The recursive binary search algorithm is a good example of repeatedly breaking a problem down into smaller pieces until it is solved.
True
A HashMap ________.
uses hash codes to store keys
Which of the following is true?
Both the Set and List interfaces extend the Collection interface
The recursive case does not require recursion, so it stops the chain of recursive calls.
False
The throws clause causes an exception to be thrown.
False
Whereas a recursive algorithm might result in faster execution time, the programmer might be able to design an iterative algorithm faster.
False
The concrete classes that implement the List interface are ________.
LinkedList and ArrayList
To use recursion for a binary search, what is required before the search can proceed?
The array must be sorted.
The catch clause ________.
The catch clause does all of these
Comparable<T> is ________.
a generic interface defined in the Java class libraries
If you try to add an item to an ArrayList whose size is equal to its capacity ________.
a new ArrayList object with twice the capacity is created, and the elements are moved to this new ArrayList
A file that contains raw binary data is known as a ________.
binary file
The notation <E extends Comparable<E>> ________.
declares a generic type that implements the Comparable interface
The Iterator interface ________.
has next(), hasNext(), and remove() methods
When you write a method that throws a checked exception, you must ________.
have a throws clause in the method header or handle the exception (e.g., using try-catch)
A class is generic ________.
if it has type parameters
Collections ________.
is a class that contains static methods for working with collections
A hashcode of an object ________.
is an integer that can be used to characterize an object and help identify it
Comparable ________.
is an interface implemented by classes that need to impose a natural order on instance objects
A Java collection ________.
is an object that is used as a container for other objects
The enhanced for loop, when used on a collection ________.
is converted by the compiler to a traditional loop that uses an iterator
A collection that does not impose a positional order on its elements, and does not allow duplicates is called a ________.
set
A recursive method must have which of the following?
some way to control the number of time it repeats
One of the advantages of using generics is ________.
that more type problems can be uncovered at compile-time rather than at run time
When a generic method is called ________.
the compiler determines the actual types to use for the type parameters from the context
A class must implement the Serializable interface in order for the objects of the class to be serialized.
True
If the class SerializedClass contains references to objects of other classes as fields, those classes must also implement the Serializable interface in order to be serialized.
True
When an object is serialized, it is converted into a series of bytes that contain the object's data.
True
When you deserialize an object using the readObject method, you must cast the return value to the desired class type.
True