Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming

Chapter 17

1. 

What’s the purpose of the Java collections framework?

2. 

Into what four primary areas is the Java collections framework organized?

3. 

What are the six core collection interfaces offered in the Java platform version 1.4.2 collections framework?

4. 

Describe the performance characteristics of a linked list.

5. 

Describe the performance characteristics of a hashtable.

6. 

Describe the performance characteristics of a red-black tree.

7. 

What’s the purpose of an Iterator?

8. 

Describe the fundamental differences between the Java 5 collections framework and previous collections framework versions.

9. 

What’s the difference between an Iterator and a ListIterator?

10. 

When would you chose to iterate over the elements of a Java 5 collection using the enhanced for loop vs. an ordinary for loop and an Iterator?

Answers

1. 

- Provides a comprehensive API for collections management. Java developers learn one API and their collection manipulation code is guaranteed to work across deployment platforms.

2. 

- interfaces, implementation classes, algorithms, infrastructure

3. 

-Collection, List, Set, SortedSet, Map, SortedMap

4. 

- List elements can reside anywhere in memory and are accessed via next and previous pointers.

5. 

- Elements are inserted into position according to an object’s hashcode. Object’s with the same hashcode will be appended to a linked list at the element position.

6. 

- A red-black tree is self-sorting and self-balancing. Leaf nodes are always the same number of black nodes away from the root element.

7. 

- Allows you to remove elements from a collection using the remove() method.

8. 

- Java 5 collections introduced generics and several new interface and implementation classes. The enhanced for loop enables you to iterate over a collection without explicitly declaring and using an Iterator.

9. 

- An iterator moves forward through a collection’ s elements; a ListIterator moves forward and backward.

10. 

- When you don’t want to remove elements from the collection.

Категории