0% found this document useful (0 votes)
4 views78 pages

Java Software Solutions For Ap Computer Science 3rd Edition Loftus Download

The document provides information about the book 'Java Software Solutions for AP Computer Science, 3rd Edition' by John Lewis, William Loftus, and Cara Cocking, which aligns with the AP Computer Science curriculum. It outlines updates and enhancements made in this edition, including detailed discussions on primitive types, loop analysis, and testing/debugging. Additionally, it highlights the structure of the book, covering various programming concepts and offering supplementary resources for both students and teachers.

Uploaded by

dieyerabab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views78 pages

Java Software Solutions For Ap Computer Science 3rd Edition Loftus Download

The document provides information about the book 'Java Software Solutions for AP Computer Science, 3rd Edition' by John Lewis, William Loftus, and Cara Cocking, which aligns with the AP Computer Science curriculum. It outlines updates and enhancements made in this edition, including detailed discussions on primitive types, loop analysis, and testing/debugging. Additionally, it highlights the structure of the book, covering various programming concepts and offering supplementary resources for both students and teachers.

Uploaded by

dieyerabab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 78

Java Software Solutions For Ap Computer Science

3rd Edition Loftus download

https://ebookbell.com/product/java-software-solutions-for-ap-
computer-science-3rd-edition-loftus-21354562

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Domaindriven Design With Java A Practitioners Guide Create Simple


Elegant And Valuable Software Solutions For Complex Business Problems
Chandrasekaran

https://ebookbell.com/product/domaindriven-design-with-java-a-
practitioners-guide-create-simple-elegant-and-valuable-software-
solutions-for-complex-business-problems-chandrasekaran-55937292

Java Software Solutions Foundations Of Program Design 7th Edition 7th


Edition John Lewis

https://ebookbell.com/product/java-software-solutions-foundations-of-
program-design-7th-edition-7th-edition-john-lewis-2371348

Java Software Solutions Global Edition 8th Edition John Lewis

https://ebookbell.com/product/java-software-solutions-global-
edition-8th-edition-john-lewis-30066712

Java Software Solutions 9th Edition John Lewis William Loftus

https://ebookbell.com/product/java-software-solutions-9th-edition-
john-lewis-william-loftus-33941204
Java Software Solutions 8th Edition 8th Edition Lewis John

https://ebookbell.com/product/java-software-solutions-8th-edition-8th-
edition-lewis-john-55557960

Java Software Solutions Foundations Of Program Design 4th Edition John


Lewis

https://ebookbell.com/product/java-software-solutions-foundations-of-
program-design-4th-edition-john-lewis-1294350

Java Software And Embedded Systems 1st Edition Mattis Hayes Isaiah
Johansen

https://ebookbell.com/product/java-software-and-embedded-systems-1st-
edition-mattis-hayes-isaiah-johansen-51764284

Java Software Structures Designing And Using Data Structures 4th


Edition International Edition Lewis

https://ebookbell.com/product/java-software-structures-designing-and-
using-data-structures-4th-edition-international-edition-lewis-21976872

Java Software Structures Designing And Using Data Structures 3rd


Edition John Lewis

https://ebookbell.com/product/java-software-structures-designing-and-
using-data-structures-3rd-edition-john-lewis-2614256
J ava 3rd Edition
S O F T WA R E S O L U T I O N S

for AP* Computer Science

*AP and Advanced Placement Program are registered trademarks of The College Board,
which was not involved in the production of, and does not endorse, this product.
This page intentionally left blank
J ava 3rd Edition
S O F T WA R E S O L U T I O N S

for AP* Computer Science

JOHN WILLIAM CARA


LEWIS LOFTUS COCKING

Addison-Wesley
Boston Columbus Indianapolis New York San Francisco Upper Saddle River
Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto
Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo

*AP and Advanced Placement Program are registered trademarks of The College Board,
which was not involved in the production of, and does not endorse, this product.
Editor in Chief: Michael Hirsch
Editorial Assistant: Stephanie Sellinger
Marketing Coordinator: Kathryn Ferranti
Managing Editor: Jeffrey Holcomb
Production Project Manager: Heather McNally
Senior Manufacturing Buyer: Carol Melville
Art Director: Linda Knowles
Cover Designer: Joyce Cosentino Wells
Text Designer: Jerilyn Bockorick, Nesbitt Graphics, Inc.
Cover Art: Michael Shivers / Alamy
Full-Service Project Management: Rose Kernan, Nesbitt Graphics, Inc.
Composition and Art: Nesbitt Graphics, Inc.

Credits and acknowledgments borrowed from other sources and reproduced, with permission, in this textbook appear on appropriate
page within text. Many of the designations by manufacturers and seller to distinguish their products are claimed as trademarks. Where
those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed in initial
caps or all caps.

Microsoft® and Windows® are registered trademarks of the Microsoft Corporation in the U.S.A. and other countries. Screen shots and
icons reprinted with permission from the Microsoft Corporation. This book is not sponsored or endorsed by or affiliated with the
Microsoft Corporation.

The programs and applications presented in this book have been included for their instructional value. They have been tested with care,
but are not guaranteed for any particular purpose. The publisher does not offer any warranties or representations, nor does it accept
any liabilities with respect to the programs or applications.

Copyright © 2011, 2007, 2004 Pearson Education, Inc., publishing as Addison-Wesley, 501 Boylston Street, Suite 900, Boston,
Massachusetts 02116. All rights reserved. Manufactured in the United States of America. This publication is protected by Copyright,
and permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmis-
sion in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission(s) to use material
from this work, please submit a written request to Pearson Education, Inc., Permissions Department, 501 Boylston Street, Suite 900,
Boston, Massachusetts 02116.

Library of Congress Cataloging-in-Publication Data


Lewis, John, 1963-
Java software solutions for AP computer science / John Lewis, William
Loftus, Cara Cocking. -- 3rd ed.
p. cm.
ISBN 0-13-137469-9
1. Java (Computer program language) 2. Electronic data processing--Study
and teaching (Secondary) I. Loftus, William. II. Cocking, Cara. III. Title.
QA76.73.J38L4885 2011
005.13'3076--dc22
2009050911

1 2 3 4 5 6 7 8 9 10--CRK--14 13 12 11 10

ISBN 10: 0-13-137469-9


www.pearsonhighered.com ISBN 13: 978-0-13-137469-0

*AP and Advanced Placement Program are registered trademarks of The College Board,
which was not involved in the production of, and does not endorse, this product.
To Sharon, Justin, Kayla, Nathan, and Samantha Lewis

—J.L.

To Veena, Isaac, and Devi Loftus

—W.L.

To Richard and Doris Cocking

—C.C.
This page intentionally left blank
Preface
Welcome to Java™ Software Solutions for AP* Computer Science. This
Advanced Placement* book matches both the AP* Computer Science topic
outline and Java subset set forth by the College Board.

What’s New in This Edition


We have been pleased to hear that this book has met and exceeded the
needs of many instructors of AP* Computer Science courses. We appreciate
your feedback and suggestions.
This third edition of Java Software Solutions for AP* Computer Science
has been updated to ensure that the most recent requirements for the
Advanced Placement test have been thoroughly covered. In addition, the
flow and discussion of certain topics have been improved and updated.
The specific changes include:
■ The coverage of primitive types in Chapter 2 now provides more
detail of internal representation and a discussion of imprecision and
round-off error.
■ An appendix has been added covering number systems and examples
of conversions between bases.
■ A discussion of the Integer.MAX_VALUE and Integer.MIN_VALUE con-
stants is now part of the Chapter 2 coverage of wrapper classes.
■ The Math.random method is discussed in more detail in Chapter 2 as
an alternative to using the Random class.
■ Chapter 3 now includes a discussion of loop analysis.
■ A new section in Chapter 5 covers Testing and Debugging.
■ End-of-chapter exercises have been updated to reflect the modified
and new material.

About This AP* Book


This book has been specifically designed to meet the needs of today’s AP*
students and AP* teachers. Let’s hit the highlights. Specifically:
■ Online sections for most chapters tie the official AP* case study in
with the concepts covered in that chapter. This material is available
on the book’s Web site.
*AP and Advanced Placement Program are registered trademarks of The College Board,
which was not involved in the production of, and does not endorse, this product. vii
viii PR EFA C E

■ The discussion and examples fully embrace the Java 2 Standard


Edition, Version 6.0.
■ We utilize hundreds of example programs, fully implemented for
experimentation by AP* students and AP* teachers.
■ Graphics are covered in an optional section (called Graphics Track) at
the end of each chapter. Building on the excitement of the Web, the
Graphics Track is intended to further inspire and engage AP* students.
■ The Self-Review Questions, Exercises, and Programming Projects have
been specifically designed to adhere to various learning styles, includ-
ing multiple choice, true/false, and short-answer questions.
■ The reference material in the appendices includes: Glossary, Unicode
Character Set, Java Operators, and Number Systems.
■ A robust ancillary package accompanies this book and is outlined fur-
ther in this preface.
■ The full-color design aids learning by making it easier to distinguish
between various elements in code and diagrams. Full-color screen shots
make the discussions of graphical interfaces more insightful and realistic.

Cornerstones of the Text


This text is based on the following basic ideas that we believe make for a
sound introductory text:
■ True object-orientation. A text that really teaches a solid object-oriented
approach must use what we call object-speak. That is, all processing
should be discussed in object-oriented terms. That does not mean,
however, that the first program an AP* student sees must discuss the
writing of multiple classes and methods. An AP* student should learn
to use objects before learning to write them. This text uses a natural
progression that culminates in the ability to design real object-oriented
solutions.
■ Sound programming practices. AP* students should not be taught
how to program; they should be taught how to write good software.
There’s a difference. Writing software is not a set of cookbook
actions, and a good program is more than a collection of state-
ments. This text integrates practices that serve as the foundation of
good programming skills. These practices are used in all examples
and are reinforced in the discussions. AP* students learn how to
solve problems as well as how to implement solutions. We introduce
and integrate basic software engineering techniques throughout the
text.
■ Examples. AP* students learn by example. This text is filled with fully
implemented examples that demonstrate specific concepts. We have
P REFAC E ix

intertwined small, readily understandable examples with larger, more


realistic ones. There is a balance between graphics and nongraphical
programs and between applets and applications.
■ Graphics and GUIs. Graphics can be a great motivator for AP* students,
and their use can serve as excellent examples of object-orientation. As
such, we use them throughout the text in a well defined set of sections
that we call the Graphics Track. This coverage includes the use of event
processing and graphical user interfaces (GUIs). AP* students learn to
build GUIs in the appropriate way by using a natural progression of
topics. The Graphics Track can be avoided entirely for those who do
not choose to use graphics.

Chapter Breakdown
Chapter 1 (Computer Systems) introduces computer systems in general,
including basic architecture and hardware, networking, programming, and
language translation. Java is introduced in this chapter, and the basics of pro-
gram development are discussed. This chapter contains broad introductory
material that can be covered while AP* students become familiar with their
development environment.
Chapter 2 (Objects and Primitive Data) establishes the concept of objects
and how they can be used. Many predefined classes from the Java standard
library are explored and used. Enumerated types, primitive types, operators,
and expressions are also explored.
Chapter 3 (Program Statements) covers most of the fundamental state-
ments including conditionals, loops, and iterators. Some additional operators
are introduced at this point as well. Establishing key statements at this point
allows the classes of the next chapter to be fully functional and realistic.
Chapter 4 (Writing Classes) explores issues related to writing classes and
methods. Topics include instance data, visibility, scope, method parameters,
and return types. Method overloading is covered as well. Some of the more
involved topics are deferred to or revisited in Chapter 5. The key to Chapter
4 is the many fully implemented, realistic classes that are presented as exam-
ples of class design.
Chapter 5 (Enhancing Classes) covers additional issues related to class
design and revisits topics that need further exploration. Object references are
revisited and carefully explored, and their impact on parameter passing is
discussed. Exceptions, interfaces, and their effect on design are also covered.
Finally, guidelines on designing classes, as well as testing, are given.
Chapter 6 (Arrays) contains extensive coverage of arrays and array pro-
cessing. Topics include multidimensional arrays, searching, and sorting.
The ArrayList class is explored as well, and generic types are introduced
here.
x PR EFA C E

Chapter 7 (Inheritance) covers class derivations and associated concepts


such as class hierarchies, overriding, and polymorphism. Emphasis is put on
the proper use of inheritance and its role in software design.
Chapter 8 (Recursion) covers the concept, implementation, and proper use
of recursion. Several examples from various domains are used to demon-
strate how recursive techniques make certain types of processing elegant.
Recursive sorting algorithms are also covered.
Chapter 9 (Linear Data Structures) introduces the idea of a collection and
its underlying data structure. Abstraction is revisited in this context and the
linked list, queue, and stack data structures are explored.
Chapter 10 (Non-linear Data Structures) further explores dynamic data
structures, including trees and heaps. Sets and maps are also introduced and
hashtables are revisited.

Supplements
AP* students are welcome to visit www.pearsonhighered.com/cssupport
(author: Lewis/Loftus/Cocking) for the following resources:
■ Source Code to all program examples in the text.
■ Case Study section for most chapters linking the concepts covered in
that chapter with the official AP* case study.
The following supplements are available online for qualified AP* teachers
only, at www.pearsonhighered.com/irc. Teachers may obtain a code to access
the supplements below from their Pearson sales representative. If you need
help finding this material, contact your Pearson sales representative. You can
find your rep in the “Find your sales rep” section atwww.pearsonschool.com.
■ Lesson Plans with Pacing Guide.
■ Solutions to all end-of-chapter exercises and programming projects.
■ PowerPoint slides.
■ Test Bank with powerful test generator software, includes a wealth of
free response, multiple choice, and true/false questions.
■ Source Code to all program examples in the text.

AP* Correlation Guide


On the next page, we present the AP* Computer Science correlation guide as
given by the College Board. The column on the right shows the sections of
this book where each topic is covered.
P REFAC E xi

AP* Computer Science Topics Sections Where Taught


I. OBJECT-ORIENTED PROGRAM DESIGN
The overall goal for designing a piece of software (a computer program) is to correctly solve the given
problem. At the same time, this goal should encompass specifying and designing a program that is
understandable, can be adapted to changing circumstances, and has the potential to be reused in
whole or in part. The design process needs to be based on a thorough understanding of the problem
to be solved.
A. Program design
1. Read and understand a problem Sections 1.3, 3.0, 3.7
description, purpose, and goals.
2. Apply data abstraction and encapsulation. Sections 2.1, 4.1, 7.7
3. Read and understand class specifications Sections 4.5, 7.0
and relationships among the classes
(“is-a,” “has-a” relationships).
4. Understand and implement a given class Sections 7.0, 7.2
hierarchy.
5. Identify reusable components from existing Sections 2.0, 7.4
code using classes and class libraries.
B. Class design
1. Design and implement a class. Sections 4.0–4.4, 5.0, 5.1, 5.4
2. Choose appropriate data representation Sections 3.7, 5.4
and algorithms.
3. Apply functional decomposition. Sections 4.2, 4.4
4. Extend a given class using inheritance. Sections 7.0, 7.1, 7.3, 7.4

II. PROGRAM IMPLEMENTATION


The overall goals for program implementation parallel those of program design. Classes that fill com-
mon needs should be built so that they can be reused easily in other programs. Object-oriented
design is an important part of program implementation.
A. Implementing techniques
1. Methodology
a. Object-oriented development Section 2.0
b. Top-down development Section 3.0
c. Encapsulation and information hiding Section 4.1
d. Procedural abstraction Section 4.2
B. Programming constructs
1. Primitive types vs. objects Sections 2.0, 2.1, 2.4
2. Declaration
a. Constant declarations Section 2.3
b. Variable declarations Section 2.3
c. Class declarations Section 4.1
d. Interface declarations Section 5.3
e. Method declarations Section 4.2
f. Parameter declarations Section 4.2
3. Console output (System.out.print/println) Section 2.1
4. Control
a. Methods Section 4.2
b. Sequential Section 3.1
c. Conditional Section 3.2
d. Iteration Sections 3.5, 3.6
e. Understand and evaluate recursive methods Sections 8.0–8.2
xii PR EFA C E

AP* Computer Science Topics Sections Where Taught


C. Java library classes (included in the A-level AP* Java Subset)
Object Section 7.2
Comparable Section 5.3
Integer Section 2.7
Double Section 2.7
String Section 2.7
Math Section 2.8
Random Section 2.8
ArrayList Section 6.7
III. PROGRAM ANALYSIS
The analysis of programs includes examining and testing programs to determine whether they cor-
rectly meet their specifications. It also includes the analysis of programs or algorithms in order to
understand their time and space requirements when applied to different data sets.
A. Testing
1. Test classes and libraries in isolation Section 5.4
2. Identify boundary cases and generate Section 5.4
appropriate test data
3. Perform integration testing Section 5.4
B. Debugging
1. Categorize errors: compile-time, run-time, logic Section 1.4
2. Identify and correct errors Sections 1.4, 5.4
3. Techniques: use a debugger, add extra output Sections 1.4, 5.4
statements, hand-trace code
C. Understand and modify existing code Learned throughout the text
D. Extend existing code using inheritance Sections 7.0, 7.1, 7.3, 7.4
E. Understand error handling
1. Understand runtime exceptions Section 5.2
F. Reason about programs
1. Pre- and post-conditions Section 4.2
2. Assertions Section 4.2
G. Analysis of algorithms
1. Informal comparisons of running times Sections 6.2, 6.4
2. Exact calculation of statement execution Sections 6.2, 6.4
counts
H. Numerical representations and limits
1. Representations of numbers in different bases Section 1.0, Appendix E
2. Limitations of finite representations Sections 2.4, 3.3
(e.g., integer bounds, imprecision of floating-point
representations, and round-off error)
IV. STANDARD DATA STRUCTURES
Data structures are used to represent information within a program. Abstraction is an important
theme in the development and application of data structures.
A. Simple data types (int, boolean, double) Section 2.4
B. Classes Sections 2.0, 4.1
P REFAC E xiii

AP* Computer Science Topics Sections Where Taught


C. Lists Sections 6.7, 9.0–9.1
D. Arrays Sections 6.0, 6.1

V. STANDARD ALGORITHMS

Standard algorithms serve as examples of good solutions to standard problems. Many are inter-
twined with standard data structures. These algorithms provide examples for analysis of program effi-
ciency.
A. Operations on data structures previously listed
1. Traversals Sections 6.0, 6.1, 6.7
2. Insertions Sections 6.0, 6.1, 6.7
3. Deletions Sections 6.0, 6.1, 6.7
B. Searching
1. Sequential Section 6.2
2. Binary Section 6.2
C. Sorting
1. Selection Section 6.3
2. Insertion Section 6.3
3. Mergesort Section 8.3

VI. COMPUTING IN CONTEXT

An awareness of the ethical and social implications of computing systems is necessary for the study
of computer science. These topics need not be covered in detail but should be considered through-
out the course.
A. System reliability Appendix F
B. Privacy Appendix F
C. Legal issues and intellectual property Appendix F
D. Social and ethical ramifications of computer use Appendix F

Acknowledgments
We are most grateful to the AP* teachers and AP* students from around the
world who have provided their feedback on the previous edition of this book.
We are pleased to see the depth of the faculty’s concern for their AP* students
and the AP* students’ thirst for knowledge. Your comments and questions
are always welcome.
Michael Hirsch and Stephanie Sellinger, our editors at Addison-Wesley,
went above and beyond the call of duty to ensure that the book met the high-
est quality standards. Their support and enthusiasm are greatly appreciated.
We are also grateful to Andrea Sheehan and Courtney Marsh with Pearson
School for making sure that AP* teachers understand the pedagogical advan-
tages of this text. The devotion that the Addison-Wesley and Pearson folks
show to their books is evident in the high-quality results.
xiv PR EFA C E

The production team for this edition is a group of gifted and hard-working
people—miracle workers all. Thanks go to Heather McNally, Joyce
Cosentino Wells (for the wonderful cover), and Rose Kernan and the rest of
the Nesbitt Graphics group. The quality of the book is due largely to their
personal attention, and it is greatly appreciated.
Special thanks also go to the reviewers of this text over the last few edi-
tions, as well as the many other instructors and friends who have provided
valuable feedback.
They include Neil Ascione—Wayne Valley High School, NJ; Brian Ellis—
Manheim Township School District, PA; Kathy Gilbert—Cary-Grove High
School, IL; Gregory King—Dublin Coffman High School, OH; Richard
Lamb—Cranbrook High School, MI; Deepa Muralidhar—Northview High
School, GA; Kim Murphy—Weber High School, UT; G. Lynne Ryan—North
Crowley High School, TXJenka Guevara, American School Foundation,
Mexico City; Leigh Ann Sudol, Fox Lane High School/New York University,
NY; Kathleen Weaver, Hillcrest High School, Dallas, TX; John E. Hanna,
Teaneck High School, NJ; Brian G. Scarbeau, Lake Highland Preparatory
School, FL; Frances Caruso Wolanczyk, Fieldston School, NY; Mark
Hanington, Punahou School, Honolulu, HI; Rose M. Hoffman, Catholic
Memorial High School, Waukesha, WI; Kathleen Larson, Kingston High
School, Kingston, NY; Bob Beck, Villanova University; Paul Gormley,
Villanova University; Cathy Helwig, Villanova University; Dan Joyce,
Villanova University; Najib Nadi, Villanova University; Beth Taddei,
Villanova University; Barbara Zimmerman, Villanova University; John
Simms, Marquette University; Marian Manyo, Marquette University.
Most importantly, we thank our families for their support during the busy
process of writing, not to mention the other times.
Feature Walkthrough
Key Concepts. Throughout the
2.1 Computer Processing 63
text, the Key Concept boxes high-
disk. When you instruct the computer to execute your program, a
light fundamental ideas and
KEY C ON C EPT
copy of the program is brought in from secondary memory and
stored in main memory. The CPU reads the individual program
The CPU reads the program important guidelines. These con-
instructions from main memory,
instructions from main memory. The CPU then executes the instruc-
tions one at a time until the program ends. The data that the instruc-
executing them one at a time
until the program ends. cepts are summarized at the end
tions use, such as two numbers that will be added together, are also
stored in main memory.
of each chapter.
The process of executing a program is fundamental to the operation of a
computer. All computer systems basically work in the same way.

Listings. All programming exam-


66 C H A P TE R 2 Data and Expressions
ples are presented in clearly
labeled listings, followed by the
L I S T I N G 2 . 2
program output, a sample run, or
screen shot display as appropri- //********************************************************************
// Roses.java Author: Lewis/Loftus
//
ate. The code is colored to visu- // Demonstrates the use of escape sequences.
//********************************************************************

ally distinguish comments and public class Roses


{
reserved words. //-----------------------------------------------------------------
// Prints a poem (of sorts) on multiple lines.
//-----------------------------------------------------------------
public static void main (String[] args)
{
System.out.println ("Roses are red,\n\tViolets are blue,\n" +
"Sugar is sweet,\n\tBut I have \"commitment issues\",\n\t" +
"So I'd rather just be friends\n\tAt this point in our " +
"relationship.");
}
}

O U T P U T

Roses are red,


Violets are blue,
Sugar is sweet,
But I have "commitment issues",
So I'd rather just be friends
At this point in our relationship.

xv
xvi F EAT U R E WALKTHRO UG H

Syntax Diagrams. At appropriate


Local Variable Declaration points in the text, syntactic ele-
Type Variable Declarator
ments of the Java language are
final
,
discussed in special highlighted
sections with diagrams that
Variable Declarator
clearly identify the valid forms for
Identifier a statement or construct.
= Expression
Array Initializer

A variable declaration consists of a Type followed by a list of


variables. Each variable can be initialized in the declaration to the
value of the specified Expression. If the final modifier precedes the
declaration, the identifiers are declared as named constants whose

Graphics Track. All processing


that involves graphics and graphi- 2.7
GRAPHICS TRACK

Graphics
cal user interfaces is discussed in K EY C ON C EPT
Graphics play a crucial role in computer systems. Throughout
this book we explore various aspects of graphics and discuss
one or two sections at the end of Graphical data is represented by
dividing it into many small pieces how they are accomplished. In fact, the last one or two sec-
called pixels. tions of each chapter are devoted to graphics topics. We refer
each chapter that we collectively to this as the Graphics Track through the book. These sections
can be skipped without losing continuity through the rest of the text, incor-
refer to as the Graphics Track. This porated into the regular flow of the chapters, or explored as a group.
A picture, like all other information stored on a computer, must be digi-
material can be skipped without tized by breaking the information into pieces and representing those pieces as
numbers. In the case of pictures, we break the picture into pixels (picture ele-
loss of continuity, or focused on ments). A pixel is a tiny region that represents a very small piece of the pic-
ture. The complete picture is stored by storing the color of each individual
specifically as desired. The mate- pixel.

rial in any Graphics Track section A digitized picture can be reproduced when needed by reassembling its
pixels. The more pixels used to represent a picture, the more realistic it looks
relates to the main topics of the when it is reproduced. The number of pixels used to represent a picture is
called the picture resolution. The number of pixels that can be displayed by
chapter in which it is found. a monitor is called the monitor resolution. A black and white picture can be
stored by representing each pixel using a single bit. If the bit is 0, that pixel
Graphics Track sections are indi- is white; if the bit is 1, it is black. Figure 2.8 shows a black and white picture
that has been stored digitally and an enlargement of a portion of that picture,
cated by a light blue border on which shows the individual pixels.
Graphics play a crucial role in computer systems. Throughout this book
the edge of the page. we explore various aspects of graphics and discuss how they are accom-
plished. In fact, the last one or two sections of each chapter are devoted to
graphics topics. We refer to this as the Graphics Track through the book.
F EAT U RE WALK T H RO U G H xvii

AP* Case Study. The case study


270 CHAP TE R 2 Data and Expressions
sections apply concepts from
the text to the AP* Case Study
AP* Case Study
that students need to study for
To work with the AP* Case Study section for this chapter, go to
www.aw.com/cssupport and look under author: Lewis/Loftus/Cocking. the AP* Exam. The case study
sections can be found at
www.aw.com/cssupport under
author: Lewis/Loftus/Cocking.

Summary of Key Concepts. The


276 C H A P TE R 2 Data and Expressions
Key Concepts presented through-
out a chapter are summarized at
Summary of Key Concepts
the end of the chapter.
■ The information we manage in a Java program is either primitive data
or objects.
■ An abstraction hides details. A good abstraction hides the right details
at the right time.
■ A variable is a name for a memory location used to hold a value.
■ A variable can store only one value of its declared type.
■ Java is a strongly typed language. Each variable has a specific type,
and we cannot assign a value of one type to a variable of another
type.
■ Constants are like variables, but they have the same value throughout
the program.
■ Java has two kinds of numeric values: integers and floating point. The
primitive type int is an integer data type and double is a floating
point data type.
■ Expressions are combinations of one or more operands and the opera-
tors used to perform a calculation.
■ Java has rules that govern the order in which operators will be evalu-
ated in an expression. These rules are called operator precedence rules.
■ Avoid narrowing conversions because they can lose information.

Self-Review Questions and


Self-Review Questions
2.1 What are the primary concepts that support object-oriented pro- Answers. These short-answer
gramming?
2.2 Why is an object an example of abstraction?
questions review the fundamental
2.3 What is primitive data? How are primitive data types different ideas and terms established in the
from objects?
2.4 What is a string literal? chapter. They are designed to
2.5 What is the difference between the print and println methods?
allow students to assess their own
basic grasp of the material. The
answers to these questions can be
Answers to Self-Review Questions
found at the end of the problem
2.1 The main elements that support object-oriented programming are sets.
objects, classes, encapsulation, and inheritance. An object is
defined by a class, which contains methods that define the opera-
tions on those objects (the services that they perform). Objects
store and manage their own data. Inheritance is a technique in
which one class can be created from another.
2.2 An object is abstract because the details of the object are hidden
from, and largely unimportant to, the user of the object. Hidden
details help us manage the complexity of software.
xviii F EAT U R E WALKTHRO UG H

Exercises. The multiple choice,


Short Answer
7.1 Draw an inheritance hierarchy containing classes that represent true/false, and short answer exercises
different types of clocks. Show the variables and method names
for two of these classes. at the end of every chapter are
7.2 Show another diagram for the hierarchy in Exercise 7.1. Explain
why it may be better or worse than the original.
designed to develop and test the stu-
7.3 Draw a class hierarchy for types of teachers at a high school. dents’ knowledge of that chapter’s
Show what characteristics would be represented in the various
classes of the hierarchy. Explain how polymorphism could play a material. These exercises generally do
role in assigning courses to each teacher.
not require the use of a computer.

Programming Projects. These problems Programming Projects


require the design and implementation 8.1 Design and implement a recursive version of the PalindromeTester
program from (Listing 3.9) Chapter 3.
of Java programs. They vary widely in 8.2 Design and implement a program for finding the greatest common
divisor of two positive numbers using Euclid’s algorithm. The
level of difficulty. greatest common divisor is the largest number that divides both
numbers without producing a remainder. An iterative version of
this method was part of the Rational class presented in Chapter 4.
In a class called DivisorCalc, define a static method called gcd
that accepts two integers, num1 and num2. Create a driver to test
your implementation. The recursive algorithm is defined as follows:
a. gcd (num1, num2) is num2 if num2 <= num1 and num2
divides num1
b. gcd (num1, num2) is gcd (num2, num1) if num1 < num2
c. gcd (num1, num2) is gcd (num2, num1%num2) otherwise
8.3 Modify the Maze class (Listing 8.2) so that it prints out the path of
the final solution as it is discovered, without storing it.
8.4 Design and implement a program that solves a 3D maze.

AP*-Style Questions. These questions


AP*-Style Multiple Choice
3.1 Consider the following output. are modeled after the multiple choice
10 9 8 7 6 5 4 3 2 1
Which of the following loops will produce this output?
and free response questions on the AP*
(A) for (int i = 0; i < 10; i--) Exam. They are designed to help
System.out.print(i + " ");
(B) for (int i = 10; i >= 0; i--) students apply material from each
System.out.print(i + " ");
chapter to the types of questions they
(C) for (int i = 0; i <= 10; i++)
System.out.print((10 – i) + " "); will encounter on the AP* Exam.
(D) for (int i = 0; i < 10; i++)
System.out.print((10 – i) + " ");
(E) for (int i = 10; i > 0; i--)
System.out.print((10 – i) + " ");

AP*-Style Free Response


5.1 Consider the following incomplete declaration of a Name class.

public class Name something missing


