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
- What are the three main disadvantages of an ArrayList?
- What are the main advantages of an ArrayList over an array?
- When would it be necessary to use an array rather than an ArrayList?
- Inserting an element into the middle of an ArrayList is a relatively slow operation. Explain why this is so.
- Write a Java statement to create an ArrayList to hold DoodleBug objects. The initial capacity of
the ArrayList should be 25 DoodleBugs.
- Describe the operations of the ArrayList methods
get(index), add(object), set(index, object),
add(index, object)
- What potential programming "pitfall" does the ArrayList
clone
method present?
True/False
- An ArrayList object has a fixed size.
- You can use any primitive type as the base type of an ArrayList class.
- ArrayList objects do not have the array square-bracket notation.
- Inheritance is the reason why some parameters of the ArrayList class are of type Base_Type and others of type Object.
- The Type parameter is always indicated as a T.
- The definition of a "parameterized class" is a class with one or more type parameters.
- An ArrayList uses an array to store its elements
II. Generics
Use the following class definition when answering the questions below.
public class Utility
{
// no instance variables
//.....
}
- What attribute(s) of a method make it a candidate to be a generic method of the Utility class?
- 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.
- 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.
- Why is appropriate to use generic programming techniques to implement container classes?
- 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.
- Explain why a generic class or method my require its type parameter to implement a particular interface
- 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?
- Create a new Box. The capacity is specified by the user when the box is created.
- Puts an item into the Box
- Removes an item from the Box
- Tells how many items are in the Box
- Empties the box
Given the class definition for Box
above
- Write a declaration for a Box that holds 10 Integers
- Write a declaration for Box that holds 25 XYZ objects
III. Containers and Iterators
- Define "container class" and give two examples from the Java library.
- What Java mechanism is used to define containers?
- Define iterator. What is the purpose of an iterator?
- Explain the advantages of using iterators for containers.
- Why are iterators required for some containers?
- 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
- What is the output from your loop?
- How would the for-loop you wrote in the question above be different if the container
were a LinkedList instead of an ArrayList?
- Rewrite your loop to print the ArrayList using an "enhanced for-loop".
- When is an iterator more appropriate than the "enhanced for-loop"?
- Indicate which of the following define an interface and which are concrete classes. For each concrete class, indicate which interface(s) it implements.
- Collection<T>
- LinkedList<T>
- Set<T>
- HashSet<T>
- TreeSet<T>
- ArrayList<T>
- List<T>
- What is the primary difference between Set<T> and List<T>?
- What is the primary difference between ArrayList<T> and LinkedList<T>?
True/False
- Some containers handle duplicate elements; others do not
- You may instantiate multiple iterators for the same container in the same program/function.
- Iterators are created by the container.
- The two types of Java containers are Collections and Maps
- Java Collection cannot be used to hold primitive types. That's why "wrapper classes" were invented for the primitives.
IV. Swing
- Describe "event driven programming". Be sure to define
"event source", "event object", "listener" and discuss how these objects interact.
- Describe how "event driven programming" is different from the "sequential" programming you've done up until now.
- Give an example of event driven programming in the implementation of a GUI implemented using Swing.
- What method(s) are defined in the
ActionListener
interface? What is the purpose of this interface?
- What is the purpose of a "layout manager"?
- Name three layout managers used in Swing and how they affect the GUI
- Define
JFrame, JPanel, JButton, JLabel
- Describe the steps necessary for an action to take place when a button is pushed in a GUI.
- Most Swing objects are derived from the AWT Container class. What advantage(s) does this have
for GUI design and implementation?
- Although a JPanel is not a visible GUI component, it is probably the most useful Swing container.
Explain why this is so.