100% found this document useful (1 vote)
7 views

(eBook PDF) Big Java: Early Objects 5th Edition instant download

The document provides information about various editions of the 'Big Java: Early Objects' eBook, along with links for downloading them. It outlines the book's structure, which includes fundamentals of programming, object-oriented design, data structures and algorithms, and applied topics. Additionally, it mentions the availability of online resources and custom book options for instructors and students.

Uploaded by

cvrdzay6118
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
100% found this document useful (1 vote)
7 views

(eBook PDF) Big Java: Early Objects 5th Edition instant download

The document provides information about various editions of the 'Big Java: Early Objects' eBook, along with links for downloading them. It outlines the book's structure, which includes fundamentals of programming, object-oriented design, data structures and algorithms, and applied topics. Additionally, it mentions the availability of online resources and custom book options for instructors and students.

Uploaded by

cvrdzay6118
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/ 56

(eBook PDF) Big Java: Early Objects 5th Edition

download

https://ebookluna.com/product/ebook-pdf-big-java-early-
objects-5th-edition/

Download full version ebook from https://ebookluna.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookluna.com
to discover even more!

(eBook PDF) Big Java: Early Objects, 7th Edition

https://ebookluna.com/product/ebook-pdf-big-java-early-objects-7th-edition/

(eBook PDF) Big Java: Early Objects, 6th Edition by Cay S. Horstmann

https://ebookluna.com/product/ebook-pdf-big-java-early-objects-6th-edition-
by-cay-s-horstmann/

(eBook PDF) Starting Out with Java: Early Objects 5th Edition

https://ebookluna.com/product/ebook-pdf-starting-out-with-java-early-
objects-5th-edition/

(eBook PDF) Big Java Late Objects 2nd Edition

https://ebookluna.com/product/ebook-pdf-big-java-late-objects-2nd-edition/
(eBook PDF) Starting Out with Java: Early Objects 5th Global Edition

https://ebookluna.com/product/ebook-pdf-starting-out-with-java-early-
objects-5th-global-edition/

(eBook PDF) Java How To Program (Early Objects) 10th

https://ebookluna.com/product/ebook-pdf-java-how-to-program-early-
objects-10th/

(eBook PDF) Starting Out with Java Early Objects 6th Edition by Tony Gaddis

https://ebookluna.com/product/ebook-pdf-starting-out-with-java-early-
objects-6th-edition-by-tony-gaddis/

(eBook PDF) Java How to Program, Early Objects 11th Edition by Paul J.
Deitel

https://ebookluna.com/product/ebook-pdf-java-how-to-program-early-
objects-11th-edition-by-paul-j-deitel/

(eBook PDF) Big C++: Late Objects 3rd Edition

https://ebookluna.com/product/ebook-pdf-big-c-late-objects-3rd-edition/
vi Preface

Part A: Fundamentals (Chapters 1–7)


Chapter 1 contains a brief introduction to computer science and Java programming.
Chapter 2 shows how to manipulate objects of predefined classes. In Chapter 3,
you will build your own simple classes from given specifications. Fundamental data
types, branches, loops, and arrays are covered in Chapters 4–7.

Part B: Object-Oriented Design (Chapters 8–12)


Chapter 8 takes up the subject of class design in a systematic fashion, and it intro-
duces a very simple subset of the UML notation. The discussion of polymorphism
and inheritance is split into two chapters. Chapter 9 covers inheritance and polymor-
phism, whereas Chapter 10 covers interfaces. Exception handling and basic file input/
output are covered in Chapter 11. The exception hierarchy gives a useful example for
inheritance. Chapter 12 contains an introduction to object-oriented design, including
two significant case studies.

Part C: Data Structures and Algorithms (Chapters 13–18)


Chapters 13 through 18 contain an introduction to algorithms and data structures,
covering recursion, sorting and searching, linked lists, binary trees, and hash tables.
These topics may be outside the scope of a one-semester course, but can be covered
as desired after Chapter 7 (see Figure 1). Recursion, in Chapter 13, starts with simple
examples and progresses to meaningful applications that would be difficult to imple-
ment iteratively. Chapter 14 covers quadratic sorting algorithms as well as merge sort,
with an informal introduction to big-Oh notation. Each data structure is presented
in the context of the standard Java collections library. You will learn the essential
abstractions of the standard library (such as iterators, sets, and maps) as well as the
performance characteristics of the various collections. Chapter 18 introduces Java
generics. This chapter is suitable for advanced students who want to implement their
own generic classes and methods.

Part D: Applied Topics (Chapters 19–25)


Chapters 19 through 25 cover Java programming techniques that definitely go
beyond a first course in Java (21–25 are on the book’s companion site). Although, as
already mentioned, a comprehensive coverage of the Java library would span many
volumes, many instructors prefer that a textbook should give students additional
reference material valuable beyond their first course. Some institutions also teach a
second-semester course that covers more practical programming aspects such as data-
base and network programming, rather than the more traditional in-depth material
on data structures and algorithms. This book can be used in a two-semester course
to give students an introduction to programming fundamentals and broad coverage
of applications. Alternatively, the material in the final chapters can be useful for stu-
dent projects. The applied topics include graphical user-interface design, advanced
file handling, multithreading, and those technologies that are of particular interest to
server-side programming: networking, databases, XML, and web applications. The
Internet has made it possible to deploy many useful applications on servers, often
accessed by nothing more than a browser. This server-centric approach to application
development was in part made possible by the Java language and libraries, and today,
much of the industrial use of Java is in server-side programming.

bj5_fm_06.indd 6 11/6/12 9:18 PM


Preface vii

Appendices
Many instructors find it highly beneficial to require a consistent style for all assign-
ments. If the style guide in Appendix I conflicts with instructor sentiment or local
customs, however, it is available in electronic form so that it can be modified.
A. The Basic Latin and Latin-1 Subsets F. Tool Summary
of Unicode G. Number Systems
B. Java Operator Summary H. UML Summary
C. Java Reserved Word Summary I. Java Language Coding Guidelines
D. The Java Library J. HTML Summary
E. Java Syntax Summary

Custom Book and eBook Options


Big Java may be ordered as a custom print or eBook that includes your choice of
chapters—including those from other Horstmann titles. Visit customselect.wiley.com
to create your custom book order.
To order the Wiley Select Edition of Big Java with all 25 chapters in the printed
book, specify ISBN 978-1-119-93670-1 when you order books.
Big Java is available in a variety of eBook formats at prices that are significantly
lower than the printed book. Please contact your Wiley sales rep for more informa-
tion or check www.wiley.com/college/horstmann for available versions.

Web Resources
This book is complemented by a complete suite of online resources. Go to www.wiley.
com/college/horstmann to visit the online companion sites, which include

• “CodeCheck,” a new online service currently in development by Cay Horstmann


that students can use to check their homework assignments and to work on addi-
tional practice problems. Visit http://horstmann.com/codecheck to learn more and to
try it out.
• Source code for all example programs in the book and in online examples.
• Worked Examples that apply the problem-solving steps in the book to other
realistic examples.
• Animations of key concepts.
• Lab exercises that apply chapter concepts (with solutions for instructors only).
• Lecture presentation slides (for instructors only).
• Solutions to all review and programming exercises (for instructors only).
• A test bank that focuses on skills, not just terminology (for instructors only). This
extensive set of multiple-choice questions can be used with a word processor or
imported into a course management system.

WORKED EXAMPLE 6.3 A Sample Debugging Session


Learn how to find bugs in an algorithm for counting the
Pointers in the book syllables of a word. Go to wiley.com/go/javaexamples and
download Worked Example 6.3.
describe what students
will find on the Web.
FULL CODE EXAMPLE

Go to wiley.com/go/
javacode to download
a program that dem-
onstrates variables
and assignments.

bj5_fm_06.indd 7 10/26/12 11:44 AM


viii Walkthrough

A Walkthrough of the Learning Aids


The pedagogical elements in this book work together to focus on and reinforce key
concepts and fundamental principles of programming, with additional tips and detail
organized to support and deepen these fundamentals. In addition to traditional
features, such as chapter objectives and a wealth of exercises, each chapter contains
elements geared to today’s visual learner.

254 Chapter 6 Loops

6.3 The for Loop


Throughout each chapter,
It often happens that you want to execute a sequence of statements a given number
margin notes show where The for loop is
used when a of times. You can use a while loop that is controlled by a counter, as in the following
example:
new concepts are introduced
value runs from a
starting point to an
ending point with a int counter = 1; // Initialize the counter
and provide an outline of key ideas. constant increment
or decrement.
while (counter <= 10) // Check the counter
{
System.out.println(counter);
counter++; // Update the counter
}

Because this loop type is so common, there is a spe-


cial form for it, called the for loop (see Syntax 6.2).
for (int counter = 1; counter <= 10; counter++)
{
Additional full code examples }
System.out.println(counter);

provides complete programs for FULL CODE EXAMPLE Some people call this loop count-controlled. In con-
trast, the while loop of the preceding section can be
students to run and modify.
Go to wiley.com/go/
javacode to download
a program that
called an event-controlled loop because it executes
uses common loop until an event occurs; namely that the balance reaches
algorithms. the target. Another commonly used term for a
count-controlled loop is definite. You know from
the outset that the loop body will be executed a
definite number of times; ten times in our example.
In contrast, you do not know how many iterations it
takes to accumulate a target balance. Such a loop is
Annotated syntax boxes called indefinite. You can visualize the for loop as
an orderly sequence of steps.
provide a quick, visual overview
of new language constructs. Syntax 6.2 for Statement

Syntax for (initialization; condition; update)


{
statements
}
These three
expressions should be related.
See page 259.

Annotations explain required This initialization The condition is This update is


components and point to more happens once
before the loop starts.
checked before
each iteration.
executed after
each iteration.
information on common errors for (int i = 5; i <= 10; i++)
or best practices associated The variable i is
{
sum = sum + i; This loop executes 6 times.
with the syntax. defined only in this for loop.
See page 261.
} See page 260.

Analogies to everyday objects are


used to explain the nature and behavior
of concepts such as variables, data
Like a variable in a computer types, loops, and more.
program, a parking space has
an identifier and a contents.

bj5_fm_06.indd 8 10/24/12 6:23 PM


Walkthrough ix

Memorable photos reinforce


analogies and help students
remember the concepts.

In the same way that there can be a street named “Main Street” in different cities,
a Java program can have multiple variables with the same name.

Problem Solving sections teach


techniques for generating ideas and 7.5 Problem Solving: Discovering Algorithms by Manipulating Physical Objects 339

evaluating proposed solutions, often Now how does that help us with our problem, switching the first and the second
using pencil and paper or other half of the array?
Let’s put the first coin into place, by swapping it with the fifth coin. However, as
artifacts. These sections emphasize Java programmers, we will say that we swap the coins in positions 0 and 4:

that most of the planning and problem


solving that makes students successful
happens away from the computer.

Next, we swap the coins in positions 1 and 5:

HOW TO 6.1 Writing a Loop How To guides give step-by-step


This How To walks you through the process of implementing a guidance for common programming
loop statement. We will illustrate the steps with the following
example problem. tasks, emphasizing planning and
Problem Statement Read twelve temperature values (one for
each month) and display the number of the month with the high- testing. They answer the beginner’s
est temperature. For example, according to worldclimate.com, the
average maximum temperatures for Death Valley are (in order by question, “Now what do I do?” and
month, in degrees Celsius):
18.2 22.6 26.4 31.1 36.6 42.2 45.7 44.5 40.2 33.1 24.2 17.6
integrate key concepts into a
In this case, the month with the highest temperature (45.7 degrees problem-solving sequence.
Celsius) is July, and the program should display 7.

Step 1 Decide what work must be done inside the loop.

Every loop needs to do some kind of repetitive work, such as


• Reading another item.
• Updating a value (such as a bank balance or total).
• Incrementing a counter. Worked Examples apply
If you can’t figure out what needs to go inside the loop, start by writing down the steps that
the steps in the How To to a
WORKED EXAMPLE 6.1 Credit Card Processing different example, showing
Learn how to use a loop to remove spaces from a credit card
number. Go to wiley.com/go/javaexamples and download
how they can be used to
Worked Example 6.1.
plan, implement, and test
a solution to another
programming problem.
Table 1 Variable Declarations in Java
Variable Name Comment

int width = 20; Declares an integer variable and initializes it with 20.

int perimeter = 4 * width; The initial value need not be a fixed value. (Of course, width
must have been previously declared.)
String greeting = "Hi!"; This variable has the type String and is initialized with the
Example tables support beginners
string “Hi”. with multiple, concrete examples.
height = 30; Error: The type is missing. This statement is not a declaration
but an assignment of a new value to an existing variable—see These tables point out common
Section 2.2.5.
errors and present another quick
Error: You cannot initialize a number with the string “20”.
reference to the section’s topic.
int width = "20";
(Note the quotation marks.)
int width; Declares an integer variable without initializing it. This can be a
cause for errors—see Common Error 2.1 on page 42.
int width, height; Declares two integer variables in a single statement. In this
book, we will declare each variable in a separate statement.

bj5_fm_06.indd 9 10/24/12 6:28 PM


x Walkthrough

This means “compute the value of width + 10 1 and store that value in the variable
width 2 ” (see Figure 4).
Progressive figures trace code
In Java, it is not a problem that the variable width is used on both sides of the = sym-
bol. Of course, in mathematics, the equation width = width + 10 has no solution.
segments to help students visualize
the program flow. Color is used
1 Compute the value of the right-hand side consistently to make variables and
width = 30
other elements easily recognizable.
width + 10

40

2 Store the value in the variable Figure 3


1 Initialize counter
Execution of a for (int counter = 1; counter <= 10; counter++)
Figure 4 width = 40 for Loop {
Executing the Statement System.out.println(counter);
counter = 1 }
width = width + 10

2 Check condition
for (int counter = 1; counter <= 10; counter++)
{
System.out.println(counter);
counter = 1 }

3 Execute loop body


for (int counter = 1; counter <= 10; counter++)
{
System.out.println(counter);
counter = 1 }

4 Update counter
for (int counter = 1; counter <= 10; counter++)
{

Students can view animations counter = 2 }


System.out.println(counter);

of key concepts on the Web.


A N I M AT I O N 5 Check condition again
for (int counter = 1; counter <= 10; counter++)
The for Loop {
System.out.println(counter);
counter = 2 }

The for loop neatly groups the initialization, condition, and update expressions
together. However, it is important to realize that these expressions are not executed
Self-check exercises at the together (see Figure 3).

end of each section are designed • The initialization is executed once, before the loop is entered. 1

to make students think through • The condition is checked before each iteration. 2 5
• The update is executed after each iteration. 4
the new material—and can
Write the for loop of the Investment class as a while loop.
spark discussion in lecture.
11.

SELF CHECK
12. How many numbers does this loop print?
for (int n = 10; n >= 0; n--)
{
System.out.println(n);
}

13. Write a for loop that prints all even numbers between 10 and 20 (inclusive).
14. Write a for loop that computes the sum of the integers from 1 to n.

Practice It Now you can try these exercises at the end of the chapter: R6.4, R6.10, E6.8, E6.12.
Optional science and business
exercises engage students with •• Business E6.17 Currency conversion. Write a program

realistic applications of Java. that first asks the user to type today’s
price for one dollar in Japanese yen,
then reads U.S. dollar values and
converts each to yen. Use 0 as a sentinel.

• Science P6.15 Radioactive decay of radioactive materials can be


section_1/Investment.java modeled by the equation A = A0e-t (log 2/h), where A is
1 /** the amount of the material at time t, A0 is the amount
2 A class to monitor the growth of an investment that at time 0, and h is the half-life.
3 accumulates interest at a fixed annual rate.
4 */ Technetium-99 is a radioisotope that is used in imaging
5 public class Investment of the brain. It has a half-life of 6 hours. Your program
6 { should display the relative amount A / A0 in a patient
7 private double balance; body every hour for 24 hours after receiving a dose.
8 private double rate;
9 private int year;
10
11 /**
12 Constructs an Investment object from a starting balance and
13 interest rate.
14 @param aBalance the starting balance
15
16 */
@param aRate the interest rate in percent
Program listings are carefully
17 public Investment(double aBalance, double aRate)
18 { designed for easy reading,
19 balance = aBalance;
20
21
rate = aRate;
year = 0;
going well beyond simple
22
23
}
color coding. Methods are set
24
25
/**
Keeps accumulating interest until a target balance has off by a subtle outline.
26 been reached.
27 @param targetBalance the desired balance
28 */

bj5_fm_05.indd 10 10/18/12 3:25 PM


Walkthrough xi

Length and Size


Common Errors describe the kinds Common Error 7.4
Unfortunately, the Java syntax for Data Type Number of Elements
of errors that students often make, determining the number of elements
in an array, an array list, and a string Array a.length
with an explanation of why the errors is not at all consistent. It is a com-
mon error to confuse these. You just Array list a.size()

occur, and what to do about them. have to remember the correct syntax
for every data type. String a.length()

Programming Tip 5.5 Hand-Tracing


A very useful technique for understanding whether a pro-
gram works correctly is called hand-tracing. You simulate
the program’s activity on a sheet of paper. You can use this
method with pseudocode or Java code.
Get an index card, a cocktail napkin, or whatever sheet
of paper is within reach. Make a column for each variable.
Have the program code ready. Use a marker, such as a
paper clip, to mark the current statement. In your mind,
execute statements one at a time. Every time the value of a
variable changes, cross out the old value and write the new
value below the old one. Hand-tracing helps you
For example, let’s trace the getTax method with the data understand whether a
Programming Tips explain from the program run above.
When the TaxReturn object is constructed, the income
program works correctly.

good programming practices, instance variable is set to 80,000 and status is set to MARRIED. Then the getTax method is called.
In lines 31 and 32 of TaxReturn.java, tax1 and tax2 are initialized to 0.
and encourage students to be 29 public double getTax()
30 {

more productive with tips and income status tax1 tax2


31 double tax1 = 0;
32 double tax2 = 0;
33 80000 MARRIED 0 0
techniques such as hand-tracing. Because status is not SINGLE, we move to the else
branch of the outer if statement (line 46).
34 if (status == SINGLE)
35 {
36 if (income <= RATE1_SINGLE_LIMIT)
37 {
38 tax1 = RATE1 * income;
39 }
40 else
41 {
42 tax1 = RATE1 * RATE1_SINGLE_LIMIT;
43 tax2 = RATE2 * (income - RATE1_SINGLE_LIMIT);
44 }
45 }
46 else
47 {

Special Topic 11.2 File Dialog Boxes


In a program with a graphical user interface, you will want to use a file dialog box (such as the
one shown in the figure below) whenever the users of your program need to pick a file. The
JFileChooser class implements a file dialog box for the Swing user-interface toolkit.
The JFileChooser class has many options to fine-tune the display of the dialog box, but in its
Special Topics present optional most basic form it is quite simple: Construct a file chooser object; then call the showOpenDialog
or showSaveDialog method. Both methods show the same dialog box, but the button for select-
topics and provide additional ing a file is labeled “Open” or “Save”, depending on which method you call.
For better placement of the dialog box on the screen, you can specify the user-interface
explanation of others. New component over which to pop up the dialog box. If you don’t care where the dialog box pops
up, you can simply pass null. The showOpenDialog and showSaveDialog methods return either
features of Java 7 are also JFileChooser.APPROVE_OPTION, if the user has chosen a file, or JFileChooser.CANCEL_OPTION, if the
user canceled the selection. If a file was chosen, then you call the getSelectedFile method to
covered in these notes. obtain a File object that describes the file. Here is a complete example:
FULL CODE EXAMPLE
JFileChooser chooser = new JFileChooser();
Go to wiley.com/go/ Scanner in = null;
javacode to download
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
a program that
{
demonstrates how to
use a file chooser. File selectedFile = chooser.getSelectedFile();
in = new Scanner(selectedFile);
. . .
}

Call with
showOpenDialog
method

Computing & Society 1.1 Computers Are Everywhere


Button is “Save” when
When computers The advent of ubiqui-
showSaveDialog method
were first invented tous computing changed
is called
in the 1940s, a computer filled an many aspects of our
entire room. The photo below shows lives. Factories used
the ENIAC (electronic numerical inte- to employ people to
A JFileChooser Dialog Box
grator and computer), completed in do repetitive assembly
1946 at the University of Pennsylvania. tasks that are today car-
The ENIAC was used by the military ried out by computer-
Computing & Society presents social to compute the trajectories of projec- controlled robots, oper-
tiles. Nowadays, computing facilities ated by a few people
and historical topics on computing—for of search engines, Internet shops, and who know how to work
social networks fill huge buildings with those computers.
interest and to fulfill the “historical and called data centers. At the other end of Books, music, and mov-
the spectrum, computers are all around ies are nowadays often

social context” requirements of the us. Your cell phone has a computer consumed on com- This transit card contains a computer.
inside, as do many credit cards and fare puters, and comput-

ACM/IEEE curriculum guidelines.


cards for public transit. A modern car ers are almost always
has several computers––to control the involved in their production. The could not have been written without
engine, brakes, lights, and the radio. book that you are reading right now computers.

bj5_fm_05.indd 11 10/18/12 3:25 PM


xii Walkthrough

Web Resources

http://horstmann.com/codecheck/
CodeCheck “CodeCheck” is a new
online service currently in development
by Cay Horstmann that students can
use to check their homework and to
work on additional practice problems.
Visit http://horstmann.com/codecheck
to learn more and to try it out.

Test Bank Instructors can use quiz and


test questions designed to exercise
students’ code reading and writing skills.

10) What is displayed after executing the given code snippet?

int[] mymarks = new int[10];


int total = 0;
Scanner in = new Scanner(System.in);
for (int cnt = 1; cnt <= 10; cnt++)
{
System.out.print("Enter the marks: ");
mymarks[cnt] = in.nextInt();
total = total + mymarks[cnt];
}
System.out.println(total);

a) The code snippet displays the total marks of all ten subjects.
b) The for loop causes a run-time time error on the first iteration.
c) The code snippet causes a bounds error.
d) The code snippet displays zero.

Lab Exercises These multi-part


1.1) Consider the following Card class. exercises ask students to apply
public class Card
{
chapter concepts. They can serve
private String name; as “warm-ups” in the lab or to Animations Students can
public Card() provide additional practice. play and replay dynamic
{
name = ""; explanations of concepts
}
and program flow.
public Card(String n)
{
name = n;
}

public String getName()


{
return name;
}

public boolean isExpired()


{
return false;
}

public String format()


{
return "Card holder: " + name;
}
}

Use this class as a superclass to implement a hierarchy of related classes:

Class Data
IDCard ID number
CallingCard Card number, PIN
DriverLicense Expiration year

Write declarations for each of the subclasses. For each subclass, supply private instance variables. Leave the
bodies of the constructors and the format methods blank for now.

bj5_fm_06.indd 12 10/24/12 6:23 PM


Acknowledgments xiii