{
private String first;
private String last;

public Name(String firstName, String lastName)


{
first = firstName;
last = lastName;
}
Contents

Preface vii

AP* Correlation Guide xi

Chapter 1 Computer Systems 1


1.0 Introduction 2
Basic Computer Processing 2
Software Categories 3
Digital Computers 5
Binary Numbers 6
1.1 Hardware Components 9
Computer Architecture 9
Input/Output Devices 11
Main Memory and Secondary Memory 11
The Central Processing Unit 15
1.2 Networks 16
Network Connections 17
Local-area Networks and Wide-area Networks 18
The Internet 19
The World Wide Web 20
Uniform Resource Locators 22
The Internet vs. The World Wide Web 22
1.3 Programming 22
Problem Solving 23
The Java Programming Language 23
A Java Program 24
Comments 26
Identifiers and Reserved Words 27
White Space 30
1.4 Programming Languages 31
Programming Language Levels 32
Compilers and Interpreters 34
Syntax and Semantics 36
Errors 37
Language Evolution 38

xix
xx CONTENTS

1.5 Graphics 38
Coordinate Systems 38
Representing Color 40

Chapter 2 Objects and Primitive Data 51


2.0 An Introduction to objects 52

2.1 Using Objects 54


The print and println Methods 55
Abstraction 56

2.2 String Literals 57


String Concatenation 57
Escape Sequences 60

2.3 Variables and Assignment 60


Variables 61
The Assignment Statement 63
Constants 65

2.4 Primitive Data Types 65


Integers and Floating Points 66
Booleans 67
Characters 67

2.5 Arithmetic Expressions 68


Operator Precedence 69
Data Conversion 72

2.6 Enumerated Types 73

2.7 Creating Objects 74


The String Class 77
Wrapper Classes 79
Autoboxing 81

2.8 Class Libraries and Packages 82


The Import Declaration 83
The Random Class 85
The Math Class 86

2.9 Interactive Programs 89


The Scanner Class 89

2.10 Formatting Output 93


The NumberFormat Class 93
The DecimalFormat Class 93
The Printf Method 95
CONTENTS xxi

2.11 An Introduction to Applets 97


Executing Applets Using the Web 99

2.12 Drawing Shapes 100


The Graphics Class 100
The Color Class 102

Chapter 3 Program Statements 117


3.0 Program Development 118

3.1 Control Flow 120

3.2 The if Statement 121


Equality and Relational Operators 123
The if-else Statement 124
Using Block Statements 125
Nested if Statements 128

3.3 Boolean Expressions Revisited 130


Logical Operators 130
Comparing Characters and Strings 132
Comparing Floating Point Values 134

3.4 More Operators 134


Increment and Decrement Operators 135
Assignment Operators 135

3.5 The While Statement 136


Infinite Loops 140
Nested Loops 143
3.6 Iterators 146
Reading Text Files 147
3.7 The For Statement 150
Iterators and for Loops 155
Comparing Loops 156
3.8 Program Development Revisited 157
3.9 Drawing Using Conditionals and Loops 161

Chapter 4 Writing Classes 181


4.0 Objects Revisited 182
Classes 183

4.1 Anatomy of a Class 184


Instance Data 187
Encapsulation and Visibility Modifiers 189
xxii CONTENTS

4.2 Anatomy of a Method 192


The Return Statement 197
Parameters 199
Preconditions and Postconditions 200
Constructors 201
Local Data 202
Accessors and Mutators 202

4.3 Method Overloading 203

4.4 Method Decomposition 204

4.5 Object Relationships 211


Association 211
Association Between Objects of the Same Class 211
Aggregation 213

4.6 Applet Methods 220

4.7 Graphical Objects 221

Chapter 5 Enhancing Classes 241


5.0 References Revisited 242
The Null Reference 242
The This Reference 243
Aliases 243
Passing Objects as Parameters 249

5.1 The Static Modifier 253


Static Variables 253
Static Methods 253

5.2 Exceptions 256


Exception Messages 257
Throwing Exceptions 258

5.3 Interfaces 259


The Comparable Interface 264
The List Interface 266
The Iterator and ListIterator Interfaces 266

5.4 Identifying Classes and Objects 268


Designing Classes 269
Testing and Debugging 271

5.5 Nested Classes 273


Inner Classes 273

5.6 Dialog Boxes 274


CONTENTS xxiii

5.7 Graphical User Interfaces 276


Essential GUI Elements 276
Creating GUIs 277
GUI Applications 279

Chapter 6 Arrays 295


6.0 Arrays 296
Array Indexing 296
Declaring and Using Arrays 297
Initializer Lists 303
Arrays as Parameters 305

6.1 Arrays of Objects 305


Arrays of String Objects 305
Command-line Arguments 307
Filling Arrays of Objects 309

6.2 Searching 313


Comparing Searches 317

6.3 Sorting 319


Selection Sort 319
Insertion Sort 322
Sorting an Array of Objects 323
6.4 Comparing Sorts 326
6.5 Hashing 328
6.6 Two-dimensional Arrays 330
6.7 The ArrayList Class 333
Specifying an ArrayList Element Type 334
Using a ListIterator 336
ArrayList Efficiency 336

6.8 Polygons and Polylines 338


The Polygon Class 341
6.9 Other Button Components 341
Check Boxes 342
Radio Buttons 345

Chapter 7 Inheritance 363


7.0 Creating Subclasses 364
Derived Classes 364
The Super Reference 368
Multiple Inheritance 370
xxiv CONTENTS

7.1 Overriding Methods 371


7.2 Class Hierarchies 372
The Object Class 374
Abstract Classes 378

7.3 Indirect Use of Class Members 384

7.4 Designing for Inheritance 387

7.5 Polymorphism 388


References and Class Hierarchies 389
Polymorphism and Inheritance 390

7.6 Interfaces 399


Polymorphism with Interfaces 399

7.7 Designing for Polymorphism 401

7.8 Inheritance and GUIs 402


Applets 402
The Component Class Hierarchy 403

7.9 Mouse Events 405


Extending Event Adapter Classes 412

Chapter 8 Recursion 429


8.0 Recursive Thinking 430
Infinite Recursion 430
Recursion in Math 431

8.1 Recursive Programming 432


Recursion vs. Iteration 434
Direct vs. Indirect Recursion 435

8.2 Using Recursion 435


Solving a Maze 436
The Towers of Hanoi 440

8.3 Recursion in Sorting 444


Merge Sort 444
Quick Sort 450

8.4 Recursion in Graphics 451


Tiled Pictures 451
Fractals 454
CONTENTS xxv

Chapter 9 Linear Data Structures 473


9.0 Collections 474
Separating Interface from Implementation 474
Java API Collection Classes 474
Generics 475

9.1 Representing Data Structures 475


Dynamic Structures 476
Managing Linked Lists 476
Inserting Nodes 478
Deleting Nodes 479
A Dynamically Linked List Example 479
Other Dynamic List Representations 482
LinkedList 484

9.2 Queues and Stacks 486


Queues 486
Stacks 490

Chapter 10 Non-linear Data Structures 509


10.0 Sets and Maps 510

10.1 Trees 511


Tree Traversal 514
Binary Search Trees 517
TreeSet and TreeMap 524

10.2 Heaps 526


Heapsort 531
Implementing Heaps 531

10.3 More on Hashtables 534


Handling Collisions 534
HashSet and HashMap 540

Appendix A: Glossary 557

Appendix B: The Unicode Character Set 575

Appendix C: Java Operators 579

Appendix D: The Java Class Library 581


Appendix E: Number Systems 591

Appendix F: Responsible Use


of Computer Systems 599

Index 621
J ava 3rd Edition
S O F T WA R E S O L U T I O N S

for AP* Computer Science

*AP and Advanced Placement Program are registered trademarks of The College Board,
which was not involved in the production of, and does not endorse, this product.
This page intentionally left blank
Computer
Systems
This book is about writing well-designed software. C HA PTE R
1
O B J E C TI V E S
To understand software, we must first understand its ■ Describe the relationship
between hardware and software.
role in a computer system. Hardware and software
■ Define various types of software
work together in a computer system to accomplish com- and how they are used.
■ Identify basic computer
plex tasks. Furthermore, computer networks have
hardware and explain what
changed how computers are used, and they now play a it does.
■ Explain how the hardware
key role in even basic software development. This chap-
components execute programs
ter explores a broad range of computing issues, laying and manage data.
■ Describe how computers are
the foundation for the study of software development. connected together into
networks to share information.
■ Explain the importance of the
Internet and the World Wide Web.
■ Introduce the Java programming
language.
■ Describe the steps involved in
program compilation and
execution.
■ Introduce graphics and their
representations.

1
2 C HAPT ER 1 Computer Systems

1.0 Introduction
We begin our exploration of computer systems with an overview of computer
processing, defining some basic terminology and showing how the key pieces
of a computer system work together.

Basic Computer Processing


A computer system is made up of hardware and software. The hardware
components of a computer system are the physical pieces. They include chips,
boxes, routers, wires, keyboards, speakers, disks, memory cards, USB flash
drives (also called jump drives), cables, plugs, printers, mice, moni-
K E Y C O N C E PT tors, and so on. If you can physically touch it and it can be consid-
A computer system consists of hard- ered part of a computer system, then it is computer hardware.
ware and software that work together
The hardware components of a computer are useless without
to help us solve problems.
instructions to tell them what to do. A program is a series of instruc-
tions that the hardware executes one after another. Software includes
programs and the data those programs use. Together hardware and software
form a tool that we can use to help solve problems.
The key hardware components in a computer system are:

■ central processing unit (CPU)


■ input/output (I/O) devices
■ main memory
■ secondary memory devices

Each of these hardware components is described in detail in the next sec-


tion. For now, let’s simply examine their basic roles. The central processing
unit (CPU) is the device that executes the individual commands of a program.
Input/output (I/O) devices, such as the keyboard, mouse, and monitor, allow
a person to interact with the computer.
Programs and data are held in storage devices called memory, which fall into
two categories: main memory and secondary memory. Main memory holds the
software while it is being processed by the CPU. Secondary memory stores soft-
ware more or less forever—until it is deliberately erased. The most important
secondary memory device of a typical computer system is the hard disk, which
is inside the main computer box. A USB flash drive is also an important
secondary device. A typical USB flash drive cannot store nearly as much infor-
mation as a hard disk. USB flash drives are portable. That is, they can be
removed or moved from computer to computer as needed. Other portable
secondary memory devices include zip disks and compact discs (CDs).
*AP and Advanced Placement Program are registered trademarks of The College Board,
which was not involved in the production of, and does not endorse, this product.
1.0 Introduction 3

Figure 1.1 shows how information moves among the basic hard-
KEY CON CEPT
ware parts of a computer. Suppose you have a program you wish to
To execute a program, the computer
run. The program is stored on some secondary memory device, such first copies the program from second-
as a hard disk. When you tell the computer to execute your program, ary memory to main memory. The CPU
then reads the program instructions
a copy of the program is brought in from secondary memory and from main memory, executing them
stored in main memory. The CPU reads the program instructions one at a time until the program ends.
from main memory. The CPU then executes the instructions one at a
time until the program ends. The data that the instructions use, such
as two numbers that will be added together, also are stored in main memory.
They are either brought in from secondary memory or read from an input
device such as the keyboard. During execution, the program may display
information to an output device such as a monitor.
The process of executing a program is basic to the operation of a com-
puter. All computer systems work in about the same way.

Software Categories
There are many types of software. At this point we will simply look at sys-
tem programs and application programs.
The operating system is the main software of a computer. It does
KEY CON CEPT
two things. First, it provides a user interface that allows the user to
The operating system provides a user
interact with the machine: to click on an icon, for example, or delete interface and manages computer
a file. Second, the operating system manages computer resources such resources.
as the CPU and main memory. It decides when programs can run,
where they are loaded into memory, and how hardware devices communi-
cate. It is the operating system’s job to make the computer easy to use and to
keep it running well.
Several popular operating systems are in use today. The Windows 7 operat-
ing system was developed for personal computers by Microsoft which has cap-
tured an operating system market share of almost 90%. Versions of the Unix

Hard disk
Keyboard

Main
CPU
memory

USB flash drive Monitor

FIG URE 1 .1 A simplified view of a computer system


4 C HAPT ER 1 Computer Systems

operating system are also quite popular, such as Linux. Mac OS X is an oper-
ating system used on Apple computers.
An application is just about any software other than the operating system.
Word processors, missile control systems, database managers, Web browsers,
and games are all application programs. Each application program has its own
user interface that allows the user to interact with that particular program.
The user interface for most modern operating systems and applications is
a graphical user interface (GUI, pronounced “gooey”), which uses graphical
screen elements. Among others, these elements include:

■ windows, which are used to separate the screen into distinct work
areas
■ icons, which are small images that represent computer resources, such
as a file
■ checkboxes, and radio buttons, which give the user selectable options
■ sliders, which let the user select from a range of values
■ buttons, which can be “pushed” with a mouse click
The mouse is the primary input device used with GUIs, so GUIs are some-
times called point-and-click interfaces. The screen shot in Figure 1.2 shows
an example of a GUI.
The interface to an application or operating system is an important part of
the software because it is the only part of the program the user directly inter-
acts with. To the user, the interface is the program.

FIGURE 1.2 An example of a graphical user interface (GUI)


(Palm Desktop™ courtesy of 3COM Corporation)
1.0 Introduction 5

The focus of this book is high-quality application programs. We


KEY CON CEPT
explore how to design and write software that will perform calcula-
As far as the user is concerned, the
tions, make decisions, and present results textually or graphically. We interface is the program.
use the Java programming language throughout the text to demon-
strate computing concepts.

Digital Computers
Two techniques are used to store and manage information: analog and digi-
tal. Analog information is continuous. For example, an alcohol thermometer
is an analog device for measuring temperature. The alcohol rises in a tube at
the same time the temperature outside the tube rises. Another example of
analog information is the speed at which a car is going. As you press and
release the gas and brake pedals, the car’s speed varies. Figure 1.3 graphically
depicts a car’s speed as it varies over time.
Digital technology breaks information into pieces and shows those pieces
as numbers. The music on a compact disc is stored digitally, as a series of num-
bers. Each number represents the voltage level of one specific instance of the
recording. Many of these measurements are taken in a short period of time,
perhaps 44,000 measurements every second. The number of measurements
per second is called the sampling rate. If samples are taken often enough, the
separate voltage measurements can be used to create an analog signal that is
“close enough” to the original. In most cases, the reproduction is good
enough to satisfy the human ear.
Figure 1.4 shows the sampling of an analog signal. When analog
KEY CON CEPT
information is converted to a digital format by breaking it into pieces,
Digital computers store information
we say it has been digitized. Because the changes that occur in a sig- by breaking it into pieces and repre-
nal between samples are lost, the sampling rate must be fast enough senting each piece as a number.
to make up the difference.
Sampling is only one way to digitize information. For example, a sentence
can be stored on a computer as a series of numbers, where each number
represents a single character in the sentence. Every letter, digit, and punctuation

60 mph

0 mph

time

FIG URE 1 .3 A car’s speed as it changes over time


6 C HAPT ER 1 Computer Systems

Information can be lost


between samples

Analog signal

Sampling process

Sampled values 12 11 39 40 7 14 47

FIG URE 1 .4 Digitizing an analog signal by sampling

mark has been given a number. Even the space character gets a number.
Consider the following sentence:

Hi, Heather.

The characters of the sentence are represented as a series of 12 numbers, as


shown in Figure 1.5. When a character is repeated, such as the uppercase ‘H’,
the same number is used. Note that the uppercase version of a letter is stored
as a different number from the lowercase version, such as the ‘H’ and ‘h’ in
the word Heather. They are considered different characters.
Modern computers are digital. Every kind of information, including text,
images, numbers, audio, video, and even program instructions, is broken into
pieces. Each piece is represented as a number. The information is stored by
storing those numbers.

Binary Numbers
A digital computer stores information as numbers, but those numbers are
not stored as decimal numbers. All information in a computer is stored and
managed as binary numbers. Unlike the decimal system, which has 10 digits

H i , H e a t h e r.

72 105 44 32 72 101 97 116 104 101 114 46

FIG URE 1 .5 Text is stored by mapping each character to a number


1.0 Introduction 7

(0 through 9), the binary number system has only two digits (0 and 1). A sin-
gle binary digit is called a bit.
All number systems work according to the same rules. The base value of a
number system tells us how many digits we have to work with and what is
the place value of each digit in a number. The decimal number system is base
10, whereas the binary number system is base 2.
Modern computers use binary numbers because the devices that
KEY CON CEPT
store and move information are less expensive and more reliable if Binary values are used to store and
they have to represent only one of two possible values. Other than move all information in a computer
this, there is nothing special about the binary number system. Some because the devices that use binary
information are inexpensive and
computers use other number systems to store and move information, reliable.
but they aren’t as convenient.
Some computer memory devices, such as hard drives, are magnetic. Magnetic
material can be polarized easily to one extreme or the other, but in-between lev-
els are hard to tell apart. So magnetic devices can be used to represent binary
values very well—a magnetized area represents a binary 1 and a demagnetized
area represents a binary 0. Other computer memory devices are made up of tiny
electrical circuits. These devices are easier to create and are less likely to fail if
they have to switch between only two states. We’re better off making millions
of these simple devices than creating fewer, more complicated ones.
Binary values and digital electronic signals go hand in hand. They improve
our ability to send information reliably along a wire. As we’ve seen, an analog
signal has continuously varying voltage with infinitely many states, but a digital
signal is discrete, which means the voltage changes dramatically between one
extreme (such as 5 volts) and the other (such as –5 volts). At any point, the
voltage of a digital signal is considered to be either “high,” which represents a
binary 1, or “low,” which represents a binary 0. Figure 1.6 compares these two
types of signals.
As a signal moves down a wire, it gets weaker. That is, the voltage levels of
the original signal change slightly. The trouble with an analog signal is that as it
changes, it loses its original information. Since the information is directly anal-
ogous to the signal, any change in the signal changes the information. The
changes in an analog signal cannot be recovered because the new, degraded signal

Analog signal Digital signal

FIG URE 1 .6 An analog signal and a digital signal


8 C HAPT ER 1 Computer Systems

is just as valid as the original. A digital signal degrades just as an analog signal
does, but because the digital signal is originally at one of two extremes, it can be
reinforced before any information is lost. The voltage may change slightly from
its original value, but it still can be interpreted correctly as either high or low.
The number of bits we use in any given situation determines how many
items we can represent. A single bit has two possible values, 0 and 1, so it can
represent two items or situations. If we want to represent the state of a light-
bulb (off or on), one bit will suffice, because we can interpret 0 as the light-
bulb being off and 1 as the lightbulb being on. If we want to represent more
than two things, we need more than one bit.
Two bits, taken together, can represent four items because there are exactly
four ways we can arrange two bits: 00, 01, 10, and 11. Suppose we want to
represent the gear that a car is in (park, drive, reverse, or neutral). We would
need only two bits, and could set up a mapping between the bits and the gears.
For instance, we could say that 00 represents park, 01 represents drive, 10 rep-
resents reverse, and 11 represents neutral. (Remember that ‘10’ is not
‘ten’ but ‘one-zero’ and ‘11’ is not ‘eleven’ but ‘one-one.’) In this case,
K E Y C ON C E PT it wouldn’t matter if we switched that mapping around, though in
There are exactly 2N ways of arrang-
ing N bits. Therefore N bits can repre-
some cases the relationships between the bit permutations and what
sent up to 2N unique items. they represent is important.
Three bits can represent eight unique items, because there are eight
arrangements of three bits. Similarly, four bits can represent 16 items, five
bits can represent 32 items, and so on. Figure 1.7 shows the relationship

1 bit 2 bits 3 bits 4 bits 5 bits


2 items 4 items 8 items 16 items 32 items
0 00 000 0000 00000 10000
1 01 001 0001 00001 10001
10 010 0010 00010 10010
11 011 0011 00011 10011
100 0100 00100 10100
101 0101 00101 10101
110 0110 00110 10110
111 0111 00111 10111
1000 01000 11000
1001 01001 11001
1010 01010 11010
1011 01011 11011
1100 01100 11100
1101 01101 11101
1110 01110 11110
1111 01111 11111

FIG URE 1 .7 The number of bits used determines the number of items
that can be represented
1.1 Hardware Components 9

between the number of bits used and the number of items they can represent.
In general, N bits can represent 2N unique items. For every bit added, the
number of items that can be represented doubles.
We’ve seen how a sentence of text is stored on a computer as numeric values.
Those numeric values are stored as binary numbers. Suppose we had character
strings in a language with 256 characters and symbols. We would need to use
eight bits to store each character because there are 256 unique ways of arrang-
ing eight bits (28 equals 256). Each arrangement of bits is a specific character.
Ultimately, representing information on a computer boils down to the
number of items and how those items are mapped to binary values.

1.1 Hardware Components


Let’s look at the hardware components of a computer system in more detail.
Consider the computer described in Figure 1.8. What does it all mean? Can
the system run the software you want it to? How does it compare to other
systems? These terms are explained in this section.

Computer Architecture
The architecture of a house describes its structure. Similarly, we use the term
computer architecture to describe how the hardware components of a com-
puter are put together. Figure 1.9 shows the basic architecture of a computer
system. Information travels between components across a group of wires
called a bus.
The CPU and the main memory make up the core of a computer. As we
mentioned earlier, main memory stores programs and data that are being
used, and the CPU executes program instructions one at a time.

■ 3.07 GHz Intel Core i7 processor


■ 4 GB RAM
■ 750 GB Hard Drive
■ 16x Blu-ray / HD DVD-ROM & 16X
DVDR DVD Burner
■ 17" Flat Screen Video Display with
1280 x 1024 resolution
■ Network Card

FI GU R E 1 .8 The hardware specification of a particular computer


10 C HAPT ER 1 Computer Systems

Central Main
processing memory
unit

Bus

Disk Video
Controller Controller
controller controller

Other peripheral devices

FIG U RE 1 . 9 Basic computer architecture

Suppose we have a program that figures out the average of a list of


K E Y C O N C E PT
numbers. The program and the numbers must be in main memory
The core of a computer is made up of while the program runs. The CPU reads one program instruction
the CPU and the main memory. Main from main memory and executes it. When it needs data, such as a
memory is used to store programs number in the list, the CPU reads that information as well. This
and data. The CPU executes a pro-
gram’s instructions one at a time. process repeats until the program ends. The answer is stored in main
memory to await further processing or in long-term storage in sec-
ondary memory.
Almost all devices in a computer system other than the CPU and main
memory are called peripherals. Peripherals operate at the periphery, or outer
edges, of the system (although they may be in the same box). Users don’t
interact directly with the CPU or main memory. Instead users interact with
the peripherals: the monitor, keyboard, disk drives, and so on. The CPU and
main memory would not be useful without peripheral devices.
Controllers are devices that send information back and forth from the
CPU and main memory to the peripherals. Every device has its own way of
formatting and sending data, and part of the controller’s job is to handle
this. Furthermore, the controller often sends information back and forth, so
the CPU can focus on other activities.
Input/output (I/O) devices and secondary memory devices are one kind
of peripherals. Another kind of peripherals are data transfer devices, which
allow information to be sent and received between computers. The computer
described in Figure 1.8 has a network card, also called a wireless network
interface controller (WNIC), which connects to a radio-based computer net-
work.
1.1 Hardware Components 11

Secondary memory devices and data transfer devices can be thought of as


I/O devices because they represent a source of information (input) and a place
to send information (output). For our discussion, however, we define I/O
devices as devices that let the user interact with the computer.

Input/Output Devices
Let’s look at some I/O devices in more detail. The most common input devices
are the keyboard and the mouse. Others include:
■ bar code readers, such as the ones used at a retail store checkout
■ joysticks, often used for games and advanced graphical applications
■ microphones, used by voice recognition systems that interpret voice
commands
■ virtual reality devices, such as handheld devices that interpret the
movement of the user’s hand
■ scanners, which convert text, photographs, and graphics into machine-
readable form
Monitors and printers are the most common output devices. Others include:
■ plotters, which move pens across large sheets of paper (or vice versa)
■ speakers, for audio output
■ goggles, for virtual reality display
Some devices can handle both input and output. A touch screen system can
detect the user touching the screen at a particular place. Software can then
use the screen to display text and graphics in response to the user’s touch.
Touch screens have become commonplace for handheld devices.
The computer described in Figure 1.8 includes a monitor with a 17-inch
diagonal display area. A picture is created by breaking it up into small pieces
called pixels, a term that stands for “picture elements.” The monitor can
display a grid of 1280 by 1024 pixels. The last section of this chapter explores
the representation of graphics in more detail.

Main Memory and Secondary Memory


Main memory is made up of a series of small, connected memory
locations, as shown in Figure 1.10. Each memory location has a KEY CON CEPT
The address is the unique number of
unique number called an address.
a memory location. It is used when
When data is stored in a memory location, it overwrites and storing and retrieving data from
memory.
destroys any information that was stored at that location. However,
data is read from a memory location without affecting it.
On many computers, each memory location consists of eight bits, or one
byte, of information. If we need to store a value that cannot be represented
12 C HAPT ER 1 Computer Systems

4802
Data values are stored in
Addresses 4803 memory locations.
4804
4805
4806 Large values are stored
4807 in consecutive memory
locations.
4808
4809
4810
4811
4812

F I G U RE 1 . 1 0 Memory locations

in a single byte, such as a large number, then multiple, consecutive bytes are
used to store the data.
The storage capacity of a device such as main memory is the total
K E Y C O N C E PT number of bytes it can hold. Devices can store thousands or millions
Data written to a memory location
of bytes, so you should become familiar with larger units of measure.
overwrites and destroys any informa-
tion that was stored at that location. Because computer memory is based on the binary number system, all
Data read from a memory location units of storage are powers of two. A kilobyte (KB) is 1,024, or 210,
leaves the value in memory alone.
bytes. Some larger units of storage are a megabyte (MB), a gigabyte
(GB), a terabyte (TB), and a petabyte (PB), as listed in Figure 1.11.
It’s usually easier to think about these numbers if we round them off. For
example, most computer users think of a kilobyte as approximately one thou-
sand bytes, a megabyte as approximately one million bytes, and so forth.
Many personal computers have 4 gigabytes of main memory, or RAM,
such as the system described in Figure 1.8. (We discuss RAM in more detail
later in the chapter.) A large main memory allows large programs, or several
programs, to run because they don’t have to get information from secondary
memory as often.

Unit Symbol Number of Bytes


0
byte 2 =1
10
kilobyte KB 2 = 1024
20
megabyte MB 2 = 1,048,576
30
gigabyte GB 2 = 1,073,741,824
40
terabyte TB 2 = 1,099,511,627,776

petabyte PB 1,099,511,627,776

FIGU RE 1 . 1 1 Units of binary storage


1.1 Hardware Components 13

Main memory is usually volatile, meaning that the information


KEY CON CEPT
stored in it will be lost if its electric power supply is turned off. When
Main memory is volatile, meaning the
you are working on a computer, you should often save your work onto stored information is lost when the
a secondary memory device such as a USB flash drive in case the power electric power is turned off. Secondary
memory devices are usually nonvolatile.
is lost. Secondary memory devices are usually nonvolatile, meaning the
information is saved even if the power supply is turned off.
The cache is used by the central processing unit (CPU) to reduce the aver-
age access time to instructions and data. The cache is a small, fast memory
which stores the contents of the most frequently used main memory loca-
tions. Contemporary CPUs include an instruction cache to speed up the fetch-
ing of executable instructions and a data cache to speed up the fetching and
storing of data.
The most common secondary storage devices are hard disks and USB flash
drives. A typical USB flash drive stores between 16 MB and 256 GB of infor-
mation. The storage capacities of hard drives vary, but on personal comput-
ers, the hard drive can usually store between 40 GB and 120 GB, such as in
the system described in Figure 1.8. Some hard disks can store 2 TB.
A disk is a magnetic medium on which bits are represented as magnetized
particles. A read/write head passes over the spinning disk, reading or writing
information. A hard disk drive might actually have several disks in a column
with several read/write heads, such as the one shown in Figure 1.12.
A USB flash drive consists of a small printed circuit board carrying the cir-
cuit elements and a USB connector, insulated electrically and protected inside
a plastic, metal, or rubberized case which can be carried in a pocket or on a
key chain, for example.
To get a feel for how much information these devices can store, all the
information in this book, including pictures and formatting, requires about
6 MB of storage.

Read/write
head

Disks

FI GU R E 1. 12 A hard disk drive with multiple disks and read/write heads


14 C HAPT ER 1 Computer Systems

Magnetic tapes also have been used as secondary storage but are slower
than hard disk and USB flash drives because of the way information is
accessed. A hard disk is a direct access device since the read/write head can
move, in general, directly to the information needed. A USB flash drive is a
direct access device, but nothing moves mechanically. The terms direct access
and random access are often confused. However, information on a tape can
be accessed only after first getting past the intervening data. A tape must be
rewound or fast-forwarded to get to the right place, the same way you have
to fast-forward through a cassette tape to get to the song you want to hear.
A tape is therefore considered a sequential access device. Tapes have been
used to store information when it is no longer used very often, or to provide
a backup copy of the information on a disk.
Two other terms are used to describe memory devices: random access mem-
ory (RAM) and read-only memory (ROM). It’s important to understand these
terms because they are used often, and their names can be misleading. RAM
and main memory are basically the same thing. The term RAM seems to mean
something it shouldn’t. Both RAM and ROM are direct (or random) access
devices. RAM should probably be called read-write memory, since data can be
both written to it and read from it. Information stored on ROM, on the other
hand, cannot be changed (as the term “read-only” implies). ROM chips are
often embedded into the main circuit board of a computer and used to pro-
vide the instructions needed when the computer is initially turned on.
A CD-ROM is a portable secondary memory device. CD stands for
K E Y C O N C E PT compact disc. It is called ROM because information is stored perma-
The surface of a CD has both smooth
areas and small pits. A pit represents a
nently when the CD is created and cannot be changed. Like a musi-
binary 1 and a smooth area represents cal CD, a CD-ROM stores information in binary format. When the
a binary 0. CD is created, a microscopic pit is pressed into the disc to represent
a binary 1, and the disc is left smooth to represent a binary 0. The bits
are read by shining a low-intensity laser beam onto the spinning disc. The
laser beam reflects strongly from a smooth area on the disc but weakly from
a pitted area. A sensor determines whether each bit is a 1 or a 0. A typical
CD-ROM can store between 650 and 900 MB.
There are many kinds of CD technology today. Most personal computers
are equipped with a CD-Recordable (CD-R) drive. A CD-R can be used to
create a CD for music or for general computer storage. Once created, you can
use a CD-R disc in a standard CD player, but you can’t change the informa-
tion on a CD-R disc once it has been “burned.” Music CDs that you buy are
pressed from a mold, whereas CD-Rs are burned with a laser.
A CD-Rewritable (CD-RW) disc can be erased and reused. It can be reused
because the pits and flat surfaces of a normal CD are made on a CD-RW by
coating the surface of the disc with a material that, when heated to one tem-
perature becomes nonreflective and when heated to a different temperature
becomes reflective. The CD-RW media doesn’t work in all players, but CD-
Rewritable drives can create both CD-R and CD-RW discs.
1.1 Hardware Components 15

CDs started as a popular format for music; they later came to be


KEY CON CEPT
used as a general computer storage device. Similarly, the DVD format
A rewritable CD simulates the pits
was first created for video and is now making headway as a general and smooth areas of a regular CD
format for computer data. DVD once stood for digital video disc or using a coating that can be made
nonreflective or reflective as needed.
digital versatile disc. A DVD has a tighter format (more bits per
square inch) than a CD so it can store much more information. DVD-
ROMs may replace CD-ROMs completely because a DVD drive can read a
CD-ROM. There are currently six different formats for recordable DVDs.
The speed of a CD drive is expressed in multiples of x, which represents a
data transfer speed of 153,600 bytes of data per second, nine times that speed,
or about 1.5 megabytes of data per second for a DVD, and three times the speed
of a DVD, or 4.5 megabytes of data per second for a Blu-ray disk. The drive
described in Figure 1.8 has a maximum data speed of 16x, or about 72 MB of
data per second. A dual-layer Blu-ray disk has a storage capacity of 50 GB.
How much a device can store changes as technology improves. A general rule
in the computer industry is that storage capacity doubles every 18 months.
However, this progress eventually will slow down as storage capacities approach
absolute physical limits.

The Central Processing Unit


The central processing unit (CPU) uses main memory to perform all the basic
processing in a computer. The CPU reads and executes instructions, one after
another, in a continuous cycle. The CPU is made up of three important com-
ponents, as shown in Figure 1.13. The control unit handles the processing
steps, the registers are small amounts of storage space in the CPU itself, and
the arithmetic/logic unit does calculations and makes decisions.
The control unit transfers data and instructions between main memory and
the registers in the CPU. It also controls the circuitry in the arithmetic/logic unit.

CPU

Arithmetic/logic
unit

Bus
Main
Control unit
memory

Registers

FIG URE 1 .1 3 CPU components and main memory


16 C HAPT ER 1 Computer Systems

Fetch an instruction Decode the instruction


from main memory and increment program
counter

Execute the instruction

FIG URE 1 . 1 4 The fetch-decode-execute cycle

In most CPUs, some registers have special purposes. For example, the
instruction register holds the current instruction being executed. The program
counter holds the address of the next instruction to be executed. In addition
to these and other special-purpose registers, the CPU also contains a set of
general-purpose registers.
The idea of storing both program instructions and data together in main mem-
ory is called the von Neumann architecture of computer design, named after John
von Neumann, a Hungarian-American mathematician, who first advanced this
programming concept in 1945. These computers continually follow the fetch-
decode-execute cycle depicted in Figure 1.14. An instruction is fetched from main
memory and put into the instruction register. The program counter increases to
get ready for the next cycle. Then the instruction is decoded electronically
KE Y C O N C E PT to determine which operation to carry out. Finally, the control unit turns
The von Neumann architecture and the on the correct circuitry to carry out the instruction, which may load a
fetch-decode-execute cycle form the
foundation of computer processing.
data value into a register or add two values together, for example.
The CPU is on a chip called a microprocessor, a part of the main
circuit board of the computer. This board also contains ROM chips and com-
munication sockets to which device controllers, such as the controller that
manages the video display, can be connected.
Another part of the main circuit board is the system clock. The clock sends
out an electronic pulse at regular intervals, so that everything going on in the
CPU happens on the same schedule. The rate at which the pulses occur is called
the clock speed, and it varies depending on the processor. The computer
KE Y C O N C E PT described in Figure 1.8 includes an Intel Core I7 processor that runs at
The speed of the system clock a clock speed of 3.07 gigahertz (GHz), or about 3.1 billion pulses per
indicates how fast the CPU executes
instructions.
second. The speed of the system clock tells you about how fast the CPU
executes instructions. Like storage capacities, the speed of processors is
constantly increasing with advances in technology.

1.2 Networks
A single computer can do a lot, but connecting several computers together into
networks can dramatically increase how much they can do and make it easier to
share information. A network is two or more computers connected together so
1.2 Networks 17

File server

Shared printer

FIG URE 1 .1 5 A simple computer network

they can exchange information. Using networks is how commercial computers


operate today. New technologies are emerging every day to improve networks.
Figure 1.15 shows a simple computer network. One of the devices on the
network is a printer. Any computer connected to the network can print a doc-
ument on that printer. One of the computers on the network is a file server,
which does nothing but store programs and data that are needed by many
network users. A file server usually has a large amount of secondary memory.
When a network has a file server, each individual computer doesn’t need its
own copy of a program.

Network Connections
If two computers are directly connected, they can communicate in basically
the same way that information moves across wires inside a single machine.
When two computers are close to each other, this is called a point-to-point
connection. If point-to-point connections are used, every computer is directly
connected by a wire to every other computer in the network. But if
the computers are far apart, having a separate wire for each connec- KEY CON CEPT
tion won’t work because every time a new computer is added to the A network is two or more computers
connected together so they can
network, a new wire will have to be installed for each computer exchange information.
already in the network. Furthermore, a single computer can handle
only a small number of direct connections.
Figure 1.16 shows multiple point-to-point connections. Consider the num-
ber of wires that would be needed if two or three additional computers were
added to the network.

FIG URE 1 .1 6 Point-to-point connections


18 C HAPT ER 1 Computer Systems

Look at the diagrams in Figure 1.15 and Figure 1.16. All of the computers
in Figure 1.15 share a single communication line. Each computer on the net-
work has its own network address. These addresses are like the addresses in
main memory except that they identify individual computers on a network
instead of individual memory locations inside a single computer. A message
from one computer to another needs the network address of the computer
receiving the message.
Sharing a communication line is less expensive and makes adding
K E Y C O N C E PT new computers to the network easier. However, a shared line also
Sharing a communication line creates
delays, but it is cost effective and
means delays. The computers on the network cannot use the commu-
simplifies adding new computers to nication line at the same time. They have to take turns, which means
the network. they have to wait when the line is busy.
One way to improve network delays is to divide large messages
into small pieces, called packets, and then send the individual packets across
the network mixed up with pieces of other messages sent by other users. The
packets are collected at the destination and reassembled into the original mes-
sage. This is like a group of people using a conveyor belt to move a set of
boxes from one place to another. If only one person were allowed to use the
conveyor belt at a time, and that person had a lot of boxes to move, every-
one else would have to wait a long time before they could use it. By taking
turns, each person can put one box on at a time, and they all can get their
work done. It’s not as fast as having a conveyor belt of your own, but it’s not
as slow as having to wait until everyone else is finished.

Local-Area Networks and Wide-Area Networks


A local-area network (LAN) is designed to span short distances and connect
a small number of computers. Usually a LAN connects the machines in only
one building or in a single room. LANs are convenient to install and
K E Y C O N C E PT manage and are highly reliable. As computers became smaller, LANs
A local-area network (LAN) is an inex- became an inexpensive way to share information throughout an
pensive way to share information and organization. However, having a LAN is like having a telephone sys-
resources throughout an organization.
tem that allows you to call only the people in your own town. We
need to be able to share information across longer distances.
A wide-area network (WAN) connects two or more LANs, often across
long distances. Usually one computer on each LAN handles the communica-
tion across a WAN. This means the other computers in a LAN don’t need to
know the details of long-distance communication. Figure 1.17 shows several
LANs connected into a WAN. The LANs connected by a WAN are often
owned by different companies or organizations, and might even be located in
different countries.
Because of networks, computing resources can now be shared among
many users, and computer-based communication across the entire world is
1.2 Networks 19

One computer
LAN
in a LAN

Long-distance
connection

FIG URE 1 .1 7 LANs connected into a WAN

now possible. In fact, the use of networks is now so common that some com-
puters can’t work on their own.

The Internet
Throughout the 1970s, an agency in the Department of Defense, known
KEY CON CEPT
as the Advanced Research Projects Agency (ARPA) funded several proj-
The Internet is a wide-area network
ects to explore network technology. One result of these efforts was the (WAN) that spans the globe.
ARPANET, a WAN that eventually became known as the Internet. The
Internet is a network of networks. The term “Internet” comes from
the word internetworking—connecting many smaller networks together.
From the mid 1980s through today, the Internet has grown incredibly. In 1983,
there were fewer than 600 computers connected to the Internet. At the present
time, the Internet serves billions of users worldwide. As more and more comput-
ers connect to the Internet, keeping up with the larger number of users and heav-
ier traffic has been difficult. New technologies have replaced the ARPANET
several times over, each time providing more capacity and faster processing.
A protocol is a set of rules about how two things communicate.
The software that controls the movement of messages across the KEY CON CEPT
TCP/IP is the set of software
Internet must follow a set of protocols called TCP/IP (pronounced by
protocols, or rules, that govern
spelling out the letters, T-C-P-I-P). TCP stands for Transmission the movement of messages across
Control Protocol, and IP stands for Internet Protocol. The IP soft- the Internet.
ware defines how information is formatted and transferred. The TCP
software handles problems such as pieces of information arriving out of order
or information getting lost, which can happen if too much information arrives
at one location at the same time.
20 C HAPT ER 1 Computer Systems

Every computer connected to the Internet has an IP address that identifies it


among all other computers on the Internet. An example of an IP address is
204.192.116.2. Fortunately, the users of the Internet rarely have to deal with IP
addresses. The Internet lets each computer be given a name. Like IP addresses,
the names must be unique. The Internet name of a computer is often called its
Internet address. An example of an Internet address is spencer.villanova.edu.
The first part of an Internet address is the local name of a specific
K E Y C O N C E PT computer. The rest of the address is the domain name. The domain
Every computer connected to the
Internet has an IP address that
name tells you about the organization to which the computer belongs.
uniquely identifies it. For example, mcps.org is the domain name for the network of com-
puters in the Montgomery County public school system, and spencer
might be the name of a particular computer in the network. Because
the domain names are unique, many organizations can have a computer
named spencer without confusion. Individual schools might be assigned
subdomains that are added to the basic domain name. For example, the
chs.mcps.org subdomain is devoted to Christiansburg High School.
The last part of each domain name, called a top-level domain (TLD), usually
indicates the type of organization to which the computer belongs. The TLD edu
typically indicates an educational institution. The TLD com often refers to a
commercial business. Another common TLD is org, initially used by nonprofit
organizations. During an international meeting held in Paris in 2008, a process
was started for introducing generic top-level domains (gTLD). The new rules
could result in hundreds of new gTLDs. Many computers, especially those out-
side of the United States, use a country-code top-leve domain (ccTLD) that tells
the country of origin, such as uk for the United Kingdom. Recently, some new
top-level domain names have been created, such as biz, info, and name.
When an Internet address is referenced, it gets translated to its correspon-
ding IP address, which is used from that point on. The software that does this
translation is called the Domain Name System (DNS). Each organization
connected to the Internet operates a domain server that maintains a list of all
computers at that organization and their IP addresses. It works like telephone
directory assistance in that you give the name, and the domain server gives
back a number. If the local domain server does not have the IP address for the
name, it contacts another domain server that does.
The Internet has revolutionized computer processing. At first, intercon-
nected computers were used to send electronic mail. Today the Internet con-
nects us through the World Wide Web.

The World Wide Web


The Internet lets us share information. The World Wide Web (also known as
WWW or simply the Web) makes sharing information easy, with the click of
a mouse.
1.2 Networks 21

The Web is based on the ideas of hypertext and hypermedia. The


KEY CON CEPT
term hypertext was first coined in 1965 by Ted Nelson to describe a
The World Wide Web is software that
way to organize information. Paul Otlet (1868–1944), considered by makes sharing information across a
some to be the father of information science, envisioned that concept network easy.
as a way to manage large amounts of information. The idea is that
documents can be linked at logical points so that the reader can jump from
one document to another. When graphics, sound, animations, and video are
mixed in, we call this hypermedia.
A browser is a software tool that loads and formats Web documents for view-
ing. Mosaic, the first graphical interface browser for the Web, was released in
1993. The designer of a Web document defines links to other Web information
that might be anywhere on the Internet. Some of the people who devel-
oped Mosaic went on to found the Netscape Communications Corp.
and create the popular Netscape Navigator browser, which is shown in KEY CON CEPT
A browser is a software tool that
Figure 1.18. Popular contemporary browsers include Internet Explorer, loads and formats Web documents for
Mozilla Firefox, Apple Safari, Google Chrome, and Opera. viewing. These documents are often
written using the HyperText Markup
A computer dedicated to providing access to Web documents is Language (HTML).
called a Web server. Browsers load and interpret documents provided

F I GU R E 1 .1 8 Netscape Navigator browsing an HTML document


(used with permission of ACM)
Other documents randomly have
different content
Europeans falling back, they dashed into the water, and, carrying
their guns above their heads to keep them dry, crossed over and
took possession of the trees which grew on the opposite edge.
Secure within this cover, they opened a galling fire upon the
Europeans, who were now hopelessly exposed upon the face of the
fern-clad hill.
Mr. Thompson did his utmost to steady the party by exclaiming,
"For God's sake, men, keep together!" But his appeals were for the
most part disregarded, not more than a third of the men remaining
with their leaders, the rest retreating up the ridge and firing
haphazard as they went. Captain Wakefield's attempts to instil
something like discipline into the men were likewise frustrated by
some panic-stricken individual rushing up and shouting out, "Run for
your lives, lads, run!"—an injunction which they were not slow to
obey. In an instant all semblance of organisation had disappeared.
Time after time a few men were got together, but the majority were
always utterly beyond control. On the last partial rally Captain
Wakefield and Warrant Officer Howard ordered the men to fix
bayonets and charge the natives; but on one of the men (Richard
Painter), who had been in the artillery, pointing out that there was
no one visible to charge at, the idea was abandoned. The natives
were still maintaining a steady fire, and a protest on the part of the
artilleryman, who declined to remain where he was "and be shot
down like a crow," led to a further retreat up the hill-side. On the
second brow of the hill they met Mr. Cotterell, who was sitting down
with a double-barrelled gun at his side. At the commencement of the
quarrel he had been unarmed, but he had now seized this weapon in
self-defence. He appeared deeply distressed at what had occurred,
and expressed his intention of quitting the scene; but he was
dissuaded from this course by Captain Wakefield, who, addressing
him in most earnest tones, said, "For God's sake, Mr. Cotterell, don't
attempt to run away; you are sure to be shot if you do." Mr. Cotterell
therefore remained with the party, only remarking to Painter, one of
his own men, "This is bad work, Dick."
Being now out of range of the native fire, a council of war was
held of such of the party as could be got together, and finally it was
decided that Captain England and Mr. Howard should bear a flag of
truce to the natives, and endeavour to settle the dispute by
negotiation. A white handkerchief was accordingly fixed on a stick,
and, with this fluttering in the breeze, the two officers started
towards the wood. As an indication of their sincerity in desiring to
relinquish fighting, Captain Wakefield ordered all those who were
with him to lay their arms on the ground, and the natives, seeming
fully to appreciate the nature of the advances that were being made
to them, ceased firing, and a number of them left their muskets
behind the trees and came out to meet the bearers of the flag.
Captain England and his comrade had almost reached the wood,
when some of the Englishmen who had halted much higher up the
hill than Captain Wakefield, seeing the Maoris emerging from the
bush, commenced to fire upon them, notwithstanding that they had
seen the flag of truce, as well as their companions laying down their
arms. Regarding this as a dastardly act of treachery, the Maoris beat
a hasty retreat into the bush, and reopened a rapid fire upon the
Englishmen, whereupon Captain England and Mr. Howard ran back
to the hill, and reached the spot from which they had started,
uninjured by the native bullets.
This attempt at conciliation having failed through the folly of their
own people, the magistrate and Captain Wakefield decided to go
further up the hill and meet those who were in advance of them, to
induce them, if possible, to act in concert with the rest. In this they
were no more successful than before, for no sooner did the one
section begin to advance than the other began to retreat. Seeing
that this must go on indefinitely, Mr. Tuckett endeavoured to
persuade Captain Wakefield that their best hope of reaching the
beach and getting back to the brig was to abandon the ridge which
they were climbing, and strike down into the plain. Although this
advice was twice pressed on Wakefield, he took no notice of it, and
Mr. Tuckett thereupon, calling to Mr. Barnicoat and a labourer named
Gay to follow him, descended in an oblique direction on to the plain
below. For a moment Mr. Cotterell hesitated which course to take,
but finally decided to go up the spur with the rest, and this decision
cost him his life. When Captain Wakefield and his party began their
last retreat, most of them left their muskets lying on the brow of the
hill, and were therefore quite defenceless; but the Maoris kept up a
running fire as they gradually crept up the side of the range. As they
approached the summit of the first knoll, Mr. Cotterell stopped and
surrendered himself when the natives reached him, calling out,
"Enough, enough! that will do the fight," in the hope of assuring
them that the Europeans wanted peace. But he was immediately
struck down and his body thrown into a manuka bush. Captain
Wakefield followed his example by surrendering a few minutes later,
as did also Captain England, Messrs. Richardson, Howard, Brooks,
Cropper, McGregor, and the magistrate. A few of the younger natives
were in the van of the pursuit, and these held the prisoners in hand
until the arrival of Rauparaha, whom they had outstripped. At first
gold was offered as ransom, and it seemed as if the feud would end
without more bloodshed, for the chief had accepted the assurances
of Captain Wakefield that the shooting had been a mistake, and had
shaken hands with them all. But Rangihaeata, who had killed the
wounded as he found them lying on the hillside, panting with haste
and anger, rushed up and called out to Rauparaha, "What are you
doing? Your daughter Te Rongo[160] is dead. What are you doing, I
say?"
Scorning the acceptance of gold, he then fiercely demanded the
lives of the principal Europeans as the only utu that would
compensate him for the loss of his wife, exclaiming in impassioned
tones, "We are sure to be killed for this some day. The white people
will take utu; let us then have some better blood than that of these
tutua (common men). We are chiefs; let us kill the chiefs, and take
utu for ourselves beforehand." To this Rauparaha was at first
reluctant to agree, and his objections were well supported by Puaha
and the other Christian natives; but he felt that, in view of Te
Ronga's death, the demand was a reasonable one, and he at length
yielded to the powerful appeal of his lieutenant, and delivered the
unfortunate colonists over to their fate.
At this juncture Mr. Thompson seemed, for the first time, to be
apprehensive of serious consequences attending his conduct, and he
implored Rauparaha to save their lives. But that chief haughtily
answered, "Did I not warn you how it would be? A little while ago I
wished to talk with you in a friendly manner, and you would not;
now you say 'Save me.' I will not save you." The whole party then
retired a little lower down the hill, and there the massacre
commenced. Captain Wakefield and Mr. Thompson were killed by Te
Oru,[161] a son of Te Ahuta, the first native who fell in the fight, as a
retribution for the death of his father. Brooks, the interpreter, was
struck down by Rangihaeata and despatched by the slaves, which
would account for the mangled condition in which his body was
found by the burial party from Port Underwood. The rest of the
slaughter, according to native accounts, was conducted mainly by
Rangihaeata. His method of procedure was to glide silently behind
the victims while they were standing amongst the crowd of natives
and brain them with a single blow of his tomahawk. The peculiar
part of the tragedy was that none of the Englishmen, except Captain
Wakefield, made the slightest resistance, and even he was checked
by Mr. Howard exclaiming, "For God's sake, sir, do nothing rash!"
Perhaps their ignorance of the native language prevented them from
understanding all that was passing around them until they received
the fatal blow. But there was no struggle, no cries, except from the
native women, led by Puaha's wife, who pleaded with the men to
"save some of the rangatiras, if only to say they had saved some."
No Englishman who survived actually saw the massacre, and
therefore it is impossible to describe the exact method of its
execution; but the colonists to all appearances met their fate with
the greatest equanimity. George Bampton, who had concealed
himself amongst the fern only a few yards from the spot where the
tragedy was enacted, in giving evidence at Nelson a few days after
the event, deposed that "he heard neither cries nor screaming, but
merely the sound of beating or chopping, which he supposed at the
time to be natives tomahawking the white people."
In accordance with Rauparaha's express orders, none of the dead
bodies were mutilated or stripped, although Captain Wakefield's
watch was taken by Rangihaeata and buried with Te Rongo, while
one native furnished himself with a pair of white gloves and another
with a pair of silver-mounted pistols. After burying their own dead in
the Waitohi Valley, the two chiefs, with their followers, came down to
the mouth of the Wairau River, bringing with them their own canoes
and the whaleboat which had been taken up by Mr. Cotterell and his
men. In these they went first to Robin Hood Bay, and then to Te
Awaiti, in Tory Channel, where they remained a few days, finally
crossing the Strait to Mana and Otaki, there to await developments.
Shortly after the skirmishing began, a Sydney merchant named
Ferguson, who had been a passenger in the brig to Nelson, and had
accompanied her to the Wairau under the impression that he would
have a pleasant outing, had taken one of the wounded men, Gapper,
down to the river where the boats had been left that morning, and,
with him and the boatman who had been stationed in charge, had
paddled down the river to the bar, and reached the brig that
afternoon. A number of the men had also gone down the Waitohi
Valley, which was then densely bushed, and by this means had
evaded pursuit until they could return to Nelson by the overland
route. Others, again, who had broken away from the main body had
made for the sea, so that before Mr. Tuckett and his two companions
had proceeded very far they were joined by eight of the original
party, one of whom, John Bumforth, was badly wounded in the
shoulder. Mr. Tuckett first proposed that they should divide into two
parties, the one to proceed to the bar and the other to the vicinity of
Port Underwood, thinking that by this means the chances of some of
them reaching the brig would be increased. But the men stoutly
refused to separate, and the chief surveyor then decided to proceed
to the corner of Cloudy Bay nearest the port, where luckily they
found one of Mr. Dougherty's fully equipped whaleboats riding in the
bay a few chains off. They hailed the boatmen, and explained that
they wished to be taken to the brig, which was anchored some
seven or eight miles away; but owing to the heavy swell that was
rolling into the bay at the time, and the large number of the party,
there was the greatest difficulty in persuading the whalers to comply
with the request. Even after the danger of embarking had been
overcome, the headsman had almost made up his mind not to risk
the voyage to the brig, but to land the party at Port Underwood. But
fortune still favoured the fugitives, for at this moment another boat's
crew, who had been watching their movements, imagining that they
had sighted a whale, came out in pursuit, and the two boats raced
for the brig, which was almost reached before the pursuing crew
discovered the true position of affairs. Up to this point the whalers
had not been informed why Mr. Tuckett and his friends desired to get
on board the brig, but they were now told that a fracas had occurred
between the Europeans and the natives, that the leaders of the
party were Rauparaha's prisoners; and a promise (that was never
fulfilled) was extracted from the boatmen that they would convey
the intelligence to the other settlers at the port, and prepare them to
act as they might think best under the circumstances. The captain of
the brig then sent his boats to search the shore, in the hope that
other fugitives might have reached the beach; but no one was seen,
and no unusual circumstance was noted except the burning of a
large fire at the mouth of the river, which had been lit for some
purpose by the natives. The brig then weighed anchor and sailed for
Wellington, the captain, whose inclination was to enter Port
Underwood, adopting this course at the earnest solicitation of Mr.
Tuckett, who believed that, if assistance was necessary, it could be
more easily obtained from the larger centre of population.
When the news of what had happened spread through the infant
settlement early next morning, the excitement ran wild and high,
and the settlers, believing that at the worst Captain Wakefield and
his friends were only prisoners in the hands of the natives,
immediately organised a band of volunteers to effect their forcible
rescue. Their departure was, however, delayed by a gale, which had
the effect of making most of the volunteers seasick; and, by the time
the storm had abated, wiser counsels prevailed, and it was decided
that only a quorum of magistrates and Dr. Dorset, the surgeon of the
settlement, should proceed to the scene, the impression having
gained ground that intercession was more likely to prevail with the
Maoris than the presence of an armed force. The brig left Wellington
for Cloudy Bay that night, and it was when she arrived at Port
Underwood that Colonel Wakefield and Mr. Tuckett learned for the
first time the appalling nature of the tragedy which had been
enacted. They also learned that the natives, both resident and
visiting, had hurriedly left the Wairau, believing that retaliatory
measures would speedily be taken against them.
Altogether about twenty-seven of the arresting party had
managed to elude the pursuit of Rangihaeata's warriors. After
undergoing intense privations, some wandered back to Nelson, but
most of them went to Port Underwood, a few suffering from
wounds, and all from protracted hunger and exposure. The first to
arrive were Morgan and Morrison, who reached Ocean Bay with their
trousers worn to their knees, and they were shortly followed by
others who were in no better plight. Their wants and wounds were
attended to by Mrs. Dougherty, who ministered to them with the
kindest of care, and it was by these few survivors that the whalers
were first apprised of the catastrophe. The Rev. Mr. Ironside had
heard vague rumours about impending trouble between the chiefs
and the Government; but, as he had not seen the arrival of the brig,
he paid no heed to them until the following Sunday, when, in the
midst of a heavy rain-storm, he noticed a Maori swiftly paddling his
canoe up the bay. Knowing that a native would only be out on such
a day under exceptional circumstances, Mr. Ironside sent one of his
mission-boys to inquire. The boy did not return, which only
increased the anxiety, and later on, when a few particulars did reach
the station, they were only sufficient to indicate that a collision had
taken place, without any details. That night the missionary and his
wife retired to rest a prey to harrowing suspense.
Next morning the storm had increased to a perfect hurricane, and
as it was impossible to launch a boat, they could do nothing but
wait. By Tuesday the weather had moderated, and a boat's crew of
whalers took Mr. Ironside down to Ocean Bay, where the two chiefs
and their exultant followers had arrived. From them the whole story
was gleaned, and by them the tragedy was justified; "for," said Te
Rangihaeata, "they killed my wife, Te Rongo, and they did not
punish the murderer of Kuika."[162]
Mr. Ironside at once asked permission to go and bury the dead,
whereupon the fiery Rangihaeata ejaculated, "What do you want to
go for? Better leave them to the wild pigs. But you can go if you
like." Still the gale was too severe to admit of venturing across the
twelve miles of open sea; but so anxious had they all become, that
next morning a start was once more made from Ngakuta, and at the
imminent risk of their lives the brave crew pulled their boat across
the stormy bar into the river. On arriving at Tua Marina, Mr. Ironside
and his party found that all the bodies had been left as Rauparaha
had directed—unmutilated. The watch of Captain Wakefield was
gone, one of the pistols, which he had evidently attempted to fire,
had been laid across his throat in compliance with Maori custom,
and a piece of "damper," in savage derision, had been placed under
his head. The body of Brooks, the interpreter, was found to be in the
most mangled condition, the others apparently only having received
the one final and decisive blow, when they were struck down by the
enraged Rangihaeata. Five bodies were discovered in the bush close
to the creek, and were there interred with the benefits of Christian
burial, while those who were slain on the brow of the hill, thirteen in
number, were buried close by with similar rites. This fatiguing work
had been almost completed by the devoted missionary and his band
of native helpers when Colonel Wakefield, with the party from the
brig, arrived to assist. On an extended search being made by the
combined parties, one more body was found at the point where the
road turns into the Waitohi Valley, and it was buried where it lay.
Probably it was that of Isaac Smith, who had either sought to escape
after being mortally wounded, and had died in the attempt, or had
been overtaken in his flight and killed where he was found. Mr.
Patchett was buried in a single grave on the spot where he fell, and
Tyrrell and Northam were interred together close beside him.
In recognition of the kindly and humane service rendered by Mr.
Ironside during this critical and anxious period, the Nelson settlers
presented him with a testimonial in the shape of a handsome edition
of the Bible, bound in three volumes. The gift was gracefully
acknowledged by the reverend gentleman in a letter to Mr. Domett,
dated from Wellington on February 20, 1845.
Upon the return of the party to Port Underwood, Messrs. Spain
and McDonough (the magistrate at Wellington) set about collecting,
with all possible speed, all available information concerning the
disaster from those of both races who had been present, and who
had now arrived at the settlement. Amongst those whose
depositions were taken were two Maori boys, who had both been
wounded, and were being taken care of by female relatives. Their
story was a general corroboration of the Maori version, and they
were both unanimous in declaring that, when the Europeans were
overtaken on the brow of the hill, Puaha, who was one of the first to
reach them, offered them his hand and did all in his power to
obviate further bloodshed by pointing out that he had counted the
slain, and, as both sides had exactly the same number shot, there
was no need for further utu. In this view Rauparaha at first
concurred, but he finally gave way before the vehement
protestations of Rangihaeata, who reminded him in violent tones of
his duty to his dead relative, Te Rongo. He had then allowed his
enraged lieutenant to work his wicked will, which Puaha and his
people, being unarmed, were powerless to prevent. At the
conclusion of his inquiry, Mr. Spain left for Wellington, taking the
wounded with him; and those of the survivors who had escaped
uninjured proceeded back to Nelson, some in the boats and some
overland. Before leaving the port Mr. Tuckett was authorised by
Colonel Wakefield to act as agent for the settlement until the
pleasure of the New Zealand Company should be known. His journey
home was rather an adventurous one, as he had a very narrow
escape of being intercepted by the natives when sailing through the
French Pass. Some of his companions who were venturesome
enough to call in at Tory Channel, were detained there for a week by
the natives, but were ultimately permitted to take their departure
unharmed.
The body of Mr. Maling, the chief constable, had not been found
when Mr. Ironside made his first search upon the scene of the
massacre, a fact which created no surprise at the time, for it was
thought probable that he had succeeded in making good his escape
into the bush. But, as he had not arrived at any of the settlements,
the missionary again returned to Tua Marina for the dual purpose of
making an extended search and of protecting the graves already
made from desecration by the wild pigs, with which the valley was at
that time thickly stocked. He was successful in finding two bodies
floating in the stream, being the remains of Clanzey and Ratcliffe,
who had been shot while crossing in the canoe. These were
reverently interred on the banks of the creek near where Mr.
Patchett had been laid. The last resting-place of these men bears no
mark to distinguish it from the surrounding landscape, but a plain
though substantial monument has been raised over the spot where
Captain Wakefield and his companions fell; while a memorial church,
built by the Wakefield family, stands prominently upon the point of
the hill, and solemnly presides over the whole scene.
It would be difficult to describe the intense excitement which
agitated the whole colony as the tidings of the massacre flew from
settlement to settlement; and in the white heat of their anger the
settlers were guilty of saying and doing many rash and intemperate
things. Few of them had made themselves conversant with the
whole facts of the case, and fewer still stayed to reason out the
natural actions of men under the circumstances. All that they knew,
and all that they cared to know, was that their countrymen had
been, as a Nelson settler forcibly expressed it, "brutally butchered by
a parcel of miscreant savages, ten thousand of whose useless lives
would have all too cheaply purchased their survival, let the cant of
ultra-philanthropists say what it will." But this fierce indignation was
not participated in by the Europeans alone. Flying from the scene of
the tragedy, Te Rauparaha arrived with his retainers at Waikanae,
cold and wet with the sea spray which had swept over him on the
passage across the Strait. He immediately assembled the Ngati-Awa
people and told them the tale of the massacre, holding their
attention by the graphic nature of his narrative. At first his listeners
were unsympathetic, but he appealed to their sympathies by
feigning physical distress. Bent in body and trembling in voice, he
appeared to speak with difficulty, and used a hacking cough with
some effect to melt their sternness. But his most telling point was
made when, advancing a few steps, he held up his shaking hands
and dramatically exclaimed, "Why should they seek to fetter me? I
am old and weak; I must soon pass away. What could they gain by
enslaving me? by fastening irons on these poor old hands? No; that
is not what they seek. It is because through my person they hope to
dishonour you. If they can enslave me they think they can degrade
the whole Maori race."
This was the dart that struck deep into Maori pride, and wounded
their sense of honour. Instantly the tribe rose responsive to the
suggestion, and weapons were gripped, eyes flashed, and the spirit
of war surged in every breast. Missionary Hadfield was present, and
saw the sway wielded by the old chief's oratory. He saw, too, how
critical was the position, and gladly availed himself of the timely
suggestion made by one of the missionary natives to ring the bell for
evening prayers, and thus bring back the warriors' thoughts to a
more peaceful frame. Next morning Te Rauparaha journeyed to
Otaki, and there harangued the fighting men of Ngati-Toa. Here
there was no need to adopt the arts of the stage. His auditors were
his own followers, many of whom had been with him since
childhood. They knew him and trusted him, and with them his word
was law. He therefore threw off the guise of broken manhood, of
fettered limbs, of tottering steps, and stood before them the bold
and imperious chief that he was. His words ringing with the timbre
of commanding confidence, were direct and to the purpose. "Now is
the time to strike. You see what the smooth speech of the pakeha is
worth; you know now what they mean in their hearts. You know
now that tyranny and injustice is all that you can expect at their
hands. Come then and sweep them from the land which they have
sought to bedew with our blood."
In these warlike counsels he was ably seconded by Te
Rangihaeata, who, reasoning as a Maori would reason, had always
strongly held the view that, as the white men would be certain to
seek satisfaction for the massacre, their duty was to get what utu
they could while the opportunity to do so was theirs. He therefore
joined with his chief in urging an immediate march upon Wellington,
in order by one swift stroke to obliterate the pakeha and his
settlements. These sanguinary proposals were not preached to
unwilling ears, for it was but natural that the Maori should judge the
settlers by their leaders, the representatives of the New Zealand
Company, whose bad faith now appeared so audaciously
transparent. But there was one chief who was proof against the
hysteria of blood which had seized the tribes. Side by side with
Hadfield he stood like a rock above the billows of hate which surged
around him, and by his calm and stedfast loyalty broke the fury of
the storm. This was Wiremu Kingi te Rangitake, the Ngati-Awa chief
of Waitara. His resolute opposition to Te Rauparaha's plans was an
obstacle which that chief could not overcome. He carried his own
people with him, while Hadfield soothed the Ngati-Raukawa into
neutrality. Without Ngati-Raukawa and Ngati-Awa, Ngati-Toa was not
equal to a task which with their united forces would have been a
simple matter. That the Maoris had the power at this time to drive
the colonists into the sea, had they chosen to exercise it, has been
freely admitted by the settlers themselves,[163] so that the service
which Wiremu and the good missionary Hadfield rendered to the
Colony at this juncture can only be estimated at the value of the
infant settlement itself. And, with regret be it said, Wellington is
even now destitute of any monument to which the passing
generations might point as a public recognition of the fact that these
two men once stood between it and extermination.
Before Te Rauparaha was able to extend his projects for avenging
his wrongs beyond his own immediate sphere of influence, he was
visited by Mr. George Clarke, the Sub-Protector of the aborigines,
who gave him his most solemn pledge that the Government would
not attack him without first hearing his side of the question, and
begged him to try and keep the natives quiet until the case could be
investigated. Following close upon Mr. Clarke came Mr. Spain,
deputed by the magistrates at Wellington, and empowered to speak
as one in authority.[164] He strove to assure the natives that they
were mistaken if they imagined that the Europeans would wage war
against them indiscriminately by way of retaliation for the death of
Captain Wakefield and his comrades. The question of punishment
rested solely with the Governor, and, until he could decide who
should be punished and what the punishment should be, there
would be no act of aggression against the natives.
"Your words are very good, but who can tell what will be the
words of the Governor?" was the comment of one of the chiefs upon
these assurances. To this Spain could only reply by pointing to their
past intercourse, and asking if during their long acquaintance they
had ever known him to deceive them. Fortunately, his record stood
him in good stead, and the chief agreed that he for one would help
to protect the Europeans. While this discussion was proceeding,
Rauparaha had joined the assembly, and at this point he rose and
delivered what Mr. Spain considered "a most powerful speech." He
traversed anew the events which had led up to the fracas, and
vehemently asked, "Is this the justice which the Queen of England
promised to the Maori? You are not satisfied with having taken all
our land from us, but you send a Queen's ship headed by a Queen's
officer to fire upon us and kill us." Spain endeavoured to expound to
the angry chief the niceties of British law, under which a warrant to
arrest did not necessarily imply established guilt; had he surrendered
he would probably have been admitted to bail until the day of the
trial, and, so far from the Queen and the Governor being to blame
for the conduct of the magistrate, they had never heard of the
warrant. On Spain expressing his abhorrence of the killing of the
captives, Te Rauparaha admitted the error of the step, which he
palliated as due to their own custom and Rangihaeata's grief at the
death of his wife. He then proceeded to question Spain with an
acumen which astonished the lawyer, and forced him to form a very
high estimate of the chief's intellectual capacity; for his examination
was as keen "as if I had undergone that ordeal in Westminster Hall
at the hands of a member of the English Bar." What Te Rauparaha
wished to guard against was treachery. He wanted everything open
to the light of day, and the conference ended by his saying to Spain,
"If the Governor should decide upon sending soldiers to take me and
Rangihaeata, let us know when they arrive, because you need not
take the trouble to send up here for us. If you only send word I will
come down to Port Nicholson with a thousand Maoris and fight with
the pakehas. If they beat us, they shall have New Zealand, and we
will be their slaves, but if we beat them, they must stand clear."
Mr. Spain next proceeded to Otaki. There he was told that the
natives intended to stand loyally by their chiefs, and that any
attempt to seize them would lead to immediate reprisals. Following
closely upon Mr. Spain's departure, Mr. Jerningham Wakefield
reached Otaki. He came from the north, and, as he drifted down the
Whanganui River, he received the first tidings of the death of his
uncle. It was difficult at first to give credence to the nebulous
rumours which reached him; but the constant reiteration of the
same story about a fight with the pakehas and the death of
"Wideawake" gradually compelled attention, and ultimately received
confirmation at the white settlement then known as Petre.[165] Here
Wakefield was the recipient of a message from Te Rauparaha,
demanding to know whether he was for peace or for war, and
preferring a request that "Tiraweke" would come to Otaki to korero
with him. In the meantime he had sent his canoes to Manawatu, and
was preparing for his retreat into the interior should he be attacked.
Wakefield left Petre, and at the end of the first day he was met at
Rangitikei by the old Ngati-Raukawa chief Te Ahu karamu,[166] who
had gone thither with an armed party to conduct his friend safely
through the disturbed district. On reaching Otaki, Wakefield went to
Rangi-ura pa, the principal settlement, where the Maoris placed only
one interpretation upon his coming—vengeance upon Te Rauparaha
for the death of his uncle.
For two days Wakefield rested at Otaki, but saw nothing of the
chiefs. Rangihaeata was reported to be some distance in the interior,
building a strong pa, where it was understood that the chiefs had
determined to make a stand should the authorities seek to pursue
them. Te Rauparaha was at the Pakakutu pa at the mouth of the
river, endeavouring to break down the influence of Mr. Hadfield and
Wiremu Kingi. His efforts to consolidate his forces were various, as
suited the circumstances. He sought to ingratiate himself into the
good opinion of the missionary natives by appearing to become
zealous in religious observances; on the feeling of others he played
by a recital of his wrongs; and towards the European residents of
Otaki he assumed an attitude of unconcealed hostility, and ordered
their removal from the district. This step he deemed to be necessary,
in order that he might be free to act unhampered by spies in the
supposed impending campaign against the Queen's troops, and it
was this mandate which brought the chief and Wakefield face to
face.
As a result of Rauparaha's prohibition, a pakeha settler named
White, who had been living under the patronage of Te Ahu karamu,
found himself suddenly stopped at the Otaki River while in the act of
driving some thirty head of cattle on to the land upon which his
patron chief had invited him to settle. This high-handed action
naturally aroused the anger of the Ngati-Raukawa chiefs, who had
hitherto assumed that they were masters of the territory which they
had chosen to "sit upon" when the division of the conquered lands
was made. Te Ahu was especially angered at what he regarded as
an uncalled-for encroachment upon his prerogative as a chief. He
therefore announced his determination to proceed to the Pakakutu
pa and demand from Te Rauparaha a complete renunciation of his
views. Wakefield was invited to be present, and to his facile pen we
are indebted for a graphic account of what followed. The korero did
not commence immediately upon the arrival of Te Ahu's party at the
pa, and Wakefield employed the interval in the kindly office of
helping to dress the wounded leg of a Maori, whom he has
described as one "particularly gentle and dignified in his manners."
While thus engaged, Te Rauparaha approached him, and, with
evident signs of apprehension as to the propriety of his doing so,
offered a friendly salutation. Wakefield coldly declined to grasp the
hand which he naturally believed was imbrued in his uncle's blood;
and Rauparaha, immediately acknowledging the delicacy of his
position, muttered "It is good," and returned to his seat. The
speech-making commenced by his entering upon a lengthy narrative
of himself and his conquests, for the evident purpose of riveting in
the minds of his hearers the fact that he was the brain and the heart
of the tribe. His story was eloquently told, for not the least of his
great natural endowments was the precious gift of the silver tongue.
The tale of conquest ended, he was proceeding to refer to the
incidents of the Wairau, when Wakefield rose and checked him.
Naturally the latter was sensitive upon the point of prejudging so
dreadful a tragedy, by listening to an ex-parte statement of its facts,
when he was fully persuaded that at no distant date he would hear
the truth disclosed before an impartial tribunal. He therefore told Te
Rauparaha that he would not remain if he proposed to discuss the
affair of the Wairau, but begged him to confine his speech to a
justification of his extreme and arbitrary desire to drive the
Europeans away from Otaki.
Te Rauparaha acknowledged the reasonableness of this request,
but so anxious was he to excuse himself in the eyes of Wakefield,
that his oration had not proceeded far before he reverted to the
subject of the massacre. Thereupon Wakefield rose, and, walking to
the stile at the outer fence, was in the act of stepping over it to
proceed home, when a chorus of shouts called him back, and a
promise was given that there would be no further reference to the
Wairau. Te Rauparaha then earnestly addressed himself to the status
of the pakehas at Otaki, claiming the land as his alone. He admitted
the validity of the sales of the Manawatu, Whanganui, and Taranaki,
but not those of Otaki or Ohau, and insisted that the white people,
whalers included,[167] must remove to those districts which the
Company had fairly bought. He upbraided the Queen for sending her
constables to tie his hands. "Who is she," he asked, "that she should
send her books and her constables after me? What have I to do with
her? She may be Queen over the white people; I am the King of the
Maori! If she chooses to have war, let her send me word, and I will
stand up against her soldiers. But I must have room; I must have no
white people so near."[168]
Challenged as to the inconsistency of these views with his action
in signing the Treaty of Waitangi, he wheeled sharply round and
exclaimed, "Yes; what of that? They gave me a blanket for it. I am
still a chief, just the same. I am Rauparaha. Give me another blanket
tomorrow and I will sign it again. What is there in writing?" The
attitude of absolute authority assumed by the chief distinctly
alarmed Wakefield, who saw in it the elements of unlimited trouble
for the New Zealand Company. For if Te Rauparaha's claim to
exclusive jurisdiction over the land was well founded, then verily
many of their purchases had been brought to the brink of
repudiation. Turning hastily to Te Ahu and several of the chiefs
around him, he sought enlightenment on the point, reminding them
that they had frequently laid claim to large possessions in the
neighbourhood, but had never acknowledged Te Rauparaha as
having the least right or interest in them. Then Te Ahu proceeded in
a tone of apology and regret to elucidate one of the many intricate
phases of Maori land tenure which were now beginning to prove so
embarrassing to the Company. He explained that when the tribe
burned their houses at Maungatautari and came down to assist Te
Rauparaha in his conquest, they had selected Otaki out of the
conquered lands to be their future home. In times of peace
Rauparaha would have made no claim to the land, nor would his
claim have been acknowledged if he had. In proof of this, he quoted
the scorn with which Rangihaeata's assumptions over the Manawatu
had been rejected by Ngati-Raukawa; but now that the war clouds
were in the air, the riri, or anger, had completely altered the whole
aspect of affairs; the land had reverted to him who had conquered
it, and Ngati-Raukawa had no land which they could call their own.
"And then he rose," says Wakefield, "and endeavoured to persuade
Rauparaha to change his determination. He reminded him of the
'war parties which he had brought to him on his back to assist him
against his enemies, through dangers and troubles more than he
could count.' He related how 'he had burned the villages of the tribe
at Taupo to make them come with him to be by the side of
Rauparaha on the sea-coast.' He counted how many times he had
adhered to him 'in his feuds with Ngati-Awa,' and described 'how
much of the blood of Ngati-Raukawa had been spilt for his name.' Te
Ahu had now warmed with his subject, and was running up and
down, bounding and yelling at each turn, and beginning to foam at
the mouth, as the natives do when they seek to speak impressively.
'Let the cows go!' he cried. 'Let them go to my place!'
"Rauparaha seemed to consider that Te Ahu's eloquence was becoming too
powerful, and he jumped up too. They both continued to run up and down in
short parallel lines, yelling at each other, with staring eyes and excited
features, grimacing and foaming, shaking their hands and smacking their
thighs. As they both spoke together, it became difficult to hear what they said,
but I caught a sentence here and there, which gave me the sense of the
argument. 'No!' cried Rauparaha; 'no cows; I will not have them.' 'Let them
go!' yelled Te Ahu. 'Yield me my cows and my white man—the cows will not
kill you.' 'No cows, no white men! I am King! Never mind your war parties! No
cows!' answered Te Rauparaha. 'The cows cannot take you,' persisted Te Ahu;
'when the soldiers come we will fight for you, but let my cows go.' 'No, no,
no, indeed,' firmly replied the chief, and sat down.
"Te Ahu remained standing. He took breath for a minute, then drew himself
up to his full height, and addressed his own people in a solemn kind of
recitative. 'Ngati-Raukawa,' he sang, 'arise! Arise, my sons and daughters, my
elder brothers and my younger brothers, my sisters, my grand-children, arise!
Stand up, the families of Ngati-Raukawa! To Taupo! to Taupo! to
Maungatautari! To our old homes which we burned and deserted; arise and
let us go! Carry the little children on your backs, as I carried you when I came
to fight for this old man who has called us to fight for him and given us land
to sit upon, but grudges us white people to be our friends and to give us
trade. We have no white men or ships at Maungatautari, but the land is our
own there. We need not beg to have a white man or cows yielded to us there
if they should want to come. To Maungatautari. Arise, my sons, make up your
packs, take your guns and your blankets, and let us go! It is enough, I have
spoken.' As he sat down, a mournful silence prevailed. An important migration
had been proposed by the chief, which no doubt would be agreed to by the
greater part of the Otaki, Ohau, and Manawatu natives, on whom was
Rauparaha's chief dependence for his defence.
"I noticed that he winced when he first heard the purport of Te Ahu's song;
but, while Te Ahu continued, his countenance gradually resumed its
confidence. Much as I abhorred his character, I could not but yield my
unbounded admiration to the imperious manner in which he overthrew the
whole effect of Te Ahu's beautiful summons to his tribe. Instead of his usual
doubting and suspicious manner, his every gesture became that of a noble
chief. He rose with all the majesty of a monarch, and he spoke in the clearest
and firmest tones, so that the change from his customary shuffling, cautious
and snarling diction was of itself sufficient to command the earnest attention
of his audience. 'Go,' said he, 'go, all of you!—go, Ngati-Raukawa, to
Maungatautari! Take your children on your backs and go, and leave my land
without men. When you are gone, I will stay and fight the soldiers with my
own hands. I do not beg you to stop. Rauparaha is not afraid! I began to fight
when I was as high as my hip. All my days have been spent in fighting, and
by fighting I have got my name. Since I seized by war all this land, from
Taranaki to Port Nicholson, and from Blind Bay to Cloudy Bay beyond the
water, I have been spoken of as a King. I am the King of all this land. I have
lived a King, and I will die a King, with my mere in my hand. Go; I am no
beggar; Rauparaha will fight the soldiers of the Queen when they come, with
his own hands and his own name. Go to Maungatautari.' Then, suddenly
changing his strain, he looked on the assemblage of chiefs, bending down
towards them with a paternal smile, and softening his voice to kindness and
emotion. 'But what do I say?' said he; 'what is my talk about? You are
children! It is not for you to talk. You talk of going here and doing that. Can
one of you talk when I am here? No! I shall rise and speak for you all, and
you shall sit dumb, for you are all my children, and Rauparaha is your head
chief and patriarch.'"

