xviii PREFACE
if a wrapper-class element appears where a primitive value is needed, unboxing automatically converts
that element to the corresponding primitive value. Finally, the enhanced
for statement—often called a
“for-each” statement—has a sleek structure for iterating through a collection. The net effect of these new
features of Java is to improve productivity by relegating to the compiler many of the “boiler-plate” details
related to casting and iterating.
OTHER IMPLEMENTATIONS CONSIDERED
As important as the Java Collections Framework implementations are, they cannot be the exclusive focus
of such a fundamental course in data structures and algorithms. Approaches that differ from those in the
framework deserve consideration. For example, the
HashMap class utilizes chaining, so there is a separate
section on open addressing, and a discussion of the trade-offs of one design over the other. Also, there is
coverage of data structures (such as a weighted digraph class) and algorithms (such as Heap Sort) that are
not yet included in the Java Collections Framework.
Sometimes, the complexity of the framework classes is mitigated by first introducing simpler
versions of those classes. For example, the
SinglyLinkedList class—not in the Java Collections
Framework—helps to pave the way for the more powerful
LinkedList class, which is in the framework.
And the
BinarySearchTree class prepares students to understand the framework’s TreeMap class,
based on red-black trees.
This text satisfies another important goal of a data structures and algorithms course: Students have the
opportunity to develop their own data structures. There are programming projects in which data structures
are either created “from the ground up” or extended from examples in the chapters. And there are many
other projects to develop or extend applications that use the Java Collections Framework.
JUNIT AND TEST-FIRST DEVELOPMENT
Students realize that methods with no compile-time errors may still be a long way from correct, but they
often need help in learning how to systematically test their methods. As described in Chapter 2, JUnit is
an Open Source platform for the testing of units, that is, methods. For example, to test a
findMedian
method, a FindMedianTest class is developed. The FindMedianTest class consists mainly of methods
that test
findMedian. When all the test methods in FindMedianTest have been passed, the student’s
confidence in the correctness of
findMedian is increased.
Instead of writing the tests after a method has been defined, we employ a “test-first” strategy. As
soon as a method’s specifications have been written, the tests for that method are coded. This ensures
that the tests are based on the specifications only, not on the definition of the method. These tests are run
on a “stub” version of the method to be tested, and all of the tests will fail. Then the method definition
is written, and the tests are run on that version of the method. Corrections to the method are made as
necessary until, eventually, all tests succeed. The test-first paradigm is introduced in Chapter 2 and utilized
in subsequent chapters.
PEDAGOGICAL FEATURES
This text offers several features that may improve the teaching environment for instructors and the learning
environment for students. Each chapter starts with a list of objectives, and most chapters conclude with
several major programming assignments. Each chapter also has a crossword puzzle, from Crossword
www.allitebooks.com