Quiz Questions
For Chapter 12


THIS PAGE CONTAINS A SAMPLE quiz on material from Chapter 12 of this on-line Java textbook. You should be able to answer these questions after studying that chapter. Sample answers to all the quiz questions can be found here.


Question 1: What is meant by generic programming and what is the alternative?

Question 2: Java does not support generic programming with the primitive types. Why not? What is it about generic programming in Java that prevents it from working with primitive types such as int and double.

Question 3: What is an iterator and why are iterators necessary for generic programming?

Question 4: Suppose that integers is a variable of type Collection and that every object in the collection belongs to the wrapper class Integer. Write a code segment that will compute the sum of all the integer values in the collection.

Question 5: Interfaces such as List, Set, and Map define abstract data types. Explain what this means.

Question 6: What is the fundamental property that distinguishes Sets from other types of Collections?

Question 7: What is the essential difference in functionality between a TreeMap and a HashMap?

Question 8: Explain what is meant by a hash code.

Question 9: Modify the following Date class so that it implements the Comparable interface. The ordering on objects of type Date should be the natural, chronological ordering.

      class Date {
         int month;  // Month number in range 1 to 12.
         int day;    // Day number in range 1 to 31.
         int year;   // Year number.
         Date(int m, int d, int y) { // Convenience constructor.
            month = m;
            day = d;
            year = y;
         }
      }

Question 10: Suppose that syllabus is a variable of type TreeMap, the keys in the map are objects belonging to the Date class from the previous problem, and the values are of type String. Write a code segment that will write out the value string for every key that is in the month of September, 2002.


[ Answers | Chapter Index | Main Index ]