This fearless rejection of Ngati-Raukawa assistance, culminating in


an arrogant assumption of absolute authority over their movements,
completely won him his point, and one of the highest chiefs said to
Wakefield, "It is true, Tiraweke! He is our father and our Ariki.
Rauparaha is the King of the Maori, like your Queen over the white
people." The others, full of conscious dignity in being followers of
such a leader, acknowledged his authority by bowing a silent assent.
Rauparaha remained inflexible in refusing to permit the cattle to
enter the district, but, in deference to the urgent persuasions of the
chiefs, he subsequently relaxed his prohibition against the white men
already settled in the district, but stoutly refused to sanction the
coming of any more.
But this effort of Te Rauparaha to consolidate his forces was in no
sense the full range of his preparations. To augment his fighting
strength was as much his policy as to unite those who already
acknowledged allegiance to him. And this he sought to do in a
quarter which, in view of past events, he would have been least
expected to approach, and where his advances, once made, would
have been least likely to touch a responsive chord. His scheme
involved no less a delicate task than salving the wounds of the Ngai-
Tahu tribe, and negotiating a friendly alliance with the men whose
mana he had so rudely trampled in the dust at Kaikoura and Kaiapoi.
To this end he collected a number of the most influential prisoners
whom he had taken at the latter place, and, bidding them go back to
their tribe, charged them to use their utmost endeavour to promote
a good feeling towards him amongst their people. This unexpected
act of clemency—or apparent clemency—which restored to them
their much esteemed chief Momo, their great warrior Iwikau, and
others equally noted in their history, went far to soothe the injured
pride of Ngai-Tahu, who, after much serious debate, decided to
forget the past, make peace, and accede to the new proposals. As
an earnest of their acceptance of Rauparaha's terms, Taiaroa at once
paid a visit to Kapiti, and, as he professed to be aggrieved at the
manner in which some land transactions had been conducted in the
south, there is little doubt that, had an attack upon Wellington been
contemplated, he and his people would have combined with their
former enemies to effect the annihilation of the colonists.[169]
A fearful uncertainty thus continued to agitate the breasts of the
settlers; and when H.M. ship of war, North Star arrived in Wellington
on 31st August, as the result of a memorial sent by the settlers to
Sir George Gipps, Governor of New South Wales, she was received
with a salute of guns and a display of bunting, which indicated a
belief that the day of retribution was at hand. It was not, however,
for four days that her commander, Sir Everard Home, was able to
enter into communication with Major Richmond, the principal officer
of the Government in Cook Strait. By him he was assured that "he
had received various reports of meditated attacks upon Wellington
by the natives under Te Rauparaha; that the chief was at a pa not
more than fourteen miles away, with between five hundred and a
thousand of his fighting men; that Taiaroa, the chief from the Middle
Island, had joined Te Rauparaha, and, having been an ancient
enemy to him, had made peace; that the pa at Porirua was fortified,
and every preparation made for an attack on the town of
Wellington." To this Sir Everard, having regard to his explicit
instructions not to intervene unless the natives and the whites were
at actual war, replied that, in his judgment, the circumstances did
not warrant his interference, but that he would keep his ship in the
harbour as a salutary check upon Maori aggression. In the meantime
he penned the following letter to Te Rauparaha:—
"Friend Rauparaha,—It has come to my knowledge that you are collecting the
tribes round you, because you expect that I am going to attack you. Those
who told you so said that which is not true. It was to keep the peace and not
to make war that I came here. You know that where many men are met
together, and continue without employment, they will find something evil to
do. They had best go home."