Acknowledgments
Many thanks to Beth Lang Golub, Don Fowley, Elizabeth Mills, Katherine Willis,
Jenny Welter, Wendy Ashenberg, Lisa Gee, Kevin Holm, and Tim Lindner at John
Wiley & Sons, and Vickie Piercey at Publishing Services for their help with this proj-
ect. An especially deep acknowledgment and thanks goes to Cindy Johnson for her
hard work, sound judgment, and amazing attention to detail.
I am grateful to Suchindran Chatterjee, Arizona State University, Jose Cordova,
University of Louisiana, Udayan Das, DeVry University, James Johnson, Aaron
Keen, California Polytechnic State University San Luis Obispo, Norm Krumpe,
Miami University Ohio, Kathy Liszka, University of Akron, Kathleen O’Brien, San
Jose State University, Donald Smith, Columbia College, Mark Thomas, University of
Cincinnati, Laurie White, Mercer University, Brent Wilson, George Fox University,
and David Woolbright, Columbus State University, for their excellent contributions
to the supplementary materials.
Many thanks to the individuals who reviewed the manuscript for this edition,
made valuable suggestions, and brought an embarrassingly large number of errors
and omissions to my attention. They include:

Eric Aaron, Wesleyan University Guy Helmer, Iowa State Bill Mongan, Drexel University
James Agnew, Anne Arundel University George Novacky, University
Community College Ed Holden, Rochester Institute of Pittsburgh
Greg Ballinger, Miami Dade of Technology Mimi Opkins, California State
College Steven Janke, Colorado College University Long Beach
Jon Beck, Truman State Mark Jones, Lock Haven Derek Pao, City University of
University University of Pennsylvania Hong Kong
Matt Boutell, Rose-Hulman Dr. Mustafa Kamal, University of Katherine Salch, Illinois Central
Institute of Technology Central Missouri College
John Bundy, DeVry University Gary J. Koehler, University of Javad Shakib, DeVry University
Chicago Florida Charlie Shu, Franklin University
Michael Carney, Finger Lakes Ronald Krawitz, DeVry Joslyn A. Smith, Florida
Community College University International University
Christopher Cassa, Norm Krumpe, Miami Robert Strader, Stephen F. Austin
Massachusetts Institute of University Ohio State University
Technology Jim Leone, Rochester Institute Jonathan S. Weissman, Finger
Dr. Suchindran S. Chatterjee, of Technology Lakes Community College
Arizona State University Kevin Lillis, St. Ambrose Katherine H. Winters, University
Tina Comston, Franklin University of Tennessee Chattanooga
University Darren Lim, Siena College Tom Wulf, University of
Lennie Cooper, Miami Dade Hong Lin, DeVry University Cincinnati
College Kuber Maharjan, Purdue Qi Yu, Rochester Institute of
Sherif Elfayoumy, University of University College of Technology
North Florida Technology at Columbus
Henry A Etlinger, Rochester Patricia McDermott-Wells,
Institute of Technology Florida International
University

bj5_fm_06.indd 13 11/9/12 11:56 AM


xiv Acknowledgments

Every new edition builds on the suggestions and experiences of prior reviewers and
users. I am grateful for the invaluable contributions these individuals have made:

Tim Andersen, Boise State University Elliotte Harold Kai Qian, Southern Polytechnic
Ivan Bajic, San Diego State University Eileen Head, Binghamton University State University
Ted Bangay, Sheridan Institute Cecily Heiner, University of Utah Cyndi Rader, Colorado School
of Technology Brian Howard, Depauw University of Mines
Ian Barland, Radford University Lubomir Ivanov, Iona College Neil Rankin, Worcester Polytechnic
George Basham, Franklin University Norman Jacobson, University of Institute
Sambit Bhattacharya, Fayetteville California, Irvine Brad Rippe, Fullerton College
State University Curt Jones, Bloomsburg University Pedro I. Rivera Vega, University
Rick Birney, Arizona State University Aaron Keen, California Polytechnic of Puerto Rico, Mayaguez
Paul Bladek, Edmonds Community State University, San Luis Obispo Daniel Rogers, SUNY Brockport
College Mugdha Khaladkar, New Jersey Chaman Lal Sabharwal, Missouri
Joseph Bowbeer, Vizrea Corporation Institute of Technology University of Science and
Timothy A. Budd, Oregon State Elliot Koffman, Temple University Technology
University Kathy Liszka, University of Akron John Santore, Bridgewater State
Robert P. Burton, Brigham Young Hunter Lloyd, Montana State College
University University Carolyn Schauble, Colorado State
Frank Butt, IBM Youmin Lu, Bloomsburg University University
Jerry Cain, Stanford University John S. Mallozzi, Iona College Brent Seales, University of Kentucky
Adam Cannon, Columbia University John Martin, North Dakota State Christian Shin, SUNY Geneseo
Nancy Chase, Gonzaga University University Jeffrey Six, University of Delaware
Archana Chidanandan, Rose-Hulman Jeanna Matthews, Clarkson University Don Slater, Carnegie Mellon
Institute of Technology Scott McElfresh, Carnegie Mellon University
Vincent Cicirello, The Richard University Ken Slonneger, University of Iowa
Stockton College of New Jersey Joan McGrory, Christian Brothers Donald Smith, Columbia College
Teresa Cole, Boise State University University Stephanie Smullen, University of
Deborah Coleman, Rochester Institute Carolyn Miller, North Carolina Tennessee, Chattanooga
of Technology State University Monica Sweat, Georgia Institute
Jose Cordova, University of Louisiana, Sandeep R. Mitra, State University of Technology
Monroe of New York, Brockport Peter Stanchev, Kettering University
Valentino Crespi, California State Teng Moh, San Jose State University Shannon Tauro, University of
University, Los Angeles John Moore, The Citadel California, Irvine
Jim Cross, Auburn University Jose-Arturo Mora-Soto, Jesica Ron Taylor, Wright State University
Russell Deaton, University Rivero-Espinosa, and Julio-Angel Russell Tessier, University of
of Arkansas Cano-Romero, University Massachusetts, Amherst
Geoffrey Decker, Northern Illinois of Madrid Jonathan L. Tolstedt, North Dakota
University Faye Navabi, Arizona State University State University
H. E. Dunsmore, Purdue University Parviz Partow-Navid, California State David Vineyard, Kettering University
Robert Duvall, Duke University University, Los Angeles Joseph Vybihal, McGill University
Eman El-Sheikh, University of Kevin O’Gorman, California Xiaoming Wei, Iona College
West Florida Polytechnic State University, San Todd Whittaker, Franklin University
John Fendrich, Bradley University Luis Obispo Robert Willhoft, Roberts Wesleyan
David Freer, Miami Dade College Michael Olan, Richard Stockton College
John Fulton, Franklin University College Lea Wittie, Bucknell University
David Geary, Sabreware, Inc. Kevin Parker, Idaho State University David Womack, University of Texas
Margaret Geroch, Wheeling Jesuit Jim Perry, Ulster County Community at San Antonio
University College David Woolbright, Columbus State
Ahmad Ghafarian, North Georgia Cornel Pokorny, California University
College & State University Polytechnic State University, Catherine Wyman, DeVry University
Rick Giles, Acadia University San Luis Obispo Arthur Yanushka, Christian Brothers
Stacey Grasso, College of San Mateo Roger Priebe, University of Texas, University
Jianchao Han, California State Austin Salih Yurttas, Texas A&M University
University, Dominguez Hills C. Robert Putnam, California State
Lisa Hansen, Western New England University, Northridge
College

bj5_fm_06.indd 14 11/6/12 9:23 PM


CONTENTS

Preface iii
Special Features xxii

Chapter 1 Introduction 1
1.1 Computer Programs 2
1.2 The Anatomy of a Computer 3
1.3 The Java Programming Language 6
1.4 Becoming Familiar with Your Programming Environment 8
1.5 Analyzing Your First Program 12
1.6 Errors 15
1.7 Problem Solving: Algorithm Design 16

Chapter 2 Using Objects 33

2.1 Objects and Classes 34


2.2 Variables 36
2.3 Calling Methods 43
2.4 Constructing Objects 48
2.5 Accessor and Mutator Methods 50
2.6 The API Documentation 52
2.7 Implementing a Test Program   55
2.8 Object References   57
2.9 Graphical Applications   61
2.10 Ellipses, Lines, Text, and Color   66

Chapter 3 Implementing Classes 81

3.1 Instance Variables and Encapsulation 82


3.2 Specifying the Public Interface of a Class 86
3.3 Providing the Class Implementation 93
3.4 Unit Testing   102
3.5 Problem Solving: Tracing Objects 105
3.6 Local Variables 107
3.7 The this Reference 109
3.8 Shape Classes   112

xv

bj5_fm_05.indd 15 10/18/12 3:25 PM


xvi Contents

Chapter 4 Fundamental Data Types 131


4.1 Numbers 132
4.2 Arithmetic 139
4.3 Input and Output 147
4.4 Problem Solving: First Do it By Hand 154
4.5 Strings 156

Chapter 5 Decisions 179


5.1 The if Statement 180
5.2 Comparing Values 186
5.3 Multiple Alternatives 196
5.4 Nested Branches 200
5.5 Problem Solving: Flowcharts 207
5.6 Problem Solving: Selecting Test Cases   210
5.7 Boolean Variables and Operators 213
5.8 Application: Input Validation 218

Chapter 6 Loops 241


6.1 The while Loop 242
6.2 Problem Solving: Hand-Tracing 249
6.3 The for Loop 254
6.4 The do Loop 262
6.5 Application: Processing Sentinel Values 263
6.6 Problem Solving: Storyboards 269
6.7 Common Loop Algorithms 272
6.8 Nested Loops 279
6.9 Application: Random Numbers and Simulations 283
6.10 Using a Debugger   286

Chapter 7 Arrays and Array Lists 311

7.1 Arrays 312


7.2 The Enhanced for Loop 321
7.3 Common Array Algorithms 322
7.4 Problem Solving: Adapting Algorithms 331
7.5 Problem Solving: Discovering Algorithms by Manipulating
Physical Objects 336
7.6 Two-Dimensional Arrays 340

bj5_fm_05.indd 16 10/18/12 3:25 PM


Contents xvii

7.7 Array Lists 347


7.8 Regression Testing   356

Chapter 8 Designing Classes 379

8.1 Discovering Classes 380


8.2 Designing Good Methods 381
8.3 Problem Solving: Patterns for Object Data 390
8.4 Static Variables and Methods 395
8.5 Packages 400
8.6 Unit Test Frameworks 407

Chapter 9 Inheritance 421


9.1 Inheritance Hierarchies 422
9.2 Implementing Subclasses 426
9.3 Overriding Methods 431
9.4 Polymorphism 437
9.5 Object: The Cosmic Superclass 448

Chapter 10 Interfaces 463

10.1 Using Interfaces for Algorithm Reuse 464


10.2 Working with Interface Variables 471
10.3 The Comparable Interface 473
10.4 Using Interfaces for Callbacks 477
10.5 Inner Classes 481
10.6 Mock Objects 483
10.7 Event Handling 484
10.8 Building Applications with Buttons 490
10.9 Processing Timer Events 494
10.10 Mouse Events 497

Chapter 11 Input/Output and Exception Handling 513

11.1 Reading and Writing Text Files 514


11.2 Text Input and Output 519
11.3 Command Line Arguments 527
11.4 Exception Handling 534
11.5 Application: Handling Input Errors 545

bj5_fm_05.indd 17 10/18/12 3:25 PM


xviii Contents

Chapter 12 Object-Oriented Design 559

12.1 Classes and Their Responsibilities 560


12.2 Relationships Between Classes 563
12.3 Application: Printing an Invoice 569

Chapter 13 RECURSION 587

13.1 Triangle Numbers 588


13.2 Recursive Helper Methods 596
13.3 The Efficiency of Recursion 598
13.4 Permutations 603
13.5 Mutual Recursion 608
13.6 Backtracking 614

Chapter 14 Sorting and searching 629

14.1 Selection Sort 630


14.2 Profiling the Selection Sort Algorithm 633
14.3 Analyzing the Performance of the Selection Sort Algorithm 636
14.4 Merge Sort 641
14.5 Analyzing the Merge Sort Algorithm 644
14.6 Searching 648
14.7 Problem Solving: Estimating the Running Time of an Algorithm 653
14.8 Sorting and Searching in the Java Library 658

Chapter 15 The Java Collections Framework 671

15.1 An Overview of the Collections Framework 672


15.2 Linked Lists 675
15.3 Sets 681
15.4 Maps 686
15.5 Stacks, Queues, and Priority Queues 692
15.6 Stack and Queue Applications 695

Chapter 16 Basic Data Structures 715

16.1 Implementing Linked Lists 716


16.2 Implementing Array Lists 731
16.3 Implementing Stacks and Queues 735
16.4 Implementing a Hash Table 741

bj5_fm_05.indd 18 10/18/12 3:25 PM


Contents xix

Chapter 17 tree Structures 761

17.1 Basic Tree Concepts 762


17.2 Binary Trees 766
17.3 Binary Search Trees 771
17.4 Tree Traversal 780
17.5 Red-Black Trees 786
17.6 Heaps 793
17.7 The Heapsort Algorithm 804

Chapter 18 Generic classes 819

18.1 Generic Classes and Type Parameters 820


18.2 Implementing Generic Types 821
18.3 Generic Methods 825
18.4 Constraining Type Parameters 827
18.5 Type Erasure 831

Chapter 19 Graphical User Interfaces 841

19.1 Layout Management 842


19.2 Processing Text Input 846
19.3 Choices 852
19.4 Menus 863
19.5 Exploring the Swing Documentation 869

Chapter 20 Streams and Binary Input/Output 881

20.1 Readers, Writers, and Streams 882


20.2 Binary Input and Output 883
20.3 Random Access 887
20.4 Object Streams 893

Chapter 21 Multithreading (WEB ONLY)

21.1 Running Threads


21.2 Terminating Threads
21.3 Race Conditions
21.4 Synchronizing Object Access
21.5 Avoiding Deadlocks
21.6 Application: Algorithm Animation

bj5_fm_05.indd 19 10/18/12 3:25 PM


xx Contents

Chapter 22 Internet Networking (WEB ONLY)

22.1 The Internet Protocol


22.2 Application Level Protocols
22.3 A Client Program
22.4 A Server Program
22.5 URL Connections

Chapter 23 Relational databases (WEB ONLY)

23.1 Organizing Database Information


23.2 Queries
23.3 Installing a Database
23.4 Database Programming in Java
23.5 Application: Entering an Invoice

Chapter 24 XML (WEB ONLY)

24.1 XML Tags and Documents


24.2 Parsing XML Documents
24.3 Creating XML Documents
24.4 Validating XML Documents

Chapter 25 Web Applications (WEB ONLY)

25.1 The Architecture of a Web Application


25.2 The Architecture of a JSF Application
25.3 JavaBeans Components
25.4 Navigation Between Pages
25.5 JSF Components
25.6 A Three-Tier Application

Appendices

Appendix A THE BASIC LATIN AND LATIN-1 SUBSETS OF UNICODE A-1


Appendix B JAVA Operator Summary A-5
Appendix C JAVA Reserved Word Summary A-7
Appendix D THE JAVA LIBRARY A-9
Appendix E JAVA SYNTAX SUMMARY A-53
Appendix F TOOL SUMMARY A-64
Appendix G NUMBER SYSTEMS A-68
Appendix H UML SUMMARY A-76

bj5_fm_06.indd 20 11/6/12 9:23 PM


Another Random Scribd Document
with Unrelated Content
The other example in the text seems still less relevant. Fear tends to accelerate
the peristaltic motion, therefore there is a connection between certain states of
the intestines and terrible ideas. To make this available for the author’s purpose,
the consequence of the connection ought to be, that acceleration of the peristaltic
motion excites ideas of terror. But does it? The state of indigestion characteristic of
hypochondria is not looseness of the bowels, but is commonly attended with the
exact opposite. The author’s usual acuteness of discernment seems to have been,
in these cases, blunted by an unwillingness to admit the possibility that ideas as
well as sensations may be directly affected by material conditions. But if, as he
admits, ideas have a direct action on our bodily organs, a prima facie case is made
out for the localization of our ideas, equally with our sensations, in some part of
our bodily system; and there is at least no antecedent presumption against the
supposition that the action may be reciprocal—that as ideas sometimes derange
the organic functions, so derangements of organic functions may sometimes
modify the trains of our ideas by their own physical action on the brain and
nerves, and not through the associations connected with the sensations they
excite.—Ed.

103 In illustration of the fact, that sensations and ideas, which are
essential to some of the most important 104 operations of our minds,
serve only as antecedents to more important consequents, and are
themselves so 105 habitually overlooked, that their existence is
unknown, we may recur to the remarkable case which we have just
explained, of the ideas introduced by the sensations of sight. The
minute gradations of colour, which accompany varieties of extension,
figure, and distance, are insignificant. The figure, the size, the
distance, themselves, on the other hand, are matters of the greatest
importance. The first having introduced the last, their work is done.
The consequents remain the sole objects of attention, the
antecedents are forgotten; in the present instance, not completely;
in other instances, so completely, that they cannot be recognised.33
34
33 Perhaps the most remarkable case of sensations overlooked on their own
account, and considered only as a means of suggesting something else, is the
visual, or retinal, magnitude of objects seen by the eye. This is probably the most
delicate sensibility within the compass of the mind; and yet we habitually
disregard it for all things near us, and use it solely for perceiving real magnitude
as estimated by our locomotive and other members. The visual magnitude of a
table, or other article in a room, is never thought of for itself; although incessantly
fluctuating we never think of the fluctuations; we pass from these to the one
constant perception, named the true or real magnitude. It is only for remote
objects, as the sun and moon, the clouds, the distant hills, that the retinal
magnitude abides with us in its own proper character. In looking down a vista, we
may also be aroused to the feeling of retinal magnitude. For perspective drawing,
it is necessary that we should arrest the strong tendency to pass from the visible,
to the real, forms and dimensions of things.—B.
34 The reader, it may be hoped, is now familiar with the important psychological
fact, so powerfully grasped and so discerningly employed by Hartley and the
author of the Analysis,—that when, through the frequent repetition of a series of
sensations, the corresponding train of ideas rushes through the mind with extreme
rapidity, some of the links are apt to disappear from consciousness as completely
as if they had never formed part of the series. It has been a subject of dispute
among philosophers which of three things takes place in this case. Do the lost
ideas pass through the mind without consciousness? Do they pass consciously
through the mind and are they then instantly forgotten? Or do they never come
into the mind at all, being, as it were, overleaped and pressed out by the rush of
the subsequent ideas?

It would seem, at first sight, that the first and third suppositions involve
impossibilities, and that the second, therefore, is the only one which we are at
liberty to adopt. As regards the first, it may be said—How can we have a feeling
without feeling it, in other words, without being conscious of it? With regard to the
third, how, it may be asked, can any link of the chain have been altogether
absent, through the pressure of the subsequent links? The subsequent ideas are
only there because called up by it, and would not have arisen at all unless it had
arisen first, however short a time it may have lasted. These arguments seem
strong, but are not so strong as they seem.
In favour of the first supposition, that feelings may be unconsciously present,
various facts and arguments are adduced by Sir William Hamilton in his Lectures;
but I think I have shewn in another work, that the arguments are inconclusive,
and the facts equally reconcilable with the second of the three hypotheses. That a
feeling should not be felt appears to me a contradiction both in words and in
nature. But, though a feeling cannot exist without being felt, the organic state
which is the antecedent of it may exist, and the feeling itself not follow. This
happens, either if the organic state is not of sufficient duration, or if an organic
state stronger than itself, and conflicting with it, is affecting us at the same
moment. I hope to be excused for quoting what I have said elsewhere on this
subject (Examination of Sir William Hamilton’s Philosophy, ch. 15).

“In the case, for instance, of a soldier who receives a wound in battle, but in the
excitement of the moment is not aware of the fact, it is difficult not to believe that
if the wound had been accompanied by the usual sensation, so vivid a feeling
would have forced itself to be attended to and remembered. The supposition
which seems most probable is, that the nerves of the particular part were affected
as they would have been by the same cause in any other circumstances, but that,
the nervous centres being intensely occupied with other impressions, the affection
of the local nerves did not reach them, and no sensation was excited. In like
manner, if we admit (what physiology is rendering more and more probable) that
our mental feelings, as well as our sensations, have for their physical antecedents
particular states of the nerves; it may well be believed that the apparently
suppressed links in a chain of association, those which Sir William Hamilton
considers as latent, really are so; that they are not, even momentarily, felt; the
chain of causation being continued only physically, by one organic state of the
nerves succeeding another so rapidly that the state of mental consciousness
appropriate to each is not produced. We have only to suppose, either that a
nervous modification of too short duration does not produce any sensation or
mental feeling at all, or that the rapid succession of different nervous modifications
makes the feelings produced by them interfere with each other, and become
confounded in one mass. The former of these suppositions is extremely probable,
while of the truth of the latter we have positive proof. An example of it is the
experiment which Sir W. Hamilton quoted from Mr. Mill, and which had been
noticed before either of them by Hartley. It is known that the seven prismatic
colours, combined in certain proportions, produce the white light of the solar ray.
Now, if the seven colours are painted on spaces bearing the same proportion to
one another as in the solar spectrum, and the coloured surface so produced is
passed rapidly before the eyes, as by the turning of a wheel, the whole is seen as
white. The physiological explanation of this phenomenon may be deduced from
another common experiment. If a lighted torch, or a bar heated to luminousness,
is waved rapidly before the eye, the appearance produced is that of a ribbon of
light; which is universally understood to prove that the visual sensation persists for
a certain short time after its cause has ceased. Now, if this happens with a single
colour, it will happen with a series of colours: and if the wheel on which the
prismatic colours have been painted, is turned with the same rapidity with which
the torch was waved, each of the seven sensations of colour will last long enough
to be contemporaneous with all the others, and they will naturally produce by their
combination the same colour as if they had, from the beginning, been excited
simultaneously. If anything similar to this obtains in our consciousness generally
(and that it obtains in many cases of consciousness there can be no doubt) it will
follow that whenever the organic modifications of our nervous fibres succeed one
another at an interval shorter than the duration of the sensations or other feelings
corresponding to them, those sensations or feelings will, so to speak, overlap one
another, and becoming simultaneous instead of successive, will blend into a state
of feeling, probably as unlike the elements out of which it is engendered, as the
colour white is unlike the prismatic colours. And this may be the source of many of
those states of internal or mental feeling which we cannot distinctly refer to a
prototype in experience, our experience only supplying the elements from which,
by this kind of mental chemistry, they are composed. The elementary feelings may
then be said to be latently present, or to be present but not in consciousness. The
truth, however, is that the feelings themselves are not present, consciously or
latently, but that the nervous modifications which are their usual antecedents have
been present, while the consequents have been frustrated, and another
consequent has been produced instead.”

In this modified form, therefore, the first of the three hypotheses may possibly
be true. Let us now consider the third, that of the entire elision of some of the
ideas which form the associated train. This supposition seemed to be inadmissible,
because the loss of any link would, it was supposed, cause the chain itself to
break off at that point. To make the hypothesis possible, it is only, however,
necessary to suppose, that, while the association is acquiring the promptitude and
rapidity which it ultimately attains, each of the successive ideas abides for a brief
interval in our consciousness after it has already called up the idea which is to
succeed it. Each idea in the series, though introduced, not by synchronous, but by
successive association, is thus, during a part of its continuance, synchronous with
the idea which introduced it: and as the rapidity of the suggestions increases by
still further repetition, an idea may become synchronous with another which was
originally not even contiguous to it, but separated from it by an intervening link; or
may come into immediate instead of mediate sequence with such an idea. When
either of these states of things has continued for some time, a direct association of
the synchronous or of the successive kind will be generated between two ideas
which are not proximate links in the chain; A will acquire a direct power of exciting
C, independently of the intervening idea B. If, then, B is much less interesting than
C, and especially if B is of no importance at all in itself, but only by exciting C, and
has therefore nothing to make the mind dwell on it after C has been reached, the
association of A with C is likely to become stronger than that of A with B: C will be
habitually excited directly by A; as the mind runs off to the further ideas
suggested by C, B will cease to be excited at all; and the train of association, like a
stream which breaking though its bank cuts off a bend in its course, will
thenceforth flow in the direct line AC, omitting B. This supposition accounts more
plausibly than either of the others for the truly wonderful rapidity of thought, since
it does not make so large a demand as the other theories on our ability to believe
that a prodigious number of different ideas can successively rush through the
mind in an instant too short for measurement.

The result is, that all the three theories of this mental process seem to be quite
possible; and it is not unlikely that each of them may be the real process in some
cases, either in different persons, or in the same persons under different
circumstances. I can only remit the question to future psychologists, who may be
able to contrive crucial experiments for deciding among these various possibilities.
—Ed.

106 11. Mr. Hume, and after him other philosophers, have said that
our ideas are associated according to 107 three principles; Contiguity
in time and place, Causation, and Resemblance. The Contiguity in
time and 108 place, must mean, that of the sensations; and so far it
is affirmed, that the order of the ideas follows that 109 of the
sensations. Contiguity of two sensations in time, means the
successive order. Contiguity of two 110 sensations in place, means
the synchronous order. We have explained the mode in which ideas
are associated, in the synchronous, as well as the successive order,
and have traced the principle of contiguity to its proper source.

Causation, the second of Mr. Hume’s principles, is the same with


contiguity in time, or the order of succession. Causation is only a
name for the order established between an antecedent and a
consequent; that is, the established or constant antecedence of the
one, 111 and consequence of the other. Resemblance only remains,
as an alleged principle of association, and it is necessary to inquire
whether it is included in the laws which have been above
expounded. I believe it will be found that we are accustomed to see
like things together. When we see a tree, we generally see more
trees than one; when we see an ox, we generally see more oxen
than one; a sheep, more sheep than one; a man, more men than
one. From this observation, I think, we may refer resemblance to the
law of frequency, of which it seems to form only a particular case.35
35 The reason assigned by the author for considering association by
resemblance as a case of association by contiguity, is perhaps the least successful
attempt at a generalisation and simplification of the laws of mental phenomena, to
be found in the work. It ought to be remembered that the author, as the text
shows, attached little importance to it. And perhaps, not thinking it important, he
passed it over with a less amount of patient thought than he usually bestowed on
his analyses.

Objects, he thinks, remind us of other objects resembling them, because we are


accustomed to see like things together. But we are also accustomed to see like
things separate. When two combinations incompatible with one another are both
realised in familiar experience, it requires a very great preponderance of
experience on one side to determine the association specially to either. We are
also much accustomed to see unlike things together; I do not mean things
contrasted, but simply unlike. Unlikeness, therefore, not amounting to contrast,
ought to be as much a cause of association as likeness. Besides, the fact that
when we see (for instance) a sheep, we usually see more sheep than one, may
cause us, when we think of a sheep, to think of an entire flock; but it does not
explain why, when we see a sheep with a black mark on its forehead, we are
reminded of a sheep with a similar mark, formerly seen, though we never saw two
such sheep together. It does not explain why a portrait makes us think of the
original, or why a stranger whom we see for the first time reminds us of a person
of similar appearance whom we saw many years ago. The law by which an object
reminds us of similar objects which we have been used to see along with it, must
be a different law from that by which it reminds us of similar objects which we
have not been used to see along with it. But it is the same law by which it reminds
us of dissimilar objects which we have been used to see along with it. The sight of
a sheep, if it reminds us of a flock of sheep, probably by the same law of
contiguity, reminds us of a meadow; but it must be by some other law that it
reminds us of a single sheep previously seen, and of the occasion on which we
saw that single sheep.

The attempt to resolve association by resemblance into association by contiguity


must perforce be unsuccessful, inasmuch as there never could have been
association by contiguity without a previous association by resemblance. Why does
a sensation received this instant remind me of sensations which I formerly had (as
we commonly say), along with it? I never had them along with this very sensation.
I never had this sensation until now, and can never have it again. I had the former
sensations in conjunction not with it, but with a sensation exactly like it. And my
present sensation could not remind me of those former sensations unlike itself,
unless by first reminding me of the sensation like itself, which really did coexist
with them. There is thus a law of association anterior to, and presupposed by, the
law of contiguity: namely, that a sensation tends to recall what is called the idea of
itself, that is, the remembrance of a sensation like itself, if such has previously
been experienced. This is implied in what we call recognising a sensation, as one
which has been felt before; more correctly, as undistinguishably resembling one
which has been felt before. The law in question was scientifically enunciated, and
included, I believe for the first time, in the list of Laws of Association, by Sir
William Hamilton, in one of the Dissertations appended to his edition of Reid: but
the fact itself is recognised by the author of the Analysis, in various passages of
his work; more especially in the second section of the fourteenth chapter. There is,
therefore, a suggestion by resemblance—a calling up of the idea of a past
sensation by a present sensation like it—which not only does not depend on
association by contiguity, but is itself the foundation which association by
contiguity requires for its support.

When it is admitted that simple sensations remind us of one another by direct


resemblance, many of the complex cases of suggestion by resemblance may be
analysed into this elementary case of association by resemblance, combined with
an association by contiguity. A flower, for instance, may remind us of a former
flower resembling it, because the present flower exhibits to us certain qualities,
that is, excites in us certain sensations, resembling and recalling to our
remembrance those we had from the former flower, and these recall the entire
image of the flower by the law of association by contiguity. But this explanation,
though it serves for many cases of complex phenomena suggesting one another
by resemblance, does not suffice for all. For, the resemblance of complex facts
often consists, not solely, or principally, in likeness between the simple sensations,
but far more in likeness of the manner of their combination, and it is often by this,
rather than by the single features, that they recall one another. After we had seen,
and well observed, a single triangle, when we afterwards saw a second there can
be little doubt that it would at once remind us of the first by mere resemblance.
But the suggestion would not depend on the sides or on the angles, any or all of
them; for we might have seen such sides and such angles uncombined, or
combined into some other figure. The resemblance by which one triangle recalls
the idea of another is not resemblance in the parts, but principally and
emphatically in the manner in which the parts are put together. I am unable to see
any mode in which this case of suggestion can be accounted for by contiguity; any
mode, at least, which would fit all cases of the kind.—Ed.

112 Mr. Hume makes contrast a principle of association, but not a


separate one, as he thinks it is compounded 113 of Resemblance and
Causation. It is not necessary for us to show that this is an
unsatisfactory account 114 of contrast. It is only necessary to
observe, that, as a case of association, it is not distinct from those
which we have above explained.

A dwarf suggests the idea of a giant. How? We call a dwarf a


dwarf, because he departs from a certain standard. We call a giant a
giant, because he departs from the same standard. This is a case,
therefore, of resemblance, that is, of frequency.

Pain is said to make us think of pleasure; and this is considered a


case of association by contrast. There is no doubt that pain makes
us think of relief from it; because they have been conjoined, and the
great vividness of the sensations makes the association strong.
Relief from pain is a species of pleasure; and one pleasure leads to
think of another, from the resemblance. This is a compound case,
therefore, of vividness and frequency. All other cases of contrast, I
believe, may be expounded in a similar manner.

I have not thought it necessary to be tedious in expounding the


observations which I have thus stated; for whether the reader
supposes that resemblance is, or is not, an original principle of
association, will not affect our future investigations.

12. Not only do simple ideas, by strong association, run together,


and form complex ideas: but a 115 complex idea, when the simple
ideas which compose it have become so consolidated that it always
appears as one, is capable of entering into combinations with other
ideas, both simple and complex. Thus two complex ideas may be
united together, by a strong association, and coalesce into one, in
the same manner as two or more simple ideas coalesce into one.
This union of two complex ideas into one, Dr. Hartley has called a
duplex idea.37 Two also of these duplex, or doubly compounded
ideas, may unite into one; and these again into other compounds,
without end. It is hardly necessary to mention, that as two complex
ideas unite to form a duplex one, not only two, but more than two
may so unite; and what he calls a duplex idea may be compounded
of two, three, four, or any number of complex ideas.
37 I have been unable to trace in Hartley the expression here ascribed to him.
In every passage that I can discover, the name he gives to a combination of two
or more complex ideas is that of a decomplex idea.—Ed.

Some of the most familiar objects with which we are acquainted


furnish instances of these unions of complex and duplex ideas.

Brick is one complex idea, mortar is another complex idea; these


ideas, with ideas of position and quantity, compose my idea of a
wall. My idea of a plank is a complex idea, my idea of a rafter is a
complex idea, my idea of a nail is a complex idea. These, united with
the same ideas of position and quantity, compose my duplex idea of
a floor. In the same manner my complex idea of glass, and wood,
and others, compose my duplex idea of a window; and 116 these
duplex ideas, united together, compose my idea of a house, which is
made up of various duplex ideas. How many complex, or duplex
ideas, are all united in the idea of furniture? How many more in the
idea of merchandize? How many more in the idea called Every
Thing?38 39
38 This chapter raises questions of the most fundamental kind relating to our
intellectual constitution. The Association of Ideas, comprehensively viewed,
involves everything connected with the mental persistence and reproduction of
ideas; being offered as adequate to explain the operations named Memory,
Reason, and Imagination.

Conditions of the Growth of Association, or of the Retentiveness of the Mind.—A


practical, as well as a theoretical, interest attaches to the precise statement of the
conditions or circumstances that regulate the growth of our associations, in other
words our mental culture generally. All agree in the efficacy of the two conditions
mentioned in the text; the vividness of the feelings associated, and the frequency
of the association, that is repetition or practice. It is well remarked, however, that
the phrase “vividness of the sensations or ideas” does not convey a very precise
meaning. The proper attribute of a sensation, or an idea, considered as an
intellectual element, is greater or less distinctness; when an object seen or
remembered is seen or remembered distinctly and fully, and without any unusual
labour or effort, there is nothing more to be desired, so far as concerns our
intelligence. If, however, the object is accompanied with feeling—with pleasure or
pain—a new element is introduced, to which other epithets are applicable. A
feeling is more or less strong or intense; and the addition of an intense feeling to
an intellectual conception is a sum, combining both sets of attributes—distinctness
and adequacy in the conception, and intensity in the feeling. An object whose
perception or conception is thus accompanied with the animation of strong feeling,
is called lively, or vivid; 117 in the absence of feeling, these epithets are
unsuitable. Hence, the associating stimulus expressed by “vividness” is better
expressed by the “strength of the feelings.” Any strong feeling impresses on the
mind whatever is the object of it, or is in any way mixed up with it. We remember
by preference the things that have given us either pleasure or pain; and the effect
may be produced by mere excitement although neither pleasurable nor painful;
the influence of a surprise being a case in point. Our interest in a thing is but
another name for the pleasure that it gives us; and to inspire interest is to aid the
memory. Hamilton’s Law of Preference refers to this source; and appears to
exclude, or not to recognise, the efficacy of feelings not pleasurable, namely, such
as are either painful or neutral. The comprehensive law should include all the
feelings, although there are specific characters attaching to the influence of each
of the three modes. Pleasure is the most effectual in stamping the memory, as it is
the most powerful in detaining the attention and the thoughts. Pain has a
conflicting operation; as affecting the will, it repels the object; but as mere
excitement it retains it; we cannot forget what is disagreeable, merely because we
wish to forget it. The stimulant of pain, as applied in education, is an indirect
pleasure. It is not intended to make the subject of the lesson disagreeable, but to
render painful all diversions from that towards other subjects; so that
comparatively the most pleasing course to a pupil may be to abide by the task
prescribed.

The influence of the Feelings upon Retentiveness is not throughout in proportion


to their degree, whether they are pleasurable, painful, or neutral. We have to
introduce a modifying circumstance into the case, namely, that great strength of
feeling absorbs the forces of the system, and diminishes the power available for
cementing an intellectual association. A strong feeling once aroused, while
inflaming the attention upon whatever is bound up with it, necessarily engages us
with itself. The plastic process of fixing a train or aggregate of ideas has but a
share of the energies awakened under feeling.

It is possible also to stimulate attention, and thereby to 118 quicken memory,


without the excitement of the feelings, as in pure voluntary attention. For although
the will, in the last resort, is stimulated by an end (which must involve the
feelings), yet we may be strongly moved without being under the excitement of
the feelings that enter into the final end. Our volitions may be energetic, without
the presence of strong emotions, notwithstanding that, apart from our possessing
such emotions, we should not be strongly moved to action. Thus, a difference is
made between the influence of the feelings and the influence of the will; both
being powers to impress the memory.

The two considerations now advanced, namely, the want of strict concomitance
between strength of feeling and the stimulus to memory, and the operation of the
will in the abeyance of present feeling, make it desirable to find some other mode
of stating the element or condition that qualifies the influence of Frequency or
Repetition, in the growth of memory and association. Perhaps the best mode of
singling out the operative circumstance is to describe it as “Concentration of
Mind;” the devotion of the mental forces to the thing to be done or remembered—
the withdrawal of power from other exercises, to expend it on the exercise in
hand. Every circumstance that at once rouses the mental and nervous energies,
and keeps them fixed upon any subject of study or the practice of any art, is a
circumstance in aid of acquisition. No fact more comprehensive, more exactly in
point, can be assigned than the one now stated. What remains is to apply it in the
detail, or to point out the occasions and conditions that favour, and those that
obstruct, the concentration of the mental energy. It is under this view that we can
best appreciate the efficacy of pleasure (interest in the subject), of pain, of mere
excitement, and of voluntary attention. We can also see, as an obvious corollary,
the advantage of having the mind unoccupied, or disengaged for the work, and
the disadvantage of being diverted, or distracted by other objects. Fear, care,
anxiety, are hostile to culture by lowering the tone or energy of the mind; while
what power is left concentrates itself upon the subject matter of the anxious
feeling. On the other hand, general vigour of the 119 system, good health, easy
circumstances, are all in favour of mental improvement, provided the force thus
made available can be reserved and devoted to that end.
Thus the two leading conditions of the plastic process are Frequency of
Repetition, and Mental Concentration. For practical purposes, these are all that we
need to consider, at least as regards the same individual. We have no art or device
for training either body or mind but what is comprised under one or other of these
heads. There are methods of superseding the labour of new acquirement, by
adapting existing acquirements to new cases; but no means can be assigned for
the original construction of adhesive links, apart from these two circumstances.

Still, in a large and exhaustive view of the Retentive power of the mind, we
should not omit to allow for the differences between one mind and another in
respect of Natural Aptitude for acquiring. When two persons engaged in the same
lesson, for equal periods of time, and with about equal concentration of mind,
make very unequal progress, we must admit a difference in natural or
constitutional plasticity on that particular subject. Sometimes we find extraordinary
progress made in acquisition generally; the same person excelling in languages, in
sciences, in practical arts, and in fine arts. More commonly, however, we find an
aptitude for some subject in particular, combined with deficiency in other things.
One person has great mechanical acquirements, another lingual, and so on.

The first case is sufficiently common to justify the assumption of degrees of


acquisitive or plastic aptitude on the whole, or a variety in the cerebral endowment
corresponding to the adhesion of trains of actions and ideas that have been more
or less frequently brought together. If the differences among human beings are
not so broad as to make this apparent, we may refer to the differences between
the lower animals and man. The animals have the power of acquiring, but so
limited is that power in comparison with human beings, that people have often
doubted its existence.

120 The second case, the inequality of the same person’s progress in different
subjects, may be looked at in another way. We may view it as incident to the
better or worse quality, for all purposes, of the special organs concerned. Thus to
take musical acquisition. This is commonly attributed to a good ear, meaning a
delicate sense of musical notes, as shown in their nice discrimination.
Discriminating is a different function from remembering; yet, we can only doubt
that the fact of being able to discriminate acutely is accompanied by the power of
remembering or retaining the impressions of the sense. The superiority of
endowment that shows itself in the one function, embraces also the other. Hence
we are entitled to say that the special retentiveness for any one subject, or
department of training, varies with the local endowment involved: which is not to
maintain an identical proposition, for the local endowment may be held as tested
by delicacy of discrimination, a distinct fact from memory. Thus, a delicate sense
of shades of colour would entail a good visual memory for spectacle; a delicate ear
for articulation would indicate a memory for shades and varieties of pronunciation,
thereby counting as a part of the verbal memory. So, delicate discrimination in the
tactile muscles would be followed by rapid acquirements in manipulative or manual
art.

The Ultimate Analysis of the Laws of Association.—It is easy to reduce all the
laws ever assigned, as governing the reproduction of our ideas, to three,
Contiguity, Similarity, and Contrast. It is open to question whether these can be
resolved any farther. The author has endeavoured to reduce Similarity to
Contiguity, but his reasons show that he had not deeply considered the workings
of similarity. Hamilton’s criticisms on the attempt (Reid, p. 914) are just and
irrefragable. By far the most important examples of the working of similarity are
such as, by their very nature, preclude a former contiguity: as, for example,
Franklin’s identification of Electricity and lightning.

There is, nevertheless, a considerable degree of subtlety in the relationship of


the two principles. There may be good reasons 121 for treating them as distinct,
but in their working they are inextricably combined. There can be no contiguity
without similarity, and no similarity without contiguity. When, looking at a river, we
pronounce its name, we are properly said to exemplify contiguity; the river and
the name by frequent association are so united that each recalls the other. But
mark the steps of the recall. What is strictly present to our view is the impression
made by the river while we gaze on it. It is necessary that this impression should,
by virtue of similarity or identity, re-instate the previous impression of the river, to
which the previous impression of the name was contiguous. If one could suppose
failure in the re-instatement of the former idea of the river, under the new
presentation, there would be no opportunity given to the contiguous bond to come
into operation. In that accumulation of the impressions of contiguous ideas,
ending at last in a firm association, there must be a process of similarity to the
extent of reviving the sum of the past at the instance of the present. This is a case
of similarity that we give little heed to, because it is sure and unfailing; we
concern ourselves more with what is liable to uncertainty, the acquired strength of
the contiguous adhesion. Yet it strictly comes under the case of reproduction
through similarity.

Consider again, what may be called a case of Similarity proper, as when a


portrait recalls the original. The sensuous effects possessed in common by the
portrait and by its subject bring about a restoration of the idea of the subject, in
spite of certain differences or discrepancies. The interest of this case is owing to
the fact that a partial likeness, a likeness in unlikeness, will often reproduce a past
idea; thus enabling us to assemble in the mind a number of things differing in
some respects because they agree in other respects. This is not identifying a thing
with itself, viewed at a former time, but assimilating one thing with other things
placed far asunder in nature, and having many features of difference.

Let us try and express the consecutive steps of this case of reproduction. The
thing now present to the mind has certain 122 peculiarities in common with one or
more things formerly present; as when, in a portrait, the outline and colouring
resembles a subject original. These sensible effects make alive the previous
recurrence of them, or put us in the cerebral and mental attitude formerly
experienced by the corresponding effects of the resembling object. We are aware,
by the liveliness of our impression, that we have gone in upon an old track; we
have the peculiar consciousness called the consciousness of Identity or
Agreement. This is one step, but not the whole. In order that the complete
restoration may be effected, the features of community must be in such firm
contiguous alliance with the features of difference—the special part of the previous
subject that the one shall reinstate the idea of the other. The points common to a
present portrait and a past original must be so strongly coherent with the
remaining features of the original, that the one cannot be awakened without the
other following. Here, then, in the very heart of Similarity, is an indispensable
bond of Contiguity; showing that it is not possible for either process to be
accomplished in separation from the other. The mutual coherence of parts, now
described as essential to reproduction, may be too weak for the purpose, and the
recovering stroke of similarity will in that case fail.

It might, therefore, be supposed that Similarity is, after all, but a mode of
Contiguity, namely, the contiguity or association of the different features or parts
of a complex whole. The inference is too hasty. Because contiguity is a part of the
fact of the restoration of similars, it is not the entire fact. There is a distinct and
characteristic step preceding the play of this mutual coherence of the parts of the
thing to be recovered. The striking into the former track of the agreeing part of
the new and the old, is a mental movement by itself, which the other follows, but
does not do away with. The effect above described, as the consciousness of
agreement or identity, the flash of a felt similarity, is real and distinct. We are
conscious of it by itself; there are occasions when we have it without the other,
that is to say, without the full re-instatement of the former 123 object in its
entireness. We often aware of an identity without being able to say what is the
thing identified; as when a portrait gives us the impression that we have seen the
original, without enabling us to say who the original is. We have been affected by
the stroke of identity or similarity; but the restoration fails from the feebleness of
the contiguous adherence of the parts of the object identified. There is thus a
genuine effect of the nature of pure similarity, or resemblance, and a mode of
consciousness accompanying that effect; but there is not the full energy of
reproduction without a concurring bond of pure contiguity. A portrait may fail to
give us the consciousness of having ever seen the original. On the supposition that
we have seen the original, this would be a failure of pure similarity.

Thus in every act of reproducing a past mental experience, there is a


complication, involving both contiguity proper and similarity proper. When the
similarity amounts to identity, as when a new impression of a thing puts us in the
track of the old impressions of the same thing, the effect is so sure, so obvious, so
easily arrived at, that we do not need to think of it, to make a question of it. It
does not prevent us from regarding the operation of recalling a name when we
see the thing, or recalling a thing when we hear the name, as pure contiguity. The
strength of the coherence may be deficient, and the restoration may fail on this
account; it can never fail on account of insufficient similarity. No inconvenience will
arise from speaking of this case as if it were Contiguity and nothing else.

The situation of Similarity in Diversity is quite distinct. The diversity obstructs


the operation of similarity; we cannot be sure that the new shall put us on the
track of the old. It is always a question whether such similarities shall be felt at all;
whether we shall experience the flash, the peculiar consciousness, of agreement in
difference. It is a farther question, whether the internal coherence of the thing
identified is enough to restore it in completeness. This last step may be allowed to
be a case of proper contiguity; while the flash of identity struck between a present
and a past, never coupled in the 124 mind before, is an effect sui generis, and not
resolvable into any mode or incident of contiguity.
The circumstances of this identifying stroke are so numerous and far-reaching
as to demand a special exemplification. Some of the broadest distinctions of
intellectual character can be grounded on the distinctive aptitudes of the mind for
Contiguity and for Similarity.

Learning, Acquisition, Memory, Habit, all designate the plastic adherence of


contiguous impressions. The processes of Classification, Reasoning, Imagination,
and the Inventive faculty generally, depend upon the identifying stroke of likeness
in unlikeness. Some forms of intellectual strength, as a whole, are best
represented by a highly energetic Adhesiveness; distinction as a learner, a follower
of routine, turns upon this power. Other, and higher, forms of intelligence depend
upon far-reaching strokes of similarity; the identification of likeness shrouded in
diversity, expresses much of the genius of the poet, the philosopher, the man of
practice.

There remains the consideration of Contrast, as a link of association. It is easy


to show that both Contiguity and Similarity may enter into the association of
contrasts. All contrasts that we are interested in are habitually coupled in
language, as light and dark, heat and cold, up and down, life and death. Again
contrasts suppose a common genus, that is a generic similarity; at least until we
ascend to the highest contrast of all, the subject mind, and the object or extended
world. Cold and Hot are grades of the common attribute called Temperature. As
these links of contiguity and similarity are present, and of considerable strength,
they practically lead to the mutual suggestion of contrasting things.

Still, we cannot overlook the deeper circumstance that in contrast there is


relation, and therefore mutual implication, so that the two members must always
be virtually present, although they are not equally attended to. Heat has no
meaning, no existence, but as a change from cold; the north implicates the south.
We have two modes of regarding these relationships, which are distinguished by
language, as if we 125 could abstract the one side from the other; that is, we
think of heat apart from cold, and of the north apart from the south. But if one
side is present, both must be present, and nothing is wanted but a motive, to
make us reverse the conception, and bring into prominence the side that was in
abeyance, cold instead of heat, south instead of north.

This view of Contrast is variously expressed by Hamilton. (Reid, Note D * * *).


Contrast, therefore, as an associating link, would draw from three sources,
Relativity, Contiguity, and Similarity. It would also be heightened, in many
instances, by the presence of strong feelings or emotions, as in the contemplation
of startling changes, and the vicissitudes of things. Being one of the effects
habitually introduced in Art and in Oratory, we are more than ordinarily impressed
by the things so made use of—infancy beside old age, squalor following on
splendour, abasement succeeding to elevation.

The associating principle of Contrast cannot be put forward as a basis of


distinction in intellectual character. There is no such a thing as a special aptitude
for Contrasts. There may be, in certain minds given to emotion, a fondness for the
impressive or emotional contrasts; but there is no intellectual gift, subsisting apart
from other powers and rising and falling independently, for the mutual recall of
contrasting qualities. Whenever we feel a difference we make a contrast; the two
differing things, are contrasting things, and are both known in one indivisible act
of thought. To be unable to bring up the contrast of a subject present to the view,
is not to know the subject; we cannot possess intelligently the conception of “up,”
and be oblivious to, or incapable of remembering, “down.” Forgetfulness in this
department is not the snapping of a link, as in Contiguity, or the dulness that
cannot reach a similitude; it is the entire blank of conception or knowledge. The
north pole of a magnet cannot be in the view, and the south pole in oblivion.—B.
39
The author and Mr. Bain agree in rejecting Contrast as an independent
principle of association. I think they might 126 have gone further, and denied it
even as a derivative one. All the cases considered as examples of it seem to me to
depend on something else. I greatly doubt if the sight or thought of a dwarf has
intrinsically any tendency to recall the idea of a giant. Things certainly do remind
us of their own absence, because (as pointed out by Mr. Bain) we are only
conscious of their presence by comparison with their absence; and for a further
reason, arising out of the former, viz. that, in our practical judgments, we are led
to think of the case of their presence and the case of their absence by one and the
same act of thought, having commonly to choose between the two. But it does
not seem to me that things have any special tendency to remind us of their
positive opposites. Black does not remind us of white more than of red or green. If
light reminds us of darkness, it is because darkness is the mere negation, or
absence, of light. The case of heat and cold is more complex. The sensation of
heat recalls to us the absence of that sensation: if the sensation amounts to pain,
it calls up the idea of relief from it; that is, of its absence, associated by contiguity
with the pleasant feeling which accompanies the change. But cold is not the mere
absence of heat; it is itself a positive sensation. If heat suggests to us the idea of
the sensation of cold, it is not because of the contrast, but because the close
connection which exists between the outward conditions of both, and the
consequent identity of the means we employ for regulating them, cause the
thought of cold and that of heat to be frequently presented to us in contiguity.—
Ed.

127
CHAPTER IV.
NAMING .

“I endeavour, as much as I can, to deliver myself from those fallacies which we


are apt to put upon ourselves, by taking words for things. It helps not our
ignorance to feign a knowledge where we have none, by making a noise with
sounds without clear and distinct significations. Names made at pleasure, neither
alter the nature of things, nor make us understand them, but as they are signs of,
and stand for, determined ideas.”—Locke, Hum. Und. b. ii. ch. 13, § 18.

WE have now surveyed the more simple and obvious phenomena


of the human mind. We have seen, first, that we have SENSATIONS;
secondly, that we have IDEAS, the copies of those sensations; thirdly,
that those ideas are sometimes SIMPLE, the copies of one sensation;
sometimes COMPLEX, the copies of several sensations so combined as
to appear not several ideas, but one idea; and, fourthly, that we
have TRAINS of those ideas, or one succeeding another without end.

These are simple facts of our nature, attested by experience; and


my chief object in fixing upon them the attention of the reader has
been, to convey to him that accurate and steady conception of them,
which is requisite for the successful prosecution of the subsequent
inquiries.

128 After delineating the simple and elementary states of


consciousness, it follows, in order, that we should endeavour to
show what is contained in those that are complex. But in all the
more complicated cases of human consciousness something of the
process of Naming is involved. These cases, of course, cannot be
unfolded, till the artifice of Naming is made known. This, therefore,
is necessarily an intermediate inquiry; and one to which it is
necessary that we should devote a particular degree of attention.

There are two purposes, both of great importance, for which


marks of our ideas, and sensations; or signs by which they may be
denoted; are necessary. One of these purposes is, That we maybe
able to make known to others what passes within us. The other is,
That we may secure to ourselves the knowledge of what at any
preceding time has passed in our minds.

The sensations and ideas of one man are hidden from all other
men; unless they have recourse to some expedient for disclosing
them. We cannot convey to another man our sensations and ideas
directly. Our means of intercourse with other men are through their
senses exclusively. We must therefore choose some SENSIBLE OBJECTS,
as SIGNS of our inward feelings. If two men agree, that each shall use
a certain sensible sign, when one of them means to make known to
the other that he has a certain sensation, or idea, they, in this, and
in no other way, can communicate a knowledge of those feelings to
one another.

Almost all the advantages, which man possesses above the inferior
animals, arise from his power of acting in combination with his
fellows; and of accomplishing, by the united efforts of numbers,
what could 129 not be accomplished by the detached efforts of
individuals. Without the power of communicating to one another
their sensations and ideas, this co-operation would be impossible.
The importance, therefore, of the invention of signs, or marks, by
which alone that communication can be effected, is obvious.
Among sensible objects, those alone which are addressed to the
senses of seeing and hearing have sufficient precision and variety to
be adapted to this end. The language of Action, as it has been
called, that is, certain gesticulations and motions, has very generally,
especially among rude people, whose spoken language is scanty,
been found in use to indicate certain states, generally complicated
states, of mind. But, for precision, variety, and rapidity, the flexibility
of the voice presented such obvious advantages, not to mention that
visible signs must be altogether useless in the dark, that sounds,
among all the varieties of our species, have been assumed as the
principal medium by which their sensations and ideas were made
known to one another.

There can be little doubt that, of the two uses of marks,


Communicating our thoughts, and Recording them, the advantage of
the first would be the earliest felt; and that signs for Communicating
would be long invented, before any person would see the advantage
of Recording his thoughts. After the use of signs for Communication
had become familiar, it would not fail, in time, to appear that signs
might be employed for Recordation also; and that, from this use of
them, the highest advantages might be derived.

In respect to those advantages, the following particulars are to be


observed.

130 1. We cannot recall any idea, or train of ideas, at will.


Thoughts come into the mind unbidden. If they did not come
unbidden, they must have been in the mind before they came into it;
which is a contradiction. You cannot bid a thought come into the
mind, without knowing that which you bid; but to know a thought is
to have the thought: the knowledge of the thought, and the
thought’s being in the mind, are not two things but one and the
same thing, under different names.

If we cannot recall at pleasure a single idea, we are not less


unable to recall a train. Every person knows how evanescent his
thoughts are, and how impossible it is for him to begin at the
beginning of a past train, if it is not a train of the individual objects
familiar to his senses, and go on to the end, neither leaving out any
of the items which composed it, nor allowing any which did not
belong to it, to enter in.

2. It is most obvious that, by ideas alone, the events which are


passed, are to us any thing. If the objects which we have seen,
heard, smelt, tasted, and touched, left no traces of themselves; if
the immediate sensation were every thing, and a blank ensued when
the sensation ended, the past would be to us as if it had never been.
Yesterday would be as unknown as the months we passed in the
womb, or the myriads of years before we were born.

3. It is only by our ideas of the past, that we have any power of


anticipating the future. And if we had no power of anticipating the
future, we should have no principle of action, but the physical
impulses, which we have in common with the brutes. This great law
of our nature, the anticipation of the future from the 131 past, will be
fully illustrated in a subsequent part of this inquiry: at present, all
that is required is, the admission, which will probably not be refused,
of this general truth: That the order, in which events have been
observed to take place, is the order in which they are expected to
take place; that the order in which they have taken place is testified
to us only by our ideas; and that upon the correctness, with which
they are so testified, depends the faculty we possess of converting
the powers of nature into the instruments of our will; and of bringing
to pass the events which we desire.

4. But all this power depends upon the order of our ideas. The
importance, therefore, is unspeakable, of being able to insure the
order of our ideas; to make, in other words, the order of a train of
ideas correspond unerringly with a train of past sensations. We have
not, however, a direct command over the train of our ideas. A train
of ideas may have passed in our minds corresponding to events of
great importance; but that train will not pass again, unvaried, except
in very simple cases, without the use of expedients.

5. The difference between the occasions of our IDEAS, and the


occasions of our SENSATIONS, affords a resource for this purpose. Over
the occasions of our sensations; we have an extensive power. We
can command the smell of a rose, the hearing of a bell, the sight of
a tree, the sensation of heat or of cold, and so on. Over the
occasions of our ideas we have little or no direct power. Our ideas
come and go. There is a perpetual train of them, one succeeding
another; but we cannot will any link in that chain of ideas; each link
is determined by the foregoing; and every man knows, how
impossible 132 it is, by mere willing, to make such a train as he
desires. Thoughts obtrude themselves without his bidding; and
thoughts which he is in quest of will not arise.

By the power, however, which we have over the occasions of our


sensations, we can make sure of having a train of sensations exactly
the same as we have had before. This affords us the means of
having a train of ideas exactly the same as we have had before. If
we choose a number of sensible objects, and make use of them as
marks of our ideas, we can ensure any succession which we please
of the sensible objects; and, by the association between them and
the ideas, a corresponding succession of the ideas.

