CPSC426 Java EH431

Exercise/Homework EH43

Q1: Stack method ______looks at the top element of a stack without removing that element.

  1. glance.
  2. peek.
  3. look.
  4. sample.

ANS:

Q2: If no elements are in the Stack, method pop throws an ______.

  1. OutOfMemoryError.
  2. OutOfMemoryException.
  3. EmptyStackError.
  4. EmptyStackException.

ANS:

Q3: Which statement is false?

  1. Queue is a new collection interface introduced in J2SE 5.0.
  2. Queue and PriorityQueue are included in the java.util package.
  3. PriorityQueue orders elements in increasing order, so that smallest value will be the first element removed from PriorityQueue.
  4. Queue extends interface Collection.

ANS:

Q4:PriorityQueue method ______inserts an element at the appropriate location in the queue.

  1. offer.
  2. push.
  3. poll.
  4. peek.

ANS:

Q5: ______methods enable a program to view a portion of a collection.

  1. Focus-view.
  2. Range-view.
  3. Delimiter-view.
  4. Subset-view.

ANS:

Q6: Which statement is false?

  1. SortedSet extends Set.
  2. Class SortedSet implements TreeSet.
  3. When a HashSet is constructed, it removes any duplicates in the Collection.
  4. By definition, a Set object does not contain any duplicates.

ANS:

Q7: Maps allocate keys to values and cannot contain duplicate keys, i.e., the key-to-value mapping is a ______mapping.

  1. Many-to-many.
  2. Many-to-one.
  3. One-to-many.
  4. One-to-one.

ANS:

Q8: Which statement about hashing is false?

  1. Hashing facilitates high-speed storing and retrieval of data.
  2. Two different data items can hash to the same cell; this is called a collision.
  3. A load factor of 0.5 usually results in good hashing performance, but less efficient utilization of memory.
  4. A load factor of 1.0 usually results in good hashing performance, but less efficient utilization of memory.

ANS:

Q9: Map method ______is used to determine whether a map contains a mapping for the specified key.

  1. containsKey.
  2. hasKey.
  3. containsMapping.
  4. hasMapping.

ANS:

Q10: A Properties object is a ______Hashtable object.

  1. Transient.
  2. Persistent.
  3. Polymorphic.
  4. Protected.

ANS:

Q11: Most objects in Java can now be output and input with Java's object ______.

  1. Encapsulation.
  2. Overloading.
  3. Serialization.
  4. Reflection.

ANS:

Q12: Which statement is false?

  1. All built-in collections are synchronized.
  2. Concurrent access to a Collection by multiple threads could cause indeterminate results or fatal errors.
  3. To prevent potential threading problems, synchronization wrappers are used around collection classes that might be accessed by multiple threads.
  4. A synchronization wrapper class receives method calls, adds some functionality for thread safety and then delegates the calls to the wrapped class.

ANS:

Q13: Which statement is false?

  1. The Collections API provides a set of publicstaticmethods for converting collections to unmodifiable versions.
  2. Unmodifable wrappers throw ModificationExceptions if attempts are made to modify the collection.
  3. You can use an unmodifiable wrapper to create a collection that offers read-only access to others while allowing read-write access to yourself.
  4. You can create the kind of collection mentioned in part (c) simply by giving others a reference to the unmodifiable wrapper while you also retain a reference to the wrapped collection itself.

ANS:

Q14: The collections framework provides various ______collection interfaces from which the programmer can quickly "flesh out" complete customized implementations.

  1. Abstract.
  2. Concrete.
  3. Structured.
  4. Unstructured.

ANS:

Q15: Which of the following is not an abstract implementation provided by the collections framework?

  1. AbstractCollection.
  2. AbstractTree.
  3. AbstractMap.
  4. AbstractList.

ANS:

Q16: Write a program that uses a StringTokenizer to tokenize a line of text input by the user and places each token in a TreeSet. Print the elements of the TreeSet. [Note: This should cause the elements to be printed in ascending sorted order.]

ANS: