Exam 3 Review Questions

Picture ID is REQUIRED for all exams

Use the list of questions below as a guide when studying for Exam 3. It is by no means a comprehensive list of questions.

You are responsible for all material presented in lecture. You are also responsible for all associated reading assignments and material covered in lab.

Answering the applicable "self-test" questions in each chapter of the text is also a good way to review. The answers to the self-test questions are found at the end of each chapter.

Note the exam 3 is a comprehensive final exam. Although the bulk of the questions will come from the topics covered since exam 2, you should be prepared to answer questions about the important principles and techniques of OOP covered throughout the semester.

For all TRUE/FALSE questions below which are FALSE, explain why.


    I. ArrayList
  1. What are the three main disadvantages of an ArrayList?
  2. What are the main advantages of an ArrayList over an array?
  3. When would it be necessary to use an array rather than an ArrayList?
  4. Inserting an element into the middle of an ArrayList is a relatively slow operation. Explain why this is so.
  5. Write a Java statement to create an ArrayList to hold DoodleBug objects. The initial capacity of the ArrayList should be 25 DoodleBugs.
  6. Describe the operations of the ArrayList methods get(index), add(object), set(index, object), add(index, object)
  7. What potential programming "pitfall" does the ArrayList clone method present?
  8. True/False
  9. An ArrayList object has a fixed size.
  10. You can use any primitive type as the base type of an ArrayList class.
  11. ArrayList objects do not have the array square-bracket notation.
  12. Inheritance is the reason why some parameters of the ArrayList class are of type Base_Type and others of type Object.
  13. The Type parameter is always indicated as a T.
  14. The definition of a "parameterized class" is a class with one or more type parameters.
  15. An ArrayList uses an array to store its elements
  16. II. Generics
    Use the following class definition when answering the questions below.
    public class Utility
    {
       // no instance variables
       
       //.....
    }
    
  17. What attribute(s) of a method make it a candidate to be a generic method of the Utility class?
  18. Write the method header for a generic method named First that returns the the first object from an ArrayList of any base type as it would appear in the Utility class above.
  19. Write a small code snippet (variable declarations and method call) that shows how First would be called from main for an ArrayList of objects of type Bob.
  20. Why is appropriate to use generic programming techniques to implement container classes?
  21. Describe the use of "wildcards" when defining generic classes or methods. In particular, what is the meaning of <?>, <? extends T> and <? super T>? Give an example definition that uses each of these.
  22. Explain why a generic class or method my require its type parameter to implement a particular interface
  23. Write a generic class definition for a class named Box that contains homogeneous data of any type and supports the following operations. The capacity of the Box cannot change. What design decisions must be considered for these Box operations?
    1. Create a new Box. The capacity is specified by the user when the box is created.
    2. Puts an item into the Box
    3. Removes an item from the Box
    4. Tells how many items are in the Box
    5. Empties the box
    6. Given the class definition for Box above

    7. Write a declaration for a Box that holds 10 Integers
    8. Write a declaration for Box that holds 25 XYZ objects

    III. Containers and Iterators
  24. Define "container class" and give two examples from the Java library.
  25. What Java mechanism is used to define containers?
  26. Define iterator. What is the purpose of an iterator?
  27. Explain the advantages of using iterators for containers.
  28. Why are iterators required for some containers?
  29. Given the code fragment below, write a loop using iterators that prints the contents of the ArrayList
        ArrayList<Integer> myList = new ArrayList<Integer>( );
    	
        myList.add( 42 );
        myList.add( 57 );
        myList.add( 95 );
        myList.add( 6 );
        myList.add( 12 );
        myList.add( 105 );
        
         // write your loop here
    
    
  30. What is the output from your loop?
  31. How would the for-loop you wrote in the question above be different if the container were a LinkedList instead of an ArrayList?
  32. Rewrite your loop to print the ArrayList using an "enhanced for-loop".
  33. When is an iterator more appropriate than the "enhanced for-loop"?
  34. Indicate which of the following define an interface and which are concrete classes. For each concrete class, indicate which interface(s) it implements.
    1. Collection<T>
    2. LinkedList<T>
    3. Set<T>
    4. HashSet<T>
    5. TreeSet<T>
    6. ArrayList<T>
    7. List<T>
  35. What is the primary difference between Set<T> and List<T>?
  36. What is the primary difference between ArrayList<T> and LinkedList<T>?
  37. True/False
  38. Some containers handle duplicate elements; others do not
  39. You may instantiate multiple iterators for the same container in the same program/function.
  40. Iterators are created by the container.
  41. The two types of Java containers are Collections and Maps
  42. Java Collection cannot be used to hold primitive types. That's why "wrapper classes" were invented for the primitives.
  43. IV. Swing
  44. Describe "event driven programming". Be sure to define "event source", "event object", "listener" and discuss how these objects interact.
  45. Describe how "event driven programming" is different from the "sequential" programming you've done up until now.
  46. Give an example of event driven programming in the implementation of a GUI implemented using Swing.
  47. What method(s) are defined in the ActionListener interface? What is the purpose of this interface?
  48. What is the purpose of a "layout manager"?
  49. Name three layout managers used in Swing and how they affect the GUI
  50. Define JFrame, JPanel, JButton, JLabel
  51. Describe the steps necessary for an action to take place when a button is pushed in a GUI.
  52. Most Swing objects are derived from the AWT Container class. What advantage(s) does this have for GUI design and implementation?
  53. Although a JPanel is not a visible GUI component, it is probably the most useful Swing container. Explain why this is so.