6. To one of the two sets of occasions, upon which Signs are thus
useful, evanescent Signs are the best adapted; permanent signs are
absolutely necessary for the other. For the purposes of speech, or
immediate communication, sounds are the most convenient marks.
Sounds, however, perish in the making. But for the purpose of
retracing a train of ideas, which we have formerly had, it is
necessary we should have marks which do not perish. Marks,
addressed to the sight, or the touch, have the requisite permanence;
and, of the two, those addressed to the eye have the advantage. Of
marks addressed to the eye, two kinds have been adopted; either
marks immediately of the ideas intended to be recalled; such as the
picture-writing, or hieroglyphics, of some nations: or, visible marks,
by letters, of the audible marks employed in oral communication.
This latter kind has been found the most convenient, and in use
among the largest, and most intelligent portion of our species.

133 According to this scheme, spoken language is the use of


immediate marks of the ideas; written language, is the use of
secondary marks of the ideas. The written marks are only signs of
the audible marks; the audible marks, are signs of the ideas.40
40 This exposition of Naming in its most general aspect, needs neither
explanation nor comment. It is one of those specimens of clear and vigorous
statement, going straight to the heart of the matter, and dwelling on it just long
enough and no longer than necessary, in which the Analysis abounds.—Ed.

134
SECTION I.
NOUNS SUBSTANTIVE .

The power of Language essentially consists, in two things; first, in


our having marks of our SENSATIONS, and IDEAS: and, secondly, in so
arranging them, that they may correctly denote a TRAIN of those
mental states or feelings. It is evident, that if we convey to others
the ideas which pass in our own minds, and also convey them in the
order in which they pass, the business of COMMUNICATION is
completed. And, if we establish the means of reviving the ideas
which we have formerly had, and also of reviving them in the order
in which we formerly had them, the business of RECORDATION is
completed. We now proceed to show, by what contrivances, the
expedient of Marking is rendered efficient to those several ends.

The primary importance to men, of being able to make known to


one another their SENSATIONS, made them in all probability begin with
inventing marks for that purpose; in other words, making Names for
their SENSATIONS. Two modes presented themselves. One was to give
a name to each single sensation. Another was to bestow a name on
a cluster of sensations, whenever they were such as occur in a
cluster. Of this latter class, are all names of what are called External
Objects; rose, water, stone, and so on. Each of these names is the
mark of as many sensations (sight, touch, smell, taste, sound) as we
are said to derive from those objects. The name rose, is the 135
mark of a sensation of colour, a sensation of shape, a sensation of
touch, a sensation of smell, all in conjunction. The name water, is
the mark of a sensation of colour, a sensation of touch, a sensation
of taste, and other sensations, regarded not separately, but as a
compound.41
41 It is not intended to be understood that all this complex meaning entered
into the names as originally given. The process of naming seems to have been
this: Each object was designated by a term expressive of some one prominent
quality, and of that only. Thus rose is referred with every probability to the same
root as the adjective red (compare Greek ῥόδον, a rose, ἑρυθρὸς red, German
roth, Latin rutilus), and thus meant “the ruddy” (flower). Other objects would
doubtless also be called “ruddy,” and would dispute the epithet with the rose; but
by a process of natural selection, each would settle down in possession of the
term found best suited to distinguish it; which would thus cease to be an
attributive, and become a name substantive with a complex connotation derived
from association. All names of objects whose origin can be traced are found to be
thus simple in their primary signification. The stars (Sans. staras) were so called
because they were “strewers” (of light).—F.

There is a convenience in giving a single mark to any number of


sensations, which we thus have in clusters; because there is hence a
great saving of marks. The sensations of sight, of touch, of smell,
and so on, derived from a rose, might have received marks, and
have been enumerated, one by one; but the term rose, performs all
this much more expeditiously, and also more certainly.

The occasions, however, are perpetual, on which we need marks


for sensations, not in clusters, but taken separately. And language is
supplied with 136 names of this description. We have the terms, red,
green, hot, cold, sweet, bitter, hard, soft, noise, stench, composing
in the whole a numerous class. For many sensations, however, we
have not names in one word; but make a name out of two or more
words: thus, for the sensation of hearing, derived from a trumpet,
we have only the name, “sound of a trumpet;” in the same manner,
we have “smell of a rose,” “taste of an apple,” “sight of a tree,”
“feeling of velvet.”

Of those names which denote clusters of sensations, it is obvious


(but still very necessary) to remark, that some include a greater,
some a lesser number of sensations. Thus, stone includes only
sensations of touch, and sight. Apple, beside sensations of touch
and sight, includes sensations of smell and taste.

We not only give names to clusters of sensations, but to clusters


of clusters; that is, to a number of minor clusters, united into a
greater cluster. Thus we give the name wood to a particular cluster
of sensations, the name canvas to another, the name rope to
another. To these clusters, and many others, joined together in one
great cluster, we give the name ship. To a number of these great
clusters united into one, we give the name fleet, and so on. How
great a number of clusters are united in the term House? And how
many more in the term City?

Sensations being infinitely numerous, all cannot receive marks or


signs. A selection must be made. Only those which are the most
important are named.

Names, to be useful, cannot exceed a certain number. They could


not otherwise be remembered. It is, therefore, of the greatest
importance that each name should accomplish as much as possible.
To this end, 137 the greater number of names stand, not for
individuals only, but classes. Thus the terms red, sweet, hot, loud,
are names, not of one sensation only, but of classes of sensations;
that is, every sensation of a particular kind. Thus also the term, rose,
is not the name of one single cluster, but of every cluster coming
under a certain description. As rose denotes one class, stone
denotes another, iron another, ox another, and so on.42
42 Economy in the use of names is a very small part of the motive leading to
the creation of names of classes. If we had a name for every individual object
which exists in the universe, and could remember all those names, we should still
require names for what those objects or some of them have in common; in other
words, we should require classification, and class names. This will be obvious if it
is considered that had we no names but names of individuals, we should not have
the means of making any affirmation respecting any object; we could not
predicate of it any qualities. But of this more largely in a future note.—Ed.

As we need marks for SENSATIONS, we need marks also for IDEAS.

The Ideas which we have occasion to name, are first, Simple


Ideas, the copies of simple sensations; secondly, Complex Ideas, the
copies of several sensations, combined. Of those complex ideas,
also, there is one species, those copied directly from sensations, in
the formation of which the mind has exercised but little control; as
the ideas of rose, horse, stone, and of what are called the objects of
sense in general. There is another species of complex ideas which,
though derived also from the senses, are put together in a great
degree at our discretion, as the ideas of a 138 centaur, a mountain of
gold, of comfort, of meanness; all that class of ideas in short which
Mr. Locke has called mixed modes.

We may thus distinguish three classes of ideas, which we have


occasion to name: 1, simple ideas, the copies of single sensations: 2,
complex ideas, copied directly from sensations: 3, complex ideas,
derived indeed from the senses, but put together in arbitrary
combinations. The two former classes may be called Sensible, the
last Mental Ideas.
With respect to ideas, of the first two classes, those which are the
direct copies of our sensations, either singly, or in groups; it is of
great importance to observe, and also to remember, that, for the
most part, the words, which are employed as marks of the
Sensations, are made to serve the further purpose of being marks
also of the Ideas. The same word is at once the name of the
sensations, and the ideas.

If any person were asked, whether the word BEING is the name of
a Sensation, or of an Idea; he would immediately reply, that it is the
name of an Idea. In like manner, if he were asked, whether the word
ANIMAL is the mark of a cluster of Sensations, or of a cluster of Ideas;
he would with equal readiness say, of a cluster of Ideas. But if we
were to ask, whether the name Sheep is the name of a cluster of
Sensations, or of a cluster of Ideas; he would probably say, that
Sheep is the name of Sensations; in the same manner as rose, or
apple. Yet, what is the difference? Only this, that ANIMAL is the more
general name, and includes sheep along with other species; and that
BEING is still more general, and includes animal along with vegetable,
mineral, and other 139 genera. If sheep, therefore, or stone, be a
name of sensations, so is animal or being; and if animal, or being,
be a name of ideas, so is sheep or stone a name of ideas. The fact
is, they are all names of both. They are names of the Sensations,
primarily; but are afterwards employed as names also of the Ideas
or copies of those sensations.

It thus appears, that the names generally of what are called the
objects of sense are equivocal; and whereas it would have been a
security against confusion to have been provided with appropriate
names, one, in each instance, for the Sensation, and one for the
Idea, the same name has been made to serve as the mark for both.
The term horse is not only made to stand for the sensations of sight,
of hearing, of touch, and even of smell, which give me occasion for
the use of the term horse; but it stands also for the ideas of those
sensations, as often as I have occasion to speak of that cluster of
ideas which compose my notion of a horse. The term tree denotes
undoubtedly the Idea in my mind, when I mean to convey the idea
tree into the mind of another man; but it also stands for the
sensations whence I have derived my idea of a tree.

Thus, too, if I mean to name my simple ideas; those, for example,


of sight; I have no other names than red, blue, violet, &c.; but all
these are names of the sensations. When forced to distinguish them,
I must use the awkward expressions, my sensation of red, my idea
of red. Again; sound of a trumpet, is the name, as well of the
sensation, as the idea; flight of a bird, the name, as well of the
sensation, as the idea; light the name as well of the sensation as the
idea; pain 140 the name as well of the sensation as the idea; heat
the name as well of the sensation as the idea.43
43 In strict propriety of language all these are names only of sensations, or
clusters of sensations; not of ideas. A person studious of precision would not, I
think, say heat, meaning the idea of heat, or a tree, when he meant the idea of a
tree. He would use heat as the name only of the sensation of heat, and tree as the
name of the outward object, or cluster of sensations; and if he had occasion to
speak of the idea, he would say, my idea (or the idea) of heat; my idea (or the
idea) of a tree.—Ed.

As we have remarked, in regard to SENSATIONS, singly, or in


clusters, that they are too numerous to receive names but in classes,
that is names common to every individual of a class, the same is
obviously true of the IDEAS. The greater number of names of Sensible
Ideas are names of classes: man is the name of a class; lion, horse,
eagle, serpent, and so on, are names of classes.
Ideas, of the third class, those which the mind forms arbitrarily,
are innumerable; because the combinations capable of being formed
of the numerous elements which compose them, exceed
computation. All these combinations cannot receive names. The
memory can manage but a moderate number. Of possible
combinations, therefore, a small proportion must be selected for
naming. These, of course, are the combinations which are suggested
by the occasions of life, and conduce to the ends which we pursue.

We arrange those ideas, also, in classes; to the end that every


name may serve the purpose of marking, as extensively as possible.
Thus the term fear is 141 applicable to a state of mind, of which the
instances form a class. In like manner, courage is the name of a
class; temperance, ignorance, piety, and so on, names of classes.
Republic, aristocracy, monarchy, are names, each of them, not of an
individual government, a government at one time and place, but of a
class, a sort of government, at any time and place.

The names of the ideas which are thus mentally clustered, are
exempt from that ambiguity which we saw belonged to the names of
both classes of sensible ideas. The names of sensible ideas generally
stand for the sensations as well as the ideas. The names of the
mental ideas are not transferable to sensations. But they are subject
to another uncertainty, still more fertile in confusion, and
embarrassment.

As the combinations are formed arbitrarily, or in other words, as


the ideas of which they are composed, are more or less numerous,
according to pleasure, and each man of necessity forms his own
combination, it very often happens, that one man includes
something more or something less than another man in the
combination to which they both give the same name. Using the
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookluna.com

You might also like