Sir Everard Home, having satisfied himself that no immediate crisis


was likely to arise at Wellington, unless it was precipitated by the
settlers themselves, was constrained by reports of seething
discontent at Nelson to visit the settlements in Blind Bay. But, before
proceeding thither, he decided to call in at the island of Mana, and
there personally discuss the situation with Te Rauparaha himself.
Accompanied by Major Richmond and Captain Best, he left
Wellington Harbour on the morning of October 5th, and anchored
the North Star under the lee of Mana that afternoon.
"As soon as the ship anchored," says Sir Everard in his official report, "I
landed, attended by Major Richmond and Captain Best, who commanded the
detachment on board the North Star. We first went to the whaling station, or
great pa, where we found Mr. Chetham (clerk of the Court), who had been
sent to join us. We also soon after met Mr. Clarke. He informed us that Te
Rauparaha had left that morning at daylight for Waikanae, which must have
been a voluntary movement, as no person knew our intention till the Strait
was entered. We immediately went round to the pa where the tribe was
established. Here we found no one on the beach to receive us, and, having
landed, walked to the huts, where we found a few persons sitting together.
Rangihaeata, they said, had fled to the bush, Te Rauparaha was at Waikanae,
and, finding that nothing could be done, we returned on board."

During this visit to Porirua, the attention of the official party had
been directed to the presence of the New Zealand Company's boat,
which had been brought by the natives from the Wairau, after the
massacre, and hauled up on the shore of Taupo Bay amongst some
twelve or fifteen canoes; and this fact was made a subject of
discussion next day when the frigate reached Kapiti.
Landing at Waikanae, where the interview was to take place, Sir
Everard Home says—
"We were received by the Rev. Mr. Hadfield, a missionary, a gentleman of high
character and great intelligence, who, living in the pa amongst the natives,
knows every movement, for none could take place without his knowledge. He
at once declared all the reports (of an intended attack upon Wellington) to be
without foundation. Having walked to his house, which is within the pa, we
proceeded to his school-yard, and the chiefs, Te Rauparaha, and Rere, chief of
the tribe inhabiting the pa of Waikanae, came, accompanied by about fifty
men. I then stated to the chief all that was reported of him, and asked him
what he had to say to contradict it. He replied that, far from wishing to
continue the quarrel with the Europeans, which had been commenced by
them, and not by him, his whole time was occupied in travelling up and down
the coast, endeavouring to allay the irritation of the natives and to prevent
any ill consequences arising from the provoking language and threats with
which they were continually annoyed by the Europeans travelling backwards
and forwards. That, for himself, he believed them to be lies invented by the
white men, having been assured by the Police Magistrate that no steps would
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like