You are on page 1of 53

Big Java: Early Objects 7th Edition Cay

S. Horstmann
Visit to download the full and correct content document:
https://textbookfull.com/product/big-java-early-objects-7th-edition-cay-s-horstmann/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Starting Out with Java: From Control Structures through


Objects (What's New in Computer Science) 7th Edition
Gaddis

https://textbookfull.com/product/starting-out-with-java-from-
control-structures-through-objects-whats-new-in-computer-
science-7th-edition-gaddis/

Transitional Objects in Early Childhood; The Value of


Transitional Objects in the Early Years 1st Edition
Amanda Norman

https://textbookfull.com/product/transitional-objects-in-early-
childhood-the-value-of-transitional-objects-in-the-early-
years-1st-edition-amanda-norman/

Fodor s Big Island of Hawaii 7th Edition Fodor’S Travel


Guides

https://textbookfull.com/product/fodor-s-big-island-of-
hawaii-7th-edition-fodors-travel-guides/

Starting Out with Java: From Control Structures through


Objects (6th Edition) Gaddis

https://textbookfull.com/product/starting-out-with-java-from-
control-structures-through-objects-6th-edition-gaddis/
Java: A Beginner’s Guide 7th Edition Herbert Schildt

https://textbookfull.com/product/java-a-beginners-guide-7th-
edition-herbert-schildt/

Java For Dummies 7th Edition Barry A. Burd

https://textbookfull.com/product/java-for-dummies-7th-edition-
barry-a-burd/

Beginning Java 9 Fundamentals: Arrays, Objects,


Modules, JShell, and Regular Expressions Sharan

https://textbookfull.com/product/beginning-java-9-fundamentals-
arrays-objects-modules-jshell-and-regular-expressions-sharan/

Big Data Analytics with Java 1st Edition Rajat Mehta

https://textbookfull.com/product/big-data-analytics-with-
java-1st-edition-rajat-mehta/

Java Cookbook Problems and Solutions for Java


Developers Early Release Ian F. Darwin

https://textbookfull.com/product/java-cookbook-problems-and-
solutions-for-java-developers-early-release-ian-f-darwin/
7/e

Cay Horstmann

Big JavaEarly Objects


7/e

Big Java Early Objects

Cay Horstmann
San Jose State University

bjeo_fm.indd 1 11/27/18 1:36 PM


VICE PRESIDENT AND EXECUTIVE PUBLISHER Laurie Rosatone
EXECUTIVE EDITOR Joanna Dingle
PROJECT MANAGER/DEVELOPMENT EDITOR Cindy Johnson
EDITORIAL ASSISTANT Crystal Franks
LEAD PRODUCT DESIGNER Tom Kulesa
MARKETING MANAGER Michael MacDougald
PRODUCTION MANAGER Nichole Urban
PRODUCTION MANAGER Nicole Repasky
PRODUCTION MANAGEMENT SERVICES Cindy Johnson, Publishing Services
PHOTO EDITOR Anindita Adiyal
COVER DESIGNER Joanna Vieira
COVER PHOTOS (tiger) © ArtMediaFactory/Shutterstock;
(rhino) © GUDKOV ANDREY/Shutterstock;
(bird) © Jeremy Woodhouse/Holly Wilmeth/
Getty Images; (tree frog) © kuritafsheen/Getty
Images.

This book was set in 10.5/12 Stempel Garamond LT Std by Publishing Services, and printed and bound by Quad
Graphics/Versailles. The cover was printed by Quad Graphics/Versailles.

Founded in 1807, John Wiley & Sons, Inc. has been a valued source of knowledge and understanding for more
than 200 years, helping people around the world meet their needs and fulfill their aspirations. Our company is
built on a foundation of principles that include responsibility to the communities we serve and where we live
and work. In 2008, we launched a Corporate Citizenship Initiative, a global effort to address the environmental,
social, economic, and ethical challenges we face in our business. Among the issues we are addressing are carbon
impact, paper specifications and procurement, ethical conduct within our business and among our vendors,
and community and charitable support. For more information, please visit our website: www.wiley.com/go/
citizenship.

This book is printed on acid-free paper. ∞

Copyright © 2019, 2016 John Wiley & Sons, Inc. All rights reserved. No part of this publication may be repro-
duced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photo-
copying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United
States Copyright Act, without either the prior written permission of the Publisher, or authorization through
payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Dan-
vers, MA 01923, (978) 750-8400, fax (978) 646-8600, or on the Web at www.copyright.com. Requests to the
Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111
River Street, Hoboken, NJ 07030-5774, (201) 748-6011, fax (201) 748-6008.

Evaluation copies are provided to qualified academics and professionals for review purposes only, for use in
their courses during the next academic year. These copies are licensed and may not be sold or transferred to a
third party. Upon completion of the review period, please return the evaluation copy to Wiley. Return instruc-
tions and a free of charge return shipping label are available at: www.wiley.com/go/returnlabel. If you have
chosen to adopt this textbook for use in your course, please accept this book as your complimentary desk copy.
Outside of the United States, please contact your local representative.

ePUB ISBN 978-1-119-49909-1

Printed in the United States of America.

The inside back cover will contain printing identification and country of origin if omitted from this page. In
addition, if the ISBN on the back cover differs from the ISBN on this page, the one on the back cover is correct.

10 9 8 7 6 5 4 3 2 1

bjeo_fm.indd 2 11/27/18 1:36 PM


P R E FA C E

This book is an introduction to Java and computer programming that focuses on the
essentials—and on effective learning. The book is designed to serve a wide range of
student interests and abilities and is suitable for a first course in programming for
computer scientists, engineers, and students in other disciplines. No prior program-
ming experience is required, and only a modest amount of high school algebra is
needed.
Here are the key features of this book:
Start objects early, teach object orientation gradually.
In Chapter 2, students learn how to use objects and classes from the standard library.
Chapter 3 shows the mechanics of implementing classes from a given specification.
Students then use simple objects as they master branches, loops, and arrays. Object-
oriented design starts in Chapter 8. This gradual approach allows students to use
objects throughout their study of the core algorithmic topics, without teaching bad
habits that must be un-learned later.
Guidance and worked examples help students succeed.
Beginning programmers often ask “How do I start? Now what do I do?” Of course,
an activity as complex as programming cannot be reduced to cookbook-style instruc-
tions. However, step-by-step guidance is immensely helpful for building confidence
and providing an outline for the task at hand. “How To” guides help students with
common programming tasks. Numerous Worked Examples demonstrate how to
apply chapter concepts to interesting problems.
Problem solving strategies are made explicit.
Practical, step-by-step illustrations of techniques help students devise and evaluate
solutions to programming problems. Introduced where they are most relevant, these
strategies address barriers to success for many students. Strategies included are:
• Algorithm Design (with pseudocode) • Solve a Simpler Problem First
• Tracing Objects • Adapting Algorithms
• First Do It By Hand (doing sample • Discovering Algorithms by
calculations by hand) Manipulating Physical Objects
• Flowcharts • Patterns for Object Data
• Selecting Test Cases • Thinking Recursively
• Hand-Tracing • Estimating the Running Time of
• Storyboards an Algorithm

Practice makes perfect.


Of course, programming students need to be able to implement nontrivial programs,
but they first need to have the confidence that they can succeed. Each section con-
tains numerous exercises that ask students to carry out progressively more complex
tasks: trace code and understand its effects, produce program snippets from prepared
parts, and complete simple programs. Additional review and programming problems
are provided at the end of each chapter.

iii

bjeo_fm.indd 3 11/27/18 1:36 PM


iv Preface

A visual approach motivates the reader and eases navigation.


Photographs present visual analogies that explain the
nature and behavior of computer concepts. Step-by-

© Terraxplorer/iStockphoto.
step figures illustrate complex program operations.
Syntax boxes and example tables present a variety
of typical and special cases in a compact format. It
is easy to get the “lay of the land” by browsing the
visuals, before focusing on the textual material.
Focus on the essentials while being
technically accurate. Visual features help the reader
An encyclopedic coverage is not helpful for a begin- with navigation.
ning programmer, but neither is the opposite—
reducing the material to a list of simplistic bullet points. In this book, the essentials are
presented in digestible chunks, with separate notes that go deeper into good practices
or language features when the reader is ready for the additional information. You will
© Terraxplorer/iStockphoto.
not find artificial over-simplifications that give an illusion of knowledge.
Reinforce sound engineering practices.
A multitude of useful tips on software quality and common errors encourage the
development of good programming habits. The optional testing track focuses on
test-driven development, encouraging students to test their programs systematically.
Provide an optional graphics track.
Graphical shapes are splendid examples of objects. Many students enjoy writing pro-
grams that create drawings or use graphical user interfaces. If desired, these topics can
be integrated into the course by using the materials at the end of Chapters 2, 3, and 10.
Engage with optional science and business exercises.
End-of-chapter exercises are enhanced with problems from scientific and business
domains. Designed to engage students, the exercises illustrate the value of program-
ming in applied fields.

New to This Edition


Adapted to Java Versions 8 Through 11
This edition takes advantage of modern Java features when they are pedagogically
sensible. I continue to use “pure” interfaces with only abstract methods. Default,
static, and private interface methods are introduced in a Special Topic. Lambda
expressions are optional for user interface callback, but they are used in the chapter
on the stream library and its applications for “big data” processing.
The “diamond” syntax for generic classes is introduced as a Special Topic in Chap-
ter 7 and used systematically starting with Chapter 15. Local type inference with the
var keyword is described in a Special Topic.
Useful features such as the try-with-resources statement are integrated into the
text. Chapter 21 covers the utilities provided by the Paths and Files classes.

Interactive Learning
With this edition, interactive content is front and center. Immersive activities integrate
with this text and engage students in activities designed to foster in-depth learning.

bjeo_fm.indd 4 11/27/18 1:36 PM


Preface v

Students don’t just watch animations and code traces, they work on generating
them. Live code samples invite the reader to experiment and to learn programming
constructs first hand. The activities provide instant feedback to show students what
they did right and where they need to study more.

A Tour of the Book


The book can be naturally grouped into four parts, as illustrated by Figure 1 on
page vi. The organization of chapters offers the same flexibility as the previous
edition; dependencies among the chapters are also shown in the figure.

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. Chapter 9 covers inheritance and
polymorphism, 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–19)


Chapters 13 through 19 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. Finally, Chapter 19 introduces the Java 8 streams
library and shows how it can be used to analyze complex real-world data.

Part D: Applied Topics (Chapters 20–25)


Chapters 20 through 25 cover Java programming techniques that definitely go
beyond a first course in Java (21–25 are in the eText). 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 database and network

bjeo_fm.indd 5 11/27/18 1:36 PM


vi Preface

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 student projects. The
applied topics include graphical user-interface design, advanced file handling, multi-
threading, and those technologies that are of particular interest to server-side pro-
gramming: networking, databases, and XML. The Internet has made it possible to

1. Introduction

Fundamentals
2. Using Objects
Object-Oriented Design
Data Structures & Algorithms
Applied Topics
e eText Chapters
3. Implementing
Classes

4. Fundamental
Data Types

5. Decisions

6. Loops

Sections 11.1 and 11.2


(text file processing) can be 7. Arrays
covered with Chapter 6. 6. Iteration
and Array Lists

11. Input/Output 8. Designing


13. Recursion
and Exception Classes
Handling

21. Advanced 23. Internet 24. Relational 15. The Java 14. Sorting
9. Inheritance
e e e
Input/Output Networking Databases Collections and Searching
Framework

19. Stream
22. Processing
20. Graphical
25. XML 10. Interfaces
e e
User Interfaces Multithreading

16. Basic
12. Object- Data Structures
Oriented Design

Figure 1
Chapter 18. Generic 17. Tree
Classes Structures
Dependencies

bjeo_fm.indd 6 11/27/18 1:36 PM


Preface vii

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.

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

Interactive eText Designed for Programming Students


Available online through wiley.com, vitalsource.com, or at your local bookstore, the
enhanced eText features integrated student coding activities that foster in-depth
learning. Designed by Cay Horstmann, these activities provide instant feedback to
show students what they did right and where they need to study more. Students do
more than just watch animations and code traces; they work on generating them right
in the eText environment. For a preview of these activities, check out http://wiley.
com/college/sc/horstmann.
Customized formats are also available in both print and digital formats and pro-
vide your students with curated content based on your unique syllabus.
Please contact your Wiley sales rep for more information about any of these
options.

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

• Source code for all example programs in the book and its Worked Examples, plus
additional example programs.
• Worked Examples that apply the problem-solving steps in the book to other
realistic examples.
• 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.
• CodeCheck®, an innovative online service that allows instructors to design their
own automatically graded programming exercises.

bjeo_fm.indd 7 11/27/18 1:36 PM


viii Walkthrough

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.

6.3 The for Loop 183

6.3 The for Loop


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

Some people call this loop count-controlled. In con-


trast, the while loop of the preceding section can
be called an event-controlled loop because it exe-
cutes until an event occurs; namely that the balance
reaches 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 defi-
nite number of times; ten times in our example. In
© Enrico Fianchini/iStockphoto.
contrast, you do not know how many iterations it
takes to accumulate a target balance. Such a loop is You can visualize the for loop as
Annotated syntax boxes called indefinite. 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 Programming Tip 6.1.

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 Special Topic 6.1.
} See Programming Tip 6.3.

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.

bjeo_fm.indd 8 11/27/18 1:36 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 333

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 How To guides give step-by-step


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

Step 1 Decide what work must be done inside the loop. Worked Examples apply
Every loop needs to do some kind of repetitive work, such as
• Reading another item. the steps in the How To to a
• Updating a value (such as a bank balance or total).
WORKED EXAMPLE 6.1 different example, showing
• Incrementing a counter.
Credit Card Processing
If you can’t figure out what needs to go inside the loop, start by writing down the steps that how they can be used to
you would take if you
howsolved
to use the problem by hand. Forfrom
example, with the temperature reading
problem, you
Learn
might See
number. write
a loop to remove spaces a credit
your eText or visit wiley.com/go/bjeo7.
card
plan, implement, and test
© MorePixels/iStockphoto. 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
int width = "20"; Error: You cannot initialize a number with the string “20”.
(Note the quotation marks.) reference to the section’s topic.
int width; Declares an integer variable without initializing it. This can be a
cause for errors—see Common Error 2.1.
int width, height; Declares two integer variables in a single statement. In this
book, we will declare each variable in a separate statement.

bjeo_fm.indd 9 11/27/18 1:37 PM


x Walkthrough

Figure 3
Progressive figures trace code Execution of a
1 Initialize counter
for (int counter = 5; counter <= 10; counter++)
{
for Loop
segments to help students visualize counter = 5 }
sum = sum + counter;

the program flow. Color is used


consistently to make variables and
2 Check condition
for (int counter = 5; counter <= 10; counter++)
{

other elements easily recognizable. counter = 5 }


sum = sum + counter;

3 Execute loop body


for (int counter = 5; counter <= 10; counter++)
{
sum = sum + counter;
counter = 5 }

4 Update counter
for (int counter = 5; counter <= 10; counter++)
{
sum = sum + counter;
counter = 6 }
sec01/ElevatorSimulation.java
1 import java.util.Scanner; 5 Check condition again
for (int counter = 5; counter <= 10; counter++)
2 {
3 /** sum = sum + counter;
4 This program simulates an elevator panel that skips the 13th floor. counter = 6 }
5 */
6 public class ElevatorSimulation
7 {
8 public static void main(String[] args)
9 { The for loop neatly groups the initialization, condition, and update expressions
10 Scanner in = new Scanner(System.in); together. However, it is important to realize that these expressions are not executed
11 System.out.print("Floor: ");
together (see Figure 3).
12 int floor = in.nextInt();
13
• The initialization is executed once, before the loop is entered. 1
14 // Adjust floor if necessary
15 • The condition is checked before each iteration. 2 5
16 int actualFloor;
17 if (floor > 13) • The update is executed after each iteration. 4

Program listings are carefully


designed for easy reading, going
well beyond simple color coding.
Students can run and change the
same programs right in the eText.

Self-check exercises in the


eText are designed to engage
students with the new material
and check understanding before
they continue to the next topic.

•• Business E6.17 Currency conversion. Write a program


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.

Optional science and business • Science P6.15 Radioactive decay of radioactive materials can be
modeled by the equation A = A0e-t (log 2/h), where A is
exercises engage students with the amount of the material at time t, A0 is the amount
realistic applications of Java. at time 0, and h is the half-life.
Technetium-99 is a radioisotope that is used in imaging
of the brain. It has a half-life of 6 hours. Your program
should display the relative amount A / A0 in a patient
body every hour for 24 hours after receiving a dose.

bjeo_fm.indd 10 11/27/18 1:37 PM


Walkthrough xi

Common Errors describe the kinds Common Error 7.4

of errors that students often make, Length and Size


Unfortunately, the Java syntax for determining the number of elements in an array, an array
with an explanation of why the errors list, and a string is not at all consistent. It is a common error to confuse these. You just have to
remember the correct syntax for every data type.
occur, and what to do about them.
Data Type Number of Elements

Array a.length

Array list a.size()

String a.length()

Programming Tip 5.5


Hand-Tracing
A very useful technique for understanding whether a program
works correctly is called hand-tracing. You simulate the pro-
gram’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
Programming Tips explain 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
good programming practices, the current statement. In your mind, execute statements one at a
time. Every time the value of a variable changes, cross out the old
and encourage students to be value and write the new value below the old one.
For example, let’s trace the getTax method with the data from © thomasd007/iStockphoto.

more productive with tips and the program run above. When the TaxReturn object is constructed,
the income instance variable is set to 80,000 and status is set to
Hand-tracing helps you
understand whether a
techniques such as hand-tracing. MARRIED. Then the getTax method is called. In lines 31 and 32 of Tax-
Return.java, tax1 and tax2 are initialized to 0.
program works correctly.

29 public double getTax()


30 {
31 double tax1 = 0; income status tax1 tax2
32 double tax2 = 0;
33 80000 MARRIED 0 0
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);

Special Topic 11.2


File Dialog Boxes

Special Topics present optional 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
topics and provide additional 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
explanation of others. 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-
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
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
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
obtain a File object that describes the file.
Here is a complete example:
JFileChooser chooser = new JFileChooser();
Scanner in = null;
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
{

Additional full code examples


File selectedFile = chooser.getSelectedFile();
in = new Scanner(selectedFile);

throughout the text provide }

complete programs for students EXAMPLE CODE See special_topic_2 of your eText or companion code for a program that demonstrates how to use a file
chooser.

to run and modify.

Computing & Society 1.1 Computers Are Everywhere


When computers The advent of ubiqui-
were first invented tous computing changed
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
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
of search engines, Internet shops, and who know how to work
and historical topics on computing—for social networks fill huge buildings
called data centers. At the other end of
with those computers.
Books, music, and mov-
interest and to fulfill the “historical and the spectrum, computers are all around
us. Your cell phone has a computer
ies are nowadays often
consumed on com- This transit card contains a computer.
social context” requirements of the inside, as do many credit cards and fare
cards for public transit. A modern car
puters, and comput-
ers are almost always

ACM/IEEE curriculum guidelines. has several computers––to control the


engine, brakes, lights, and the radio.
involved in their production. The
book that you are reading right now
could not have been written without
computers.

bjeo_fm.indd 11 11/27/18 1:37 PM


xii Walkthrough

Interactive activities in the eText


engage students in active reading as they… Complete a program and
get immediate feedback

Trace through a code segment

Arrange code to fulfill a task

Build an example table

Create a memory diagram

Explore common algorithms

bjeo_fm.indd 12 11/27/18 2:30 PM


Acknowledgments xiii

Acknowledgments
Many thanks to Joanna Dingle, Crystal Franks, Graig Donini, and Michael Mac-
Dougald at John Wiley & Sons, and Vickie Piercey at Publishing Services for their
help with this project. An especially deep acknowledgment and thanks goes to Cindy
Johnson for her hard work, sound judgment, and amazing attention to detail.
Special thanks to Stephen Gilbert, Orange Coast College, for his excellent help
with the interactive exercises.
Many thanks to the individuals who worked through the many new activities in
this edition, reviewed the manuscript, made valuable suggestions, and brought errors
and omissions to my attention. They include:
Radhouane Chouchane, Columbus State University
Sussan Einakian, California Polytechnic State University
Jon Hanrath, Illinois Institute of Technology
Brian King, Bucknell University
Kathleen O’Brien, San Jose State University
Eman Saleh, University of Georgia
William Wei, New York Institute of Technology
Each new edition builds on the suggestions and experiences of prior reviewers, con-
tributors, and users. I am grateful for the invaluable contributions these individuals
have made:
Eric Aaron, Wesleyan University Jerry Cain, Stanford University Geoffrey Decker, Northern Illinois
James Agnew, Anne Arundel Adam Cannon, Columbia University
Community College University Suzanne Dietrich, Arizona State
Tim Andersen, Boise State Michael Carney, Finger Lakes University,West Campus
University Community College Mike Domaratzki, University of
Ivan Bajic, San Diego State Robin Carr, Drexel University Manitoba
University Christopher Cassa, Massachusetts H. E. Dunsmore, Purdue University
Greg Ballinger, Miami Dade College Institute of Technology Robert Duvall, Duke University
Ted Bangay, Sheridan Institute Nancy Chase, Gonzaga University Sherif Elfayoumy, University of
of Technology Dr. Suchindran S. Chatterjee, North Florida
Ian Barland, Radford University Arizona State University Eman El-Sheikh, University of
George Basham, Franklin University Archana Chidanandan, Rose- West Florida
Jon Beck, Truman State University Hulman Institute of Technology Henry A. Etlinger, Rochester
Sambit Bhattacharya, Fayetteville Vincent Cicirello, The Richard Institute of Technology
State University Stockton College of New Jersey John Fendrich, Bradley University
Rick Birney, Arizona State Gerald Cohen, The Richard Stockton David Freer, Miami Dade College
University College of New Jersey John Fulton, Franklin University
Paul Bladek, Edmonds Community Teresa Cole, Boise State University David Geary, Sabreware, Inc.
College Deborah Coleman, Rochester Margaret Geroch, Wheeling Jesuit
Matt Boutell, Rose-Hulman Institute of Technology University
Institute of Technology Tina Comston, Franklin University Ahmad Ghafarian, North Georgia
Joseph Bowbeer, Vizrea Corporation Lennie Cooper, Miami Dade College College & State University
Timothy A. Budd, Oregon State Jose Cordova, University of Rick Giles, Acadia University
University Louisiana, Monroe Stacey Grasso, College of San Mateo
John Bundy, DeVry University Valentino Crespi, California State Jianchao Han, California State
Chicago University, Los Angeles University, Dominguez Hills
Robert P. Burton, Brigham Young Jim Cross, Auburn University Lisa Hansen, Western New England
University Russell Deaton, University College
Frank Butt, IBM of Arkansas Elliotte Harold

bjeo_fm.indd 13 11/27/18 1:37 PM


xiv Acknowledgments

Eileen Head, Binghamton Teng Moh, San Jose State University Jeffrey Six, University of Delaware
University Bill Mongan, Drexel University Don Slater, Carnegie Mellon
Cecily Heiner, University of Utah John Moore, The Citadel University
Guy Helmer, Iowa State University Jose-Arturo Mora-Soto, Jesica Ken Slonneger, University of Iowa
Ed Holden, Rochester Institute Rivero-Espinosa, and Julio-Angel Aurelia Smith, Columbus State
of Technology Cano-Romero, University University
Brian Howard, Depauw University of Madrid Donald Smith, Columbia College
Lubomir Ivanov, Iona College Faye Navabi, Arizona State Joslyn A. Smith, Florida
Norman Jacobson, University of University International University
California, Irvine Parviz Partow-Navid, California Stephanie Smullen, University of
Steven Janke, Colorado College State University, Los Angeles Tennessee, Chattanooga
Curt Jones, Bloomsburg University George Novacky, University Robert Strader, Stephen F. Austin
Mark Jones, Lock Haven University of Pittsburgh State University
of Pennsylvania Kevin O’Gorman, California Monica Sweat, Georgia Institute
Dr. Mustafa Kamal, University of Polytechnic State University, San of Technology
Central Missouri Luis Obispo Peter Stanchev, Kettering University
Aaron Keen, California Polytechnic Michael Olan, Richard Stockton Aakash Taneja, The Richard
State University, San Luis Obispo College Stockton College of New Jersey
Mugdha Khaladkar, New Jersey Mimi Opkins, California State Craig Tanis, University of Tennessee
Institute of Technology University Long Beach at Chattanooga
Gary J. Koehler, University of Derek Pao, City University of Shannon Tauro, University of
Florida Hong Kong California, Irvine
Elliot Koffman, Temple University Kevin Parker, Idaho State University Ron Taylor, Wright State University
Ronald Krawitz, DeVry University Jim Perry, Ulster County Russell Tessier, University of
Norm Krumpe, Miami University Community College Massachusetts, Amherst
Ohio Cornel Pokorny, California Jonathan L. Tolstedt, North Dakota
Jim Leone, Rochester Institute Polytechnic State University, State University
of Technology San Luis Obispo David Vineyard, Kettering
Kevin Lillis, St. Ambrose University Roger Priebe, University of Texas, University
Austin Joseph Vybihal, McGill University
Darren Lim, Siena College
C. Robert Putnam, California State Xiaoming Wei, Iona College
Hong Lin, DeVry University
University, Northridge Jonathan S. Weissman, Finger Lakes
Kathy Liszka, University of Akron
Kai Qian, Southern Polytechnic Community College
Hunter Lloyd, Montana State State University
University Todd Whittaker, Franklin University
Cyndi Rader, Colorado School Robert Willhoft, Roberts Wesleyan
Youmin Lu, Bloomsburg University of Mines
Peter Lutz, Rochester Institute of College
Neil Rankin, Worcester Polytechnic Brent Wilson, George Fox University
Technology Institute
Kuber Maharjan, Purdue University Katherine Winters, University of
Brad Rippe, Fullerton College Tennessee at Chattanooga
College of Technology at
Pedro I. Rivera Vega, University Lea Wittie, Bucknell University
Columbus
of Puerto Rico, Mayaguez
John S. Mallozzi, Iona College David Womack, University of Texas
Daniel Rogers, SUNY Brockport at San Antonio
John Martin, North Dakota State
Chaman Lal Sabharwal, Missouri David Woolbright, Columbus State
University
University of Science and University
Jeanna Matthews, Clarkson Technology
University Tom Wulf, University of Cincinnati
Katherine Salch, Illinois Central
Patricia McDermott-Wells, Florida Catherine Wyman, DeVry
College
International University University
John Santore, Bridgewater State
Scott McElfresh, Carnegie Mellon Arthur Yanushka, Christian Brothers
College
University University
Javad Shakib, DeVry University
Joan McGrory, Christian Brothers Qi Yu, Rochester Institute of
Carolyn Schauble, Colorado State Technology
University
University
Carolyn Miller, North Carolina Salih Yurttas, Texas A&M University
Brent Seales, University of Kentucky
State University
Christian Shin, SUNY Geneseo
Sandeep R. Mitra, State University
of New York, Brockport Charlie Shu, Franklin University

bjeo_fm.indd 14 11/27/18 1:37 PM


CONTENTS

PREFACE iii 2.4 Constructing Objects 38


SPECIAL FEATURES xxiv 2.5 Accessor and Mutator Methods 40
2.6 The API Documentation 41
1 INTRODUCTION 1 Browsing the API Documentation 41
Packages 43
1.1 Computer Programs 2 2.7 Implementing a Test Program 44
1.2 The Anatomy of a Computer 3 ST2 Testing Classes in an Interactive
1.3 The Java Programming Language 5 Environment 45
WE1 How Many Days Have You Been Alive? 46
1.4 Becoming Familiar with Your
WE2 Working with Pictures 46
Programming Environment 7
2.8 Object References 46
1.5 Analyzing Your First Program 11
2.9 Graphical Applications 49
1.6 Errors 13
Frame Windows 50
1.7 PROBLEM SOLVING Algorithm Design 15 Drawing on a Component 51
The Algorithm Concept 15 Displaying a Component in a Frame 53
An Algorithm for Solving an
Investment Problem 16
2.10 Ellipses, Lines, Text, and Color 54
Pseudocode 17 Ellipses and Circles 54
From Algorithms to Programs 18 Lines 55
HT1 Describing an Algorithm with Drawing Text 56
Pseudocode 18 Colors 56
WE1 Writing an Algorithm for Tiling a Floor 20
3 IMPLEMENTING CLASSES 61
2 USING OBJECTS 23
3.1 Instance Variables and Encapsulation 62
2.1 Objects and Classes 24 Instance Variables 62
Using Objects 24 The Methods of the Counter Class 64
Classes 25 Encapsulation 64

2.2 Variables 26 3.2 Specifying the Public Interface


Variable Declarations 26
of a Class 66
Types 28 Specifying Methods 66
Names 29 Specifying Constructors 67
Comments 30 Using the Public Interface 69
Assignment 30 Commenting the Public Interface 69
ST1 Variable Type Inference 33 3.3 Providing the Class Implementation 72
2.3 Calling Methods 33 Providing Instance Variables 72
The Public Interface of a Class 33 Providing Constructors 73
Method Arguments 34 Providing Methods 75
Return Values 35 HT1 Implementing a Class 78
Method Declarations 36 WE1 Making a Simple Menu 81

xv

bjeo_fm.indd 15 11/27/18 1:37 PM


xvi Contents

3.4 Unit Testing 81 5 DECISIONS 131


3.5 PROBLEM SOLVING Tracing Objects 84
5.1 The if Statement 132
3.6 Local Variables 86
ST1 The Conditional Operator 137
3.7 The this Reference 88
5.2 Comparing Values 137
ST1 Calling One Constructor from Another 90
Relational Operators 138
3.8 Shape Classes 90 Comparing Floating-Point Numbers 139
HT2 Drawing Graphical Shapes 94 Comparing Strings 140
Comparing Objects 141
Testing for null 141
4 FUNDAMENTAL DATA
HT1 Implementing an if Statement 143
TYPES 99
WE1 Extracting the Middle 146
4.1 Numbers 100 5.3 Multiple Alternatives 146
Number Types 100 ST2 The switch Statement 148
Constants 102 5.4 Nested Branches 149
ST1 Big Numbers 106 ST3 Block Scope 154
4.2 Arithmetic 107 ST4 Enumeration Types 155
Arithmetic Operators 107 5.5 PROBLEM SOLVING Flowcharts 156
Increment and Decrement 107
5.6 PROBLEM SOLVING Selecting Test
Integer Division and Remainder 108
Powers and Roots 109 Cases 159
Converting Floating-Point Numbers ST5 Logging 161
to Integers 110 5.7 Boolean Variables and Operators 161
ST2 Avoiding Negative Remainders 112 ST6 Short-Circuit Evaluation of Boolean
ST3 Combining Assignment and Arithmetic 113 Operators 165
ST4 Instance Methods and Static Methods 113 ST7 De Morgan’s Law 165
4.3 Input and Output 114 5.8 APPLICATION Input Validation 166
Reading Input 114
Formatted Output 115
6 LOOPS 171
HT1 Carrying Out Computations 118
WE1 Computing the Volume and Surface Area of 6.1 The while Loop 172
a Pyramid 121
6.2 PROBLEM SOLVING Hand-Tracing 179
4.4 PROBLEM SOLVING First Do it By Hand 121
6.3 The for Loop 183
WE2 Computing Travel Time 122
ST1 Variables Declared in a for Loop
4.5 Strings 122 Header 189
The String Type 122 6.4 The do Loop 190
Concatenation 123
String Input 124 6.5 APPLICATION Processing Sentinel
Escape Sequences 124 Values 192
Strings and Characters 124 ST2 Redirection of Input and Output 194
Substrings 125 ST3 The “Loop and a Half” Problem 194
ST5 Using Dialog Boxes for Input and ST4 The break and continue Statements 195
Output 128 6.6 PROBLEM SOLVING Storyboards 197
6.7 Common Loop Algorithms 199
Sum and Average Value 199
Counting Matches 200

bjeo_fm.indd 16 11/27/18 1:37 PM


Contents xvii

Finding the First Match 200 7.6 Two-Dimensional Arrays 248


Prompting Until a Match is Found 201 Declaring Two-Dimensional Arrays 248
Maximum and Minimum 201 Accessing Elements 249
Comparing Adjacent Values 202 Locating Neighboring Elements 250
HT1 Writing a Loop 203 Accessing Rows and Columns 251
WE1 Credit Card Processing 206 Two-Dimensional Array Parameters 252
6.8 Nested Loops 206 WE2 A World Population Table 253
WE2 Manipulating the Pixels in an Image 209 ST3 Two-Dimensional Arrays with Variable
Row Lengths 254
6.9 APPLICATION Random Numbers and
ST4 Multidimensional Arrays 255
Simulations 209
7.7 Array Lists 255
Generating Random Numbers 210
The Monte Carlo Method 211 Declaring and Using Array Lists 255
Using the Enhanced for Loop with
6.10 Using a Debugger 213 Array Lists 258
HT2 Debugging 215 Copying Array Lists 259
WE3 A Sample Debugging Session 217 Wrappers and Auto-boxing 259
Using Array Algorithms with Array Lists 260
Storing Input Values in an Array List 261
7 ARRAYS AND ARRAY Removing Matches 261
LISTS 221 Choosing Between Array Lists and Arrays 262
ST5 The Diamond Syntax 264
7.1 Arrays 222
Declaring and Using Arrays 222 7.8 Regression Testing 264
Array References 225
Using Arrays with Methods 226
8 DESIGNING CLASSES 271
Partially Filled Arrays 226
ST1 Methods with a Variable Number of 8.1 Discovering Classes 272
Arguments 229
8.2 Designing Good Methods 273
7.2 The Enhanced for Loop 230
Providing a Cohesive Public Interface 273
7.3 Common Array Algorithms 232 Minimizing Dependencies 274
Filling 232 Separating Accessors and Mutators 275
Sum and Average Value 232 Minimizing Side Effects 276
Maximum and Minimum 232 ST1 Call by Value and Call by Reference 278
Element Separators 232 8.3 PROBLEM SOLVING Patterns for
Linear Search 233
Object Data 282
Removing an Element 234
Keeping a Total 282
Inserting an Element 234
Counting Events 283
Swapping Elements 236
Collecting Values 283
Copying Arrays 237
Managing Properties of an Object 284
Reading Input 238
Modeling Objects with Distinct States 284
ST2 Sorting with the Java Library 240
Describing the Position of an Object 285
7.4 PROBLEM SOLVING Adapting
8.4 Static Variables and Methods 286
Algorithms 240
ST2 Alternative Forms of Instance and Static
HT1 Working with Arrays 242 Variable Initialization 289
WE1 Rolling the Dice 245 ST3 Static Imports 290
7.5 PROBLEM SOLVING Discovering Algorithms by 8.5 PROBLEM SOLVING Solve a Simpler
Manipulating Physical Objects 245 Problem First 291

bjeo_fm.indd 17 11/27/18 1:37 PM


xviii Contents

8.6 Packages 295 10.3 The Comparable Interface 350


Organizing Related Classes into Packages 295 ST3 The clone Method and the Cloneable
Importing Packages 296 Interface 352
Package Names 297 10.4 Using Interfaces for Callbacks 355
Packages and Source Files 297 ST4 Lambda Expressions 358
ST4 Package Access 298 ST5 Generic Interface Types 360
HT1 Programming with Packages 299
10.5 Inner Classes 360
8.7 Unit Test Frameworks 300
10.6 Mock Objects 361
10.7 Event Handling 363
9 INHERITANCE 305 Listening to Events 363
9.1 Inheritance Hierarchies 306 Using Inner Classes for Listeners 365

9.2 Implementing Subclasses 310 10.8 Building Applications with Buttons 368

9.3 Overriding Methods 314 10.9 Processing Timer Events 371


ST1 Calling the Superclass Constructor 318 10.10 Mouse Events 374
ST6 Keyboard Events 377
9.4 Polymorphism 319
ST7 Event Adapters 378
ST2 Dynamic Method Lookup and the Implicit
Parameter 322
ST3 Abstract Classes 323 11 INPUT/OUTPUT AND
ST4 Final Methods and Classes 324 EXCEPTION HANDLING 383
ST5 Protected Access 324
HT1 Developing an Inheritance Hierarchy 325 11.1 Reading and Writing Text Files 384
WE1 Implementing an Employee Hierarchy for ST1 Reading Web Pages 387
Payroll Processing 330 ST2 File Dialog Boxes 387
9.5 Object: The Cosmic Superclass 330 ST3 Character Encodings 388

Overriding the toString Method 330 11.2 Text Input and Output 389
The equals Method 332 Reading Words 389
The instanceof Operator 333 Reading Characters 390
ST6 Inheritance and the toString Method 335 Classifying Characters 390
ST7 Inheritance and the equals Method 336 Reading Lines 390
Scanning a String 392
Converting Strings to Numbers 392
10 INTERFACES 339
Avoiding Errors When Reading Numbers 392
10.1 Using Interfaces for Algorithm Mixing Number, Word, and Line Input 393
Formatting Output 394
Reuse 340
ST4 Regular Expressions 395
Discovering an Interface Type 340
ST5 Reading an Entire File 396
Declaring an Interface Type 341
Implementing an Interface Type 343 11.3 Command Line Arguments 396
Comparing Interfaces and Inheritance 345 HT1 Processing Text Files 399
ST1 Constants in Interfaces 346 WE1 Analyzing Baby Names 403
ST2 Nonabstract Interface Methods 347 11.4 Exception Handling 403
10.2 Working with Interface Variables 348 Throwing Exceptions 403
Converting from Classes to Interfaces 348 Catching Exceptions 405
Invoking Methods on Interface Variables 349 Checked Exceptions 407
Casting from Interfaces to Classes 349 Closing Resources 409
WE1 Investigating Number Sequences 350 Designing Your Own Exception Types 410

bjeo_fm.indd 18 11/27/18 1:37 PM


Contents xix

ST6 Assertions 411 14 SORTING AND


ST7 The try/finally Statement 412 SEARCHING 477
11.5 APPLICATION Handling Input Errors 412
14.1 Selection Sort 478
14.2 Profiling the Selection Sort
12 OBJECT-ORIENTED
Algorithm 481
DESIGN 419
14.3 Analyzing the Performance of the
12.1 Classes and Their Responsibilities 420 Selection Sort Algorithm 484
Discovering Classes 420 ST1 Oh, Omega, and Theta 486
The CRC Card Method 421 ST2 Insertion Sort 487
12.2 Relationships Between Classes 423 14.4 Merge Sort 488
Dependency 423 14.5 Analyzing the Merge Sort Algorithm 491
Aggregation 424 ST3 The Quicksort Algorithm 493
Inheritance 425
14.6 Searching 495
HT1 Using CRC Cards and UML Diagrams in
Program Design 426 Linear Search 495
ST1 Attributes and Methods in UML Binary Search 497
Diagrams 426 14.7 PROBLEM SOLVING Estimating the Running
ST2 Multiplicities 427 Time of an Algorithm 500
ST3 Aggregation, Association, and Linear Time 500
Composition 427 Quadratic Time 501
12.3 APPLICATION Printing an Invoice 428 The Triangle Pattern 502
Requirements 429 Logarithmic Time 503
CRC Cards 429 14.8 Sorting and Searching in the Java
UML Diagrams 432 Library 504
Method Documentation 432
Sorting 504
Implementation 434
Binary Search 505
WE1 Simulating an Automatic Teller Machine 439 Comparing Objects 505
ST4 The Comparator Interface 506
13 RECURSION 443 ST5 Comparators with Lambda Expressions 507
WE1 Enhancing the Insertion Sort Algorithm 507
13.1 Triangle Numbers 444
HT1 Thinking Recursively 448
WE1 Finding Files 452
15 THE JAVA COLLECTIONS
FRAMEWORK 511
13.2 Recursive Helper Methods 452
13.3 The Efficiency of Recursion 453 15.1 An Overview of the Collections
Framework 512
13.4 Permutations 459
15.2 Linked Lists 514
13.5 Mutual Recursion 463
The Structure of Linked Lists 515
13.6 Backtracking 469
The LinkedList Class of the Java Collections
WE2 Towers of Hanoi 475 Framework 516
List Iterators 516
15.3 Sets 520
Choosing a Set Implementation 520
Working with Sets 522

bjeo_fm.indd 19 11/27/18 1:37 PM


xx Contents

15.4 Maps 525 Adding and Removing Elements 572


ST1 Updating Map Entries 527 Iterating over a Hash Table 573
HT1 Choosing a Collection 527 ST2 Open Addressing 578
WE1 Word Frequency 528
ST2 Hash Functions 529 17 TREE STRUCTURES 581
15.5 Stacks, Queues, and Priority Queues 531
17.1 Basic Tree Concepts 582
Stacks 531
Queues 532 17.2 Binary Trees 585
Priority Queues 533 Binary Tree Examples 586
15.6 Stack and Queue Applications 534 Balanced Trees 588
A Binary Tree Implementation 589
Balancing Parentheses 534
Evaluating Reverse Polish Expressions 535 WE1 Building a Huffman Tree 590
Evaluating Algebraic Expressions 537 17.3 Binary Search Trees 590
Backtracking 540 The Binary Search Property 591
ST3 Reverse Polish Notation 542 Insertion 592
WE2 Simulating a Queue of Waiting Removal 594
Customers 543 Efficiency of the Operations 595
17.4 Tree Traversal 599
16 BASIC DATA Inorder Traversal 599
STRUCTURES 545 Preorder and Postorder Traversals 601
The Visitor Pattern 602
16.1 Implementing Linked Lists 546 Depth-First and Breadth-First Search 603
The Node Class 546 Tree Iterators 604
Adding and Removing the First Element 547 17.5 Red-Black Trees 605
The Iterator Class 548
Basic Properties of Red-Black Trees 605
Advancing an Iterator 549
Insertion 607
Removing an Element 550
Removal 608
Adding an Element 552
WE2 Implementing a Red-Black Tree 611
Setting an Element to a Different Value 553
Efficiency of Linked List Operations 553 17.6 Heaps 612
ST1 Static Classes 560 17.7 The Heapsort Algorithm 622
WE1 Implementing a Doubly-Linked List 560
16.2 Implementing Array Lists 560 18 GENERIC CLASSES 629
Getting and Setting Elements 560
Removing or Adding Elements 562 18.1 Generic Classes and Type
Growing the Internal Array 563 Parameters 630
16.3 Implementing Stacks and Queues 564 18.2 Implementing Generic Types 631
Stacks as Linked Lists 565 18.3 Generic Methods 634
Stacks as Arrays 566
18.4 Constraining Type Parameters 636
Queues as Linked Lists 567
ST1 Wildcard Types 638
Queues as Circular Arrays 568
18.5 Type Erasure 639
16.4 Implementing a Hash Table 570
ST2 Reflection 642
Hash Codes 570
WE1 Making a Generic Binary Search
Hash Tables 570
Tree Class 643
Finding an Element 572

bjeo_fm.indd 20 11/27/18 1:37 PM


Contents xxi

19 STREAM PROCESSING 645 Check Boxes 687


Combo Boxes 687
19.1 The Stream Concept 646 HT1 Laying Out a User Interface 692
19.2 Producing Streams 648 WE1 Programming a Working Calculator 694

19.3 Collecting Results 649 20.4 Menus 695


ST1 Infinite Streams 651 20.5 Exploring the Swing Documentation 702
19.4 Transforming Streams 652
19.5 Lambda Expressions 654 21 ADVANCED INPUT/OUTPUT*
ST2 Method and Constructor References 656 (ETEXT ONLY)
ST3 Higher-Order Functions 657
21.1 Readers, Writers, and Input/Output Streams
ST4 Higher-Order Functions and
Comparators 658 21.2 Binary Input and Output
19.6 The Optional Type 659 21.3 Random Access
19.7 Other Terminal Operations 661 21.4 Object Input and Output Streams
19.8 Primitive-Type Streams 663 HT1 Choosing a File Format

Creating Primitive-Type Streams 663 21.5 File and Directory Operations


Mapping a Primitive-Type Stream 663 Paths
Processing Primitive-Type Streams 664 Creating and Deleting Files and Directories
19.9 Grouping Results 665 Useful File Operations
Visiting Directories
19.10 Common Algorithms Revisited 667
Filling 667
Sum, Average, Maximum, and Minimum 668 22 MULTITHREADING*
Counting Matches 668 (ETEXT ONLY)
Element Separators 668
Linear Search 669
22.1 Running Threads
Comparing Adjacent Values 669 ST1 Thread Pools

HT1 Working with Streams 670 22.2 Terminating Threads


WE1 Word Properties 672 22.3 Race Conditions
WE2 A Movie Database 673
22.4 Synchronizing Object Access
22.5 Avoiding Deadlocks
20 GRAPHICAL USER ST2 Object Locks and Synchronized Methods
INTERFACES 675 ST3 The Java Memory Model

20.1 Layout Management 676


22.6 APPLICATION Algorithm Animation
Using Layout Managers 676
Achieving Complex Layouts 677 23 INTERNET NETWORKING*
Using Inheritance to Customize Frames 678 (ETEXT ONLY)
ST1 Adding the main Method to the
Frame Class 679 23.1 The Internet Protocol
20.2 Processing Text Input 680 23.2 Application Level Protocols
Text Fields 680 23.3 A Client Program
Text Areas 682
23.4 A Server Program
20.3 Choices 685 HT1 Designing Client/Server Programs
Radio Buttons 685 23.5 URL Connections

*See your eText or visit www.wiley.com/go/bjeo7.

bjeo_fm.indd 21 11/27/18 1:37 PM


xxii Contents

24 RELATIONAL DATABASES* APPENDIX A THE BASIC LATIN AND LATIN-1 SUBSETS


(ETEXT ONLY) OF UNICODE A-1
APPENDIX B JAVA OPERATOR SUMMARY A-5
24.1 Organizing Database Information APPENDIX C JAVA RESERVED WORD SUMMARY A-7
Database Tables APPENDIX D THE JAVA LIBRARY A-9
Linking Tables APPENDIX E JAVA LANGUAGE CODING
Implementing Multi-Valued Relationships GUIDELINES A-38
ST1 Primary Keys and Indexes APPENDIX F TOOL SUMMARY (ETEXT ONLY)
24.2 Queries APPENDIX G NUMBER SYSTEMS (ETEXT ONLY)
Simple Queries APPENDIX H UML SUMMARY (ETEXT ONLY)
Selecting Columns APPENDIX I JAVA SYNTAX SUMMARY (ETEXT ONLY)
Selecting Subsets
APPENDIX J HTML SUMMARY (ETEXT ONLY)
Calculations
Joins
Updating and Deleting Data
GLOSSARY G-1
INDEX I-1
24.3 Installing a Database
CREDITS C-1
24.4 Database Programming in Java
QUICK REFERENCE C-3
Connecting to the Database
Executing SQL Statements
Analyzing Query Results
Result Set Metadata
24.5 APPLICATION Entering an Invoice
ST2 Transactions
ST3 Object-Relational Mapping
WE1 Programming a Bank Database

25 XML* (ETEXT ONLY)


25.1 XML Tags and Documents
Advantages of XML
Differences Between XML and HTML
The Structure of an XML Document
HT1 Designing an XML Document Format

25.2 Parsing XML Documents


25.3 Creating XML Documents
HT2 Writing an XML Document
ST1 Grammars, Parsers, and Compilers

25.4 Validating XML Documents


Document Type Definitions
Specifying a DTD in an XML Document
Parsing and Validation
HT3 Writing a DTD
ST2 Schema Languages
ST3 Other XML Technologies

*See your eText or visit www.wiley.com/go/bjeo7.

bjeo_fm.indd 22 11/27/18 1:37 PM


Contents xxiii

ALPHABETICAL LIST OF SYNTAX BOXES


Arrays 223
Array Lists 256
Assignment 31
Calling a Superclass Method 315
Cast 110
Catching Exceptions 406
Class Declaration 68
Comparisons 138
Constant Declaration 104
Constructor with Superclass Initializer 318
Declaring a Generic Class 632
Declaring a Generic Method 635
Declaring an Interface 342
for Statement 183
if Statement 134
Implementing an Interface 343
Importing a Class from a Package 43
Input Statement 115
Instance Variable Declaration 63
Java Program 12
Lambda Expressions 655
Object Construction 39
Package Specification 296
Subclass Declaration 311
The Enhanced for Loop 231
The instanceof Operator 334
The throws Clause 408
The try-with-resources Statement 409
Throwing an Exception 403
Two-Dimensional Array Declaration 249
while Statement 173
Variable Declaration 27

bjeo_fm.indd 23 11/27/18 1:37 PM


xxiv Special Features

How Tos
CH AP TE R Common and
Errors Worked Examples
© Steve Simzer/iStockphoto.

1 Introduction ©Omitting
John Bell/iStockphoto.
Semicolons 13 Describing an Algorithm
Misspelling Words 14 with Pseudocode 18
Writing an Algorithm for
Tiling a Floor 20

2 Using Objects Using Undeclared or How Many Days Have You


Uninitialized Variables 32 Been Alive? 46
Confusing Variable Declarations Working with Pictures 46
and Assignment Statements 32
Trying to Invoke a Constructor Like
a Method 40

3 Implementing Classes Declaring a Constructor as void 72 Implementing a Class 78


Ignoring Parameter Variables 77 Making a Simple Menu 81
Duplicating Instance Variables Drawing Graphical Shapes 94
in Local Variables 86
Providing Unnecessary
Instance Variables 87
Forgetting to Initialize Object
References in a Constructor 87

4 Fundamental Unintended Integer Division 111 Carrying out Computations 118


Unbalanced Parentheses 112 Computing the Volume and
Data Types Surface Area of a Pyramid 121
Computing Travel Time 122

5 Decisions A Semicolon After the Implementing an


if Condition 134 if Statement 143
Using == to Compare Strings 143 Extracting the Middle 146
The Dangling else Problem 152
Combining Multiple
Relational Operators 164
Confusing && and || Conditions 164

6 Loops Don’t Think “Are We There Yet?” 177 Writing a Loop 203
Infinite Loops 177 Credit Card Processing 206
Off-by-One Errors 178 Manipulating the Pixels
in an Image 209
Debugging 215
A Sample Debugging Session 217

bjeo_fm.indd 24 11/27/18 2:09 PM


Special Features xxv

Programming Special Topics Computing &


Tips Society
© Eric Isselé/iStockphoto. © Media Bakery.
© Eric Isselé/iStockphoto.
Backup Copies 10 Computers Are Everywhere 5

Choose Descriptive Variable Type Inference 33 Computer Monopoly 49


Variable Names 32 Testing Classes in an Interactive
Learn By Trying 37 Environment 45
Don’t Memorize—Use
Online Help 43

The javadoc Utility 72 Calling One Constructor Electronic Voting 83


from Another 90

Do Not Use Magic Numbers 106 Big Numbers 106 Bugs in Silicon 114
Spaces in Expressions 112 Avoiding Negative International Alphabets
Reading Exception Reports 127 Remainders 112 and Unicode 128
Combining Assignment
and Arithmetic 113
Instance Methods and
Static Methods 113
Using Dialog Boxes for Input
and Output 128

Brace Layout 135 The Conditional Operator 137 Dysfunctional Computerized


Always Use Braces 135 The switch Statement 148 Systems 145
Tabs 136 Block Scope 154 Artificial Intelligence 168
Avoid Duplication in Branches 136 Enumeration Types 155
Hand-Tracing 153 Logging 161
Make a Schedule and Make Time Short-Circuit Evaluation of
for Unexpected Problems 160 Boolean Operators 165
De Morgan’s Law 165

Use for Loops for Their Variables Declared in a Digital Piracy 182
Intended Purpose Only 188 for Loop Header 189 The First Bug 217
Choose Loop Bounds That Redirection of Input and Output 194
Match Your Task 188 The Loop-and-a-Half Problem 194
Count Iterations 189 The break and continue
Flowcharts for Loops 191 Statements 195

bjeo_fm.indd 25 11/27/18 2:09 PM


xxvi Special Features

How Tos
CH AP TE R Common and
Errors
Worked Examples
© Steve Simzer/iStockphoto.

7 Arrays and Array Lists ©Bounds Errors


John Bell/iStockphoto. 227 Working with Arrays 242
Uninitialized and Rolling the Dice 245
Unfilled Arrays 227 A World Population Table 253
Underestimating the
Size of a Data Set 240
Length and Size 264

8 Designing Classes Trying to Access Instance Programming with Packages 299


Variables in Static Methods 288
Confusing Dots 298

9 Inheritance Replicating Instance Variables Developing an


from the Superclass 313 Inheritance Hierarchy 325
Confusing Super- and Implementing an
Subclasses 313 Employee Hierarchy for
Accidental Overloading 317 Payroll Processing 330
Forgetting to Use super
When Invoking a
Superclass Method 318
Don’t Use Type Tests 335

10 Interfaces Forgetting to Declare Investigating Number


Implementing Methods Sequences 350
as Public 346
Trying to Instantiate an Interface 346
Modifying Parameter Types
in the Implementing Method 367
Trying to Call Listener Methods 368
Forgetting to Attach a Listener 371
Forgetting to Repaint 373

11 Input/Output and Backslashes in File Names 386 Processing Text Files 399
Constructing a Scanner Analyzing Baby Names 403
Exception Handling with a String 386

bjeo_fm.indd 26 11/27/18 2:09 PM


Special Features xxvii

Programming Special Topics Computing &


Tips Society
© Eric Isselé/iStockphoto. © Media Bakery.
© EricArrays
Use Isselé/iStockphoto.
for Sequences of Methods with a Variable Computer Viruses 229
Related Items 228 Number of Arguments 229 Liability for Software
Make Parallel Arrays into Sorting with the Java Library 240 Malfunction 267
Arrays of Objects 228 Two-Dimensional Arrays
Batch Files and Shell Scripts 266 with Variable Row Lengths 254
Multidimensional Arrays 255
The Diamond Syntax 264

Consistency 277 Call by Value and Call Personal Computing 302


Minimize the Use of by Reference 278
Static Methods 289 Alternative Forms of Instance
and Static Variable Initialization 289
Static Imports 290
Package Access 298

Use a Single Class for Variation Calling the Superclass Who Controls the Internet? 337
in Values, Inheritance for Constructor 318
Variation in Behavior 309 Dynamic Method Lookup and
the Implicit Parameter 322
Abstract Classes 323
Final Methods and Classes 324
Protected Access 324
Inheritance and the
toString Method 335
Inheritance and the
equals Method 336

Comparing Integers and Floating- Constants in Interfaces 346 Open Source and
Point Numbers 351 Nonabstract Interface Methods 347 Free Software 379
The clone Method and the
Cloneable Interface 352
Lambda Expressions 358
Generic Interface Types 360
Keyboard Events 377
Event Adapters 378

Throw Early, Catch Late 411 Reading Web Pages 387 Encryption Algorithms 402
Do Not Squelch Exceptions 411 File Dialog Boxes 387 The Ariane Rocket Incident 417
Do Throw Specific Character Encodings 388
Exceptions 411 Regular Expressions 395
Reading an Entire File 396
Assertions 411
The try/finally Statement 412

bjeo_fm.indd 27 11/27/18 2:09 PM


Another random document with
no related content on Scribd:
honor. The offence which provoked this assault is not even hinted at,
though it may have arisen from the troubled state of public affairs.
Captain Praa was a man of influence and dignity in the community,
an exiled Huguenot, of remarkable skill in horsemanship and arms.
In spite of all this, it appears probable that the sentiment of the
community was in sympathy with the two turbulent assaulters and
batterers, for they were fined only six shillings and three pounds
respectively. They threw themselves on the mercy of the Court, and
certainly were treated with mercy.
There are, however, few women-criminals named in the old Dutch
and early English records, and these few were not prosecuted for
any very great crimes or viciousness; the chief number were brought
up for defamation of character and slander, though men-slanderers
were more plentiful than women. The close intimacy, the ideal
neighborliness of the Dutch communities of New York made the
settlers deeply abhor all violations of the law of social kindness. To
preserve this state of amity, they believed with Chaucer “the first
vertue is to restraine and kepen wel thine tonge.”
The magistrates knew how vast a flame might be kindled by a
petty spark; and therefore promptly quenched the odious slander in
its beginning; petty quarrels were adjusted by arbitration ere they
grew to great breaches. As sung the chorus of Batavian women in
Van der Vondel’s great poem:—

“If e’er dispute or discord dared intrude,


’Twas soon by wisdom’s voice subdued.”

In spite, however, of all wariness and watchfulness and patience,


the inevitable fretfulness engendered in petty natures by a narrow
and confined life showed in neighborhood disputes and suits for
defamation of character, few of them of great seriousness and most
of them easily adjusted by the phlegmatic and somewhat dictatorial
Dutch magistrates. In a community so given to nicknaming it seems
strange to find such extreme touchiness about being called names.
Suits for defamation were frequent, through opprobrious name-
calling, and on very slight though irritating grounds. It would certainly
seem a rather disproportionate amount of trouble to bring a lawsuit
simply because you were called a “black pudding,” or a verklickker,
or tale-bearer, or even a “Turk;” though, of course, no one would
stand being called a “horned beast” or a “hay thief.” Nor was “Thou
swine” an offensive term too petty to be passed over in silence. The
terrible epithets, spitter-baard and “Dutch dough-face,” seem to
make a climax of opprobriousness; but the word moff was worse, for
it was the despised term applied in Holland to the Germans, and it
led to a quarrel with knives.
I wish to note in passing that though the Dutch called each other
these disagreeable and even degrading names, they did not swear
at each other. Profanity was seldom punished in New Amsterdam,
for practically it did not exist, as was remarked by travellers.
Chaplain Wolley told of “the usual oath” of one Dutch colonist,—the
word “sacrament.”
The colonists were impatient of insulting actions as well as words.
Sampson said in “Romeo and Juliet,” “I will bite my thumb at them,
which is a disgrace to them if they bear it;” so “finger-sticking” was a
disgrace in colonial times if unresented, and it was actionable in the
courts. The man or woman who pointed the finger of scorn at a
neighbor was pretty sure to have the finger of the law pointed at him.
The curious practice of the Dutch settlers alluded to—the giving of
nicknames—may be partly explained by the fact that in some cases
the persons named had no surname, and the nickname was really a
distinguishing name. These nicknames appear not only in the
records of criminal cases, but in official documents such as the
patents for towns, transfers of estates, civil contracts, etc. In Albany,
in 1655 and 1657, we find Jan the Jester, Huybert the Rogue,
Jacobus or Cobus the Looper, squint-eyed Harmen, the wicked
Domine. On Long Island were John the Swede, Hans the Boor,
Tunis the Fisher. In Harlem was Jan Archer the Koop-all (or buy-all).
In New York, in English days, in 1691, we find Long Mary, Old Bush,
Top-knot Betty, Scarebouch. These names conveyed no offence,
and seem to have been universally adopted and responded to.
It would appear to a casual observer glancing over the court-
records of those early years of New York life under Dutch
supremacy, that the greater number of the cases brought before the
magistrates were these slander and libel cases. We could believe
that no other court-room ever rang with such petty personal suits; to
use Tennyson’s words, “it bubbled o’er with gossip and scandal and
spite.” But in truth slander was severely punished in all the colonies,
in New England, Virginia, Pennsylvania; and it is not to the detriment
of the citizens of New Netherland that they were more sharp in the
punishment of such offences, for it is well known, as Swift says, that
the worthiest people are those most injured by slander.
The slander cases of colonial times seem most trivial and even
absurd when seen through the mist of years. They could scarce
reach the dignity of Piers Plowman’s definition of slanders:—

“To bakbyten, and to bosten, and to bere fals witnesse


To scornie and to scolde, sclaundres to make.”

To show their character, let me give those recorded in which


Thomas Applegate of Gravesend, Long Island, took an accused part.
In 1650, he was brought up before the Gravesend court for saying of
a fellow-towns-man that “he thought if his debts were paid he would
have little left.” For this incautious but not very heinous speech he
paid a fine of forty guilders. The next year we find him prosecuted for
saying of a neighbor that “he had not half a wife.” Though he at first
denied this speech, he was ordered “to make publick
acknowledgement of error; to stand at the publick post with a paper
on his breast mentioning the reason, that he is a notorious,
scandalous person.” This brought him to his senses, and he
confessed his guilt, desired the slandered “half a wife” to “pass it by
and remit it, which she freely did and he gave her thanks.” Next
Mistress Applegate was brought up for saying that a neighbor’s wife
milked the Applegate cows. She escaped punishment by proving
that Penelope Prince told her so. As a climax, Thomas Applegate
said to a friend that he believed that the Governor took bribes. The
schout in his decision on this grave offence said Applegate “did
deserve to have his tongue bored through with a hot iron;” but this
fierce punishment was not awarded him, nor was he banished.
When the tailor of New Amsterdam said disrespectful words of the
Governor, his sentence was that he “stand before the Governor’s
door with uncovered head, after the ringing of the bell, and to declare
that he falsely and scandalously issued such words and then to ask
God’s pardon.”
The magistrates were very touchy of their dignity. Poor Widow
Piertje Jans had her house sold on an execution; and, exasperated
by the proceeding, and apparently also at the price obtained, she
said bitterly to the officers, “Ye despoilers, ye bloodsuckers, ye have
not sold but given away my house.” Instead of treating these as the
heated words of a disappointed and unhappy woman, the officers
promptly ran tattling to the Stadt Huys and whiningly complained to
the Court that her words were “a sting which could not be endured.”
Piertje was in turn called shameful; her words were termed “foul,
villanous, injurious, nay, infamous words,” and also called a
blasphemy, insult, affront, and reproach. She was accused of
insulting, defaming, affronting, and reproaching the Court, and that
she was in the highest degree reprimanded, particularly corrected,
and severely punished; and after being forbidden to indulge in any
more such blasphemies, she was released,—“bethumped with
words,” as Shakespeare said,—doubtless well scared at the
enormity of her offence, as well as at the enormity of the magistrate’s
phraseology.
The notary Walewyn van der Veen was frequently in trouble,
usually for contempt of court. And I doubt not “the little bench of
justices” was sometimes rather trying in its ways to a notary who
knew anything about law. On one occasion, when a case relating to
a bill of exchange had been decided against him, Van der Veen
spoke of their High Mightinesses the magistrates as “simpletons and
blockheads.” This was the scathing sentence of his punishment:—
“That Walewyn Van der Veen, for his committed insult, shall
here beg forgiveness, with uncovered head, of God, Justice,
and the Worshipful Court, and moreover pay as a fine 190
guilders.”
This fine must have consumed all his fees for many a weary
month thereafter, if we can judge by the meagre lawyers’ bills which
have come down to us.
Another time the contumacious Van der Veen called the Secretary
a rascal. Thereat, the latter, much aggrieved, demanded “honorable
and profitable reparation” for the insult. The schout judged this
epithet to be a slander and an affront to the Secretary, which
“affected his honor, being tender,” and the honor of the Court as well,
since it was to a member of the Court, and he demanded that the
notary should pay a fine of fifty guilders as an example to other
slanderers, “who for trifles have constantly in their mouths curses
and abuses of other honorable people.”
Another well-known notary and practitioner and pleader in the
busy little Court held in the Stadt Huys was Solomon La Chair. His
manuscript volume of nearly three hundred pages, containing
detailed accounts of all the business he transacted in Manhattan, is
now in the County Clerk’s Office in New York, and proves valuable
material for the historiographer. He had much business, for he could
speak and write both English and Dutch; and he was a faithful,
painstaking, intelligent worker. He not only conducted lawsuits for
others, but he seems to have been in constant legal hot water
himself on his own account. He was sued for drinking and not paying
for a can of sugared wine; and also for a half-aam of costly French
wine; and he was sued for the balance of payment for a house he
had purchased; he pleaded for more time, and with the ingenuous
guilelessness peculiar to the law said in explanation that he had had
the money gathered at one time for payment, but it had somehow
dropped through his fingers. “The Court condemned to pay at
once,”—not being taken in by any such simplicity as that. He had to
pay a fine of twelve guilders for affronting both fire inspector and
court messenger. He first insulted the brandt-meester who came to
inspect his chimney, and was fined, then he called the bode who
came to collect the fine “a little cock booted and spurred.” The Court
in sentence said with dignity, “It is not meet that men should mock
and scoff at persons appointed to any office, yea a necessary office.”
He won one important suit for the town of Gravesend, by which the
right of that town to the entire region of Coney Island was
established; and he received in payment for his legal services
therein, the munificent sum of twenty-four florins (ten dollars) paid in
gray pease. He kept a tavern and was complained of for tapping
after nine o’clock; and he was sued by his landlord for rent; and he
had a yacht, “The Pear Tree,” which ran on trading trips to Albany,
and there were two or three lawsuits in regard to that. He was also a
farmer of the excise on slaughtered cattle; but, in spite of all his
energy and variety of employment, he died insolvent in 1664. The
last lawsuit in which Lawyer Solomon had any share was through a
posthumous connection,—the burgher who furnished an anker of
French wine for the notary’s funeral claimed a position as preferred
creditor to the estate.
A very aggravated case of scorn and resistance of authority was
that of Abel Hardenbrock against the schout de Mill. And this case
shows equally the popular horror of violations of the law and the
confiding trust of the justices that the word of the law was enough
without any visible restraining force. Hardenbrock, who was a
troublesome fellow, had behaved most vilely, shoving the schout on
the breast, and wickedly “wishing the devil might break his neck,”
simply because the schout went to Hardenbrock’s house to warn his
wife not to annoy further Burgomaster De Peyster by unwelcome
visits. Hardenbrock was accordingly seized and made a prisoner at
the Stadt Huys “in the chamber of Pieter Schaefbanck, where he
carried on and made a racket like one possessed and mad,
notwithstanding the efforts of Heer Burgomaster Van Brught, running
up to the Court room and going away next morning as if he had not
been imprisoned.” It was said with amusing simplicity that this cool
walking out of prison was “contrary to the customs of the law,” and a
fine of twenty-five florins was imposed.
For serious words against the government, which could be
regarded as treasonable, the decreed punishment was death. One
Claerbout van ter Goes used such words (unfortunately they are not
given in the indictment), and a judgment was recorded from each
burgomaster and schepen as to what punishment would be proper.
He was branded, whipped on a half-gallows, and banished, and
escaped hanging only by one vote.
All classes in the community were parties in these petty slander
suits; schoolmasters and parsons appear to have been specially
active. Domine Bogardus and Domine Schaets had many a slander
suit. The most famous and amusing of all these clerical suits is the
one brought by Domine Bogardus and his wife, the posthumously
famous Anneke Jans, against Grietje von Salee, a woman of very
dingy reputation, who told in New Amsterdam that the domine’s wife,
Mistress Anneke, had lifted her petticoats in unseemly and extreme
fashion when crossing a muddy street. This was proved to be false,
and the evidence adduced was so destructive of Grietje’s character
that she stands disgraced forever in history as the worst woman in
New Netherland.
Not only were slanderers punished, but they were disgraced with
terrible names. William Bakker was called “a blasphemer, a street
schold, a murderer as far as his intentions are concerned, a defamer,
a disturber of public peace,”—the concentration of which must have
made William Bakker hang his head in the place of his banishment.
They were also rebuked from the pulpit, and admonished in private.
Perhaps the best rebuke given, as well as a unique one, was the
one adopted by Domine Frelinghuysen, who had suffered somewhat
from slander himself. He had this rhyme painted in large letters on
the back of his sleigh, that he who followed might read:—

“Niemands tong; nog neimands pen,


Maakt my anders dan ik ben.
Spreek quaad-spreekers: spreek vonder end,
Niemand en word van u geschend.”

Which, translated into English, reads:—


“No one’s tongue, and no one’s pen
Makes me other than I am.
Speak, evil-speakers, speak without end,
No one heeds a word you say.”

The original Court of the colony was composed of a Director and


his Council. In 1656, in answer to complaints from the colonists, the
States-General ordered the election of a board of magistrates, in
name and function like those of the Fatherland; namely, a schout,
two burgomasters, and five schepens. The duties of the
burgomasters and schepens were twofold: they regulated municipal
affairs like a board of aldermen, and they sat as a court of justice
both in civil and criminal cases. The annual salary of a burgomaster
was fixed at one hundred and forty dollars, and of a schepen at one
hundred dollars; but as these salaries were to come out of the
municipal chest, which was chronically empty, they never were paid.
When funds did come in from the excise on taverns, on slaughtered
cattle, the tax on land, the fees on transfers, etc., it always had to be
paid out in other ways,—for repairs for the school-room, the Graft,
the watch-room, the Stadt Huys. It never entered the minds of those
guileless civic rulers, two centuries ago, to pay themselves and let
the other creditors go without. The early city schout was also schout-
fiskaal till 1660; but the proper duties of this functionary were really a
combination of those pertaining now to the mayor, sheriff, and
district-attorney. In the little town one man could readily perform all
these duties. He also presided in Court. An offender could thus be
arrested, prosecuted, and judged, by one and the same person,
which seems to us scarcely judicious; but the bench of magistrates
had one useful power, that of mitigating and altering the sentence
demanded by the schout. Often a fine of one hundred guilders would
be reduced to twenty-five; often the order for whipping would be set
aside, and the command of branding as well.
Sometimes justice in New York was tempered with mercy, and
sorely it needed it when fierce English rule and law came in force.
Felons were few, but these few were severely punished. A record of
a trial in 1676 reveals a curious scene in Court, as well as an
astonishing celerity in the execution of the law under English rule
and in the English army. Three soldiers stole a couple of iron pots,
two hoes, a pair of shears, and half a firkin of soap. They were tried
in the morning, confessed, cast into “the Hole” in the afternoon, and
in the evening “the Governor ordered some persons to go to the
prisoners and advise them to prepare for another world, for that one
of them should dye the next day.” On the gloomy morrow, on
Saturday, the three terror-stricken souls drew lots, and the fatal lot
fell to one Thomas Weale. The court of aldermen interceded for him
and finally secured his reprieve till Monday. The peaceful Dutch
Sunday, darkened and shocked by this impending death, saw a
strange and touching sight.
“In the evening a company of the chiefe women of the City,
both English and Dutch, made earnest suite to the Governor
for the Condemned man’s life. Monday in the morning the
same women who came the last night with many others of the
better sort, and a greater number of the ordinary Dutch
women, did again very much importune the Governor to spare
him.”
These tender-hearted colonists were indorsed and supplemented
by the petition of Weale’s fellow-soldiers in the garrison, who
pleaded the prisoner’s youth and his past usefulness, and who
promised if he were pardoned never to steal nor to conceal theft. As
a result of all this intercession, the Governor “graciously” granted
pardon.
This promise and pardon seem to have accomplished much in
army discipline, for thereafter arrests for crime among the soldiery
were rare. Five years later a soldier was accused of pilfering.
“The Court Marshall doth adjudge that the said Melchoir
Classen shall run the Gantlope once, the length of the fort:
where according to the custome of that punishment, the
souldiers shall have switches delivered to them, with which
they shall strike him as he passes between them stript to the
waist, and at the Fort-gate the Marshall is to receive him, and
there to kick him out of the Garrison as a cashiered person,
when he is no more to returne, and if any pay is due him it is
to be forfeited.”
And that was the end of Melchoir Classen.
Gantlope was the earlier and more correct form of the word now
commonly called gantlet. Running the gantlope was a military
punishment in universal use.
Another common punishment for soldiers (usually for rioting or
drinking) was riding the wooden horse. In New Amsterdam the
wooden horse stood between Paerel Street and the Fort, and was
twelve feet high. Garret Segersen, for stealing chickens, rode the
wooden horse for three days from two o’clock to close of parade with
a fifty-pound weight tied to each foot. At other times a musket was
tied to each foot of the disgraced man. One culprit rode with an
empty scabbard in one hand and a pitcher in the other to show his
inordinate love for John Barleycorn. Jan Alleman, a Dutch officer,
challenged Jan de Fries, who was bedridden; for this cruel and
meaningless insult he too rode the wooden horse. In Revolutionary
days we still find the soldiers of the Continental Army punished by
riding the wooden horse, or, as it was sometimes called, “the timber
mare;” but it was probably a modification of the cruel punishment of
the seventeenth century.
A sailor, for drawing a knife on a companion, was dropped three
times from the yard-arm and received a kick from every sailor on the
ship,—a form of running the gantlope. And we read of a woman who
enlisted as a seaman, and whose sex was detected, being dropped
three times from the yard-arm and tarred and feathered.
These women petitioners for Soldier Weale of whom I have told,
were not the only tender-hearted New Yorkers to petition for “mercy,
that herb of grace, to flower.” During Stuyvesant’s rule his sister,
Madam Bayard, successfully interceded for the release, and thereby
saved the life, of an imprisoned Quaker; and in September, 1713,
two counterfeiters were saved from the death penalty by the
intervention of New York dames. We read, “Most of the gentlewomen
of the city waited on the Governor, and addressed him earnestly with
prayers and tears for the lives of the culprits, who were accordingly
pardoned.” When two sailors rioted through the town demanding
food and drink, and used Carel Van Brugh so roughly that his face
was cut, they were sentenced to be fastened to the whipping-post,
and scourged, and have gashes cut in their faces; the wife of Van
Brugh and her friends petitioned that the sentence should not be
carried out, or at any rate executed within a room. Doubtless other
examples could be found.
The laws of New Netherland were naturally based upon the laws
and customs of the Fatherland, which in turn were formed by the
rules of the College of XIX. from the Imperial Statutes of Charles V.
and the Roman civil law.
The punishments were the ordinary ones of the times, neither
more nor less severe than those of the Fatherland or the other
colonies. In 1691 it was ordered that a ducking-stool be erected in
New York on the wharf in front of the City Hall. The following year an
order was passed that a pillory, cage, and ducking-stool be built.
Though scolds were punished, I have never seen any sentence to
show that this ducking-stool was ever built, or that one was ever
used in New York; while instances of the use of a ducking-stool are
comparatively plentiful in the Southern colonies. The ducking-stool
was an English “engine” of punishment, not a Dutch.
The colonists were astonishingly honest. Thieves were surprisingly
few; they were punished under Dutch rule by scourging with rods,
and usually by banishment,—a very convenient way of shifting
responsibility. Assaults were punished by imprisonment and
subjection to prison fare, consisting only of bread and water or small
beer; and sometimes temporary banishment. There was at first no
prison, so men were often imprisoned in their own houses, which
does not seem very disgraceful. In the case of François de Bruyn,
tried for insulting and striking the court messenger, he was fined two
hundred guilders, and answered that he would rot in prison before he
would pay. He was then ordered to be imprisoned in a respectable
tavern, which sentence seems to have some possibility of mitigating
accompaniments.
In 1692 it was ordered in Kings County that a good pair of stocks
and a pound be made in every bound within Kings County, and kept
in sufficient repair. In repair and in use were they kept till this century.
Pillories too were employed in punishment till within the memory of
persons now living. The whipping-post was really a public blessing,
—in constant use, and apparently of constant benefit, though the
publicity of its employment seems shocking to us to-day. The public
whipper received a large salary. In 1751, we learn from an
advertisement, it was twenty pounds annually.
Some of the punishments were really almost picturesque in their
ingenious inventions of mortification and degradation. Truly it was a
striking sight when “Jan of Leyden”—a foul-mouthed rogue, a true
blather-schuyten—was fastened to a stake in front of the townhouse,
with a bridle in his mouth and a bundle of rods tied under each arm,
and a placard on his breast bearing the inscription, “Lampoon-riter,
false accuser, defamer of magistrates.” Though he was banished, I
am sure he never was forgotten by the children who saw him
standing thus garnished and branded on that spring day in 1664. In
the same place a thief was punished by being forced to stand all day
under a gallows, a gallows-rope around his neck and empty sword-
scabbard in his hand, a memorable figure.
And could any who saw it ever forget the punishment of Mesaack
Martens, who stole six cabbages from his neighbor, and confessed
and stood for days in the pillory with cabbages on his head, that “the
punishment might fit the crime;” to us also memorable because the
prisoner was bootlessly examined by torture to force confession of
stealing fowls, butter, turkeys, etc.
He was not the only poor creature who suffered torture in New
Amsterdam. It was frequently threatened and several times
executed. The mate of a ship was accused of assaulting a sheriff’s
officer, who could not identify positively his assailant. The poor mate
was put to torture, and he was innocent of the offence. The assailant
was proved to be another man from whom the officer had seized a
keg of brandy. Still none in New Amsterdam were tortured or pressed
to death. The blood of no Giles Corey stains the honor of New
Netherland.
Sometimes the execution of justice seemed to “set a thief to catch
a thief.” A letter written by an English officer from Fort James on
Manhattan Island to Captain Silvester Salisbury in Fort Albany in
1672 contains this sentence:—
“We had like to have lost our Hang-man Ben Johnson, for
he being taken in Divers Thefts and Robbings convicted and
found guilty, escaped his neck through want of another
Hangman to truss him up, soe that all the punishment that he
received for his Three Years’ Roguery in thieving and stealing
(which was never found out till now) was only 39 stripes at the
Whipping Post, loss of an Ear and Banishment.”
We have the records of an attempt at capital punishment in 1641;
and Mr. Gerard’s account of it in his paper “The Old Stadt-Huys” is
so graphic, I wish to give it in full:—
“The court proceedings before the Council, urged by the
Fiscal, were against Jan of Fort Orange, Manuel Gerrit the
Giant, Anthony Portugese, Simon Congo, and five others, all
negroes belonging to the Company, for killing Jan Premero,
another negro. The prisoners having pleaded guilty, and it
being rather a costly operation to hang nine able-bodied
negroes belonging to the Company, the sentence was that
they were to draw lots to determine ‘who should be punished
with the cord until death, praying the Almighty God, the
Creator of Heaven and Earth, to direct that the lot may fall on
the guiltiest, whereupon’ the record reads, ‘the lot fell by
God’s Providence on Manuel Gerrit, the Giant, who was
accordingly sentenced to be hanged by the neck until dead as
an example to all such malefactors.’ Four days after the trial,
and on the day of the sentence, all Nieuw Amsterdam left its
accustomed work to gaze on the unwonted spectacle. Various
Indians also gathered, wondering, to the scene. The giant
negro is brought out by the black hangman, and placed on the
ladder against the fort with two strong halters around his
neck. After an exhortation from Domine Bogardus during
which the negro chaunts barbaric invocations to his favorite
Fetich, he is duly turned off the ladder into the air. Under the
violent struggles and weight of the giant, however, both
halters break. He falls to the ground. He utters piteous cries.
Now on his knees, now twisting and groveling on the earth.
The women shriek. The men join in his prayers for mercy to
the stern Director. He is no trifler and the law must have its
course. The hangman prepares a stronger rope. Finally the
cry for mercy is so general that the Director relents, and the
fortunate giant is led off the ground by his swarthy friends,
somewhat disturbed in his intellect by his near view of the
grim King of Terrors.”
Up to February 21, 1788, benefit of clergy existed; that is, the plea
in capital felonies of being able to read. This was a monkish privilege
first extended only to priestly persons. In England it was not
abolished till 1827. The minutes of the Court of General Quarter
Sessions in New York bear records of criminals who pleaded “the
benefit” and were branded on the brawn of the left thumb with “T” in
open court and then discharged.
As the punishments accorded for crimes were not severe for the
notions of the times, it is almost amusing to read some fierce
ordinances,—though there is no record of any executions in
accordance with them. For instance, in January, 1659, by the
Director-General and Council with the advice of the burgomasters
and schepens it was enacted that “No person shall strip the fences
of posts or rails under penalty for the first offence of being whipped
and branded, and for the second, of punishment with the cord until
death ensues.” It is really astonishing to think of these kindly Dutch
gentlemen calmly ordering hanging for stealing fence-rails, though of
course the matter reached further than at first appeared: there was
danger of a scarcity of grain; and if the fences were stolen, the cattle
would trample down and destroy the grain. Later orders as to fences
were given which appear eminently calculated to be mischief-
making. “Persons thinking their neighbors’ fences not good, first to
request them to repair; failing which to report to the overseers.” In
1674 all persons were forbidden to leave the city except by city-gate,
under penalty of death; this was of course when war threatened.
The crime of suicide was not without punishment. Suicides were
denied ordinary burial rites. In Dutch days when one Smitt of New
York committed suicide, the schout asked that his body be drawn on
a hurdle and buried with a stake in his heart. This order was not
executed; he was buried at night and his estates confiscated. When
Sir Danvers Osborne—the Governor for a day—was found dead by
his own act, he was “decently interred in Trinity churchyard.”
Women in New York sometimes made their appearance in New
York courts, as in those of other colonies, in another rôle than that of
witness or criminal; they sometimes sat on juries. In the year 1701,
six good Albany wives served on a jury: Tryntje Roseboom, Catheren
Gysbertse, Angeneutt Jacobse, Marritje Dirkse, Elsje Lansing, and
Susanna Bratt. They were, of course, empanelled for a special duty,
not to serve on the entire evidence of the case for which they were
engaged.
Many old records are found which employ quaint metaphors or
legal expressions; I give one which refers to a custom which seems
at one time to have been literally performed. It occurs in a
commission granted to the trustees of an estate of which the debts
exceeded the assets. Any widow in Holland or New Netherland could
be relieved of all demands or claims of her husband’s creditors by
relinquishing all right of inheritance. This widow took this privilege; it
is recorded thus:—
“Whereas, Harman Jacobsen Bamboes has been lately
shot dead, murdered by the Indians, and whereas the estate
left by him has been kicked away with the foot by his wife who
has laid the key on the coffin, it is therefore necessary to
authorize and qualify some persons to regulate the same.”
There was a well-known Dutch saying which referred to this
privilege, Den Sleutel op het graf leggen, and simply meant not to
pay the debts of the deceased.
This legal term and custom is of ancient origin. In Davies’ “History
of Holland” we read of a similar form being gone through with in
Holland in 1404, according to the law of Rhynland. The widow of a
great nobleman immediately after his death desired to renounce all
claim on his estate and responsibility for his debts. She chose a
guardian, and, advancing with him to the door of the Court (where
the body of the dead Count had been placed on a bier), announced
that she was dressed wholly in borrowed clothing; she then formally
gave a straw to her guardian, who threw it on the dead body, saying
he renounced for her all right of dower, and abjured all debts. This
was derived from a still more ancient custom of the Franks, who
renounced all alliances by the symbolic breaking and throwing away
a straw.
In other states of the Netherlands the widow gave up dower and
debts by laying a key and purse on the coffin. This immunity was
claimed by persons in high rank, one being the widow of the Count
of Flanders.
In New England (as I have told at length in my book, “Customs
and Fashions in Old New England,”) the widow who wished to
renounce her husband’s debts was married in her shift, often at the
cross-roads, at midnight. These shift-marriages took place in
Massachusetts as late as 1836; I have a copy of a court record of
that date.
I know of but one instance of the odious and degrading English
custom of wife-trading taking place in New York. Laurens Duyts, an
agent for Anneke Jans in some of her business transactions, was in
the year 1663 sentenced to be flogged and have his right ear cut off
for selling his wife, Mistress Duyts, to one Jansen. Possibly the
severity of the punishment may have prevented the recurrence of the
crime.
After a somewhat extended study and comparison of the early
court and church records of New England with those of New York, I
cannot fail to draw the conclusion—if it is just to judge from such
comparisons—that the state of social morals was higher in the Dutch
colonies than in the English. Perhaps the settlers of Boston and
Plymouth were more severe towards suspicion of immorality, as they
were infinitely more severe towards suspicion of irreligion, than were
their Dutch neighbors. And they may have given more publicity and
punishment to deviations from the path of rectitude and uprightness;
but certainly from their own records no fair-minded person can fail to
deem them more frail, more erring, more wicked, than the Dutch.
The circumstances of immigration and the tendencies of
temperament were diverse, and perhaps it was natural that a
reaction tending to sin and vice should come to the intense and
overwrought religionist rather than to the phlegmatic and prosperous
trader. In Virginia and Maryland the presence of many convict-
emigrants would form a reasonable basis for the existence of the
crime and law-breaking which certainly was in those colonies far in
excess of the crime in New Netherland and New York.
I know that Rev. Mr. Miller, the English clergyman, did not give the
settlement a very good name at the last of the seventeenth century;
but even his strictures cannot force me to believe the colonists so
unbearably wicked.
It should also be emphasized that New Netherland was far more
tolerant, more generous than New England to all of differing religious
faiths. Under Stuyvesant, however, Quakers were interdicted from
preaching, were banished, and one Friend was treated with great
cruelty. The Dutch clergymen opposed the establishment of a
Lutheran church, and were rebuked by the Directors in Holland, who
said that in the future they would send out clergymen “not tainted
with any needless preciseness;” and Stuyvesant was also rebuked
for issuing an ordinance imposing a penalty for holding conventicles
not in accordance with the Synod of Dort. Many Christians not in
accordance in belief with that synod settled in New Netherland.
Quakers, Lutherans, Church of England folk, Anabaptists,
Huguenots, Waldenses, Walloons. The Jews were protected and
admitted to the rights of citizenship. Director Kieft, with heavy
ransoms, rescued the captive Jesuits, Father Jogues and Father
Bressani, from the Indians and tenderly cared for them. No witches
suffered death in New York, and no statute law existed against
witchcraft. There is record of but one witchcraft trial under the
English governor, Nicholls, who speedily joined with the Dutch in
setting aside all that nonsense.
CHAPTER XIII
CHURCH AND SUNDAY IN OLD NEW YORK

Sunday was not observed in New Netherland with any such rigidity
as in New England. The followers of Cocceius would not willingly
include Saturday night, and not even all of the Sabbath day, in their
holy time. Madam Knight, writing in 1704 of a visit to New York,
noted: “The Dutch aren’t strict in keeping the Sabbath as in Boston
and other places where I have been.” This was, of course, in times of
English rule in New York. Still, much respect to the day was required,
especially under the governing hand of the rigid Calvinist
Stuyvesant. He specially enjoined and enforced strict regard for
seemly quiet during service time. The records of Stuyvesant’s
government are full of injunctions and laws prohibiting “tavern-
tapping” during the hours of church service. He would not tolerate
fishing, gathering of berries or nuts, playing in the street, nor gaming
at ball or bowls during church time. At a little later date the time of
prohibition of noise and tapping and gaming was extended to include
the entire Sabbath day, and the schout was ordered to be active in
searching out and punishing such offenders.
Occasionally his vigilance did discover some Sabbath disorders.
He found the first Jew trader who came to the island of Manhattan
serenely keeping open shop on Sunday, and selling during sermon
time, knowing naught of any Sunday laws of New Amsterdam.
And Albert the Trumpeter was seen on the Sabbath in suspicious
guise, with an axe on his shoulder,—but he was only going to cut a
bat for his little son; and as for his neighbor who did cut wood, it was
only kindling, since his children were cold.
And one Sunday evening in 1660 the schout triumphantly found
three sailors round a tap-house table with a lighted candle and a
backgammon-board thereon; and he surely had a right to draw an
inference of gaming therefrom.
And in another public-house ninepins were visible, and a can and
glass, during preaching-time. The landlady had her excuse,—some
came to her house and said church was out, and one chanced to
have a bowl in his hand and another a pin, but there was no playing
at bowls.
Still, though he snooped and fined, in 1656 the burgomasters
learned “by daily and painful experience” that the profanation of “the
Lord’s day of Rest by the dangerous, Yes, damnable Sale or Dealing
out of Wines Beers and Brandy-Waters” still went on; and fresh
Sunday Laws were issued forbidding “the ordinary and customary
Labors of callings, such as Sowing, Mowing, Building, Sawing wood,
Smithing, Bleeching, Hunting, Fishing.” All idle sports were banned
and named: “Dancing, Card-playing, Tick-tacking, Playing at ball, at
bowls, at ninepins; taking Jaunts in Boats, Wagons, or Carriages.”
In 1673, again, the magistrates “experienced to our great grief”
that rolling ninepins was more in vogue on Sunday than on any other
day. And we learn that there were social clubs that “Set on the
Sabbath,” which must speedily be put an end to. Thirty men were
found by the schout in one tap-huys; but as they were playing
ninepins and backgammon two hours after the church-doors had
closed, prosecution was most reluctantly abandoned.
Of course scores of “tappers” were prosecuted, both in taverns
and private houses. Piety and regard for an orderly Sabbath were
not the only guiding thoughts in the burgomasters’ minds in framing
these Sunday liquor laws and enforcing them; for some tapsters had
“tapped beer during divine service and used a small kind of measure
which is in contempt of our religion and must ruin our state,”—and
the state was sacred. In the country, as for instance on Long Island,
the carting of grain, travelling for pleasure, and shooting of wild-fowl
on Sunday were duly punished in the local courts.
I do not think that children were as rigid church attendants in New
York as in New England. In 1696, in Albany, we find this injunction:
“ye Constables in eache warde to take thought in attending at ye
church to hender such children as Profane ye Sabbath;” and we
know that Albany boys and girls were complained of for coasting
down hill on Sunday,—which enormity would have been simply
impossible in New England, except in an isolated outburst of Adamic
depravity. In another New York town the “Athoatys” complained of
the violation of the Sabbath by “the Younger Sort of people in
Discourssing of Vane things and Running of Raesses.” As for the city
of New York, even at Revolutionary times a cage was set up on City
Hall Park in which to confine wicked New York boys who profaned
the Sabbath. I do not find so full provisions made for seating children
in Dutch Reformed churches as in Puritan meeting-houses. A wise
saying of Martin Luther’s was “Public sermons do very little edify
children”—perhaps the Dutch agreed with him. As the children were
taught the Bible and the catechism every day in the week, their
spiritual and religious schooling was sufficient without the Sunday
sermon,—but, of course, if they were not in the church during
services, they would “talk of vane Things and run Raesses.”
Before the arrival of any Dutch preacher in the new settlement in
the new world, the spiritual care of the little company was provided
for by men appointed to a benign and beautiful old Dutch office, and
called krankebesoeckers or zeikentroosters,—“comforters of the
Sick,”—who not only tenderly comforted the sick and weary of heart,
but “read to the Commonalty on Sundays from texts of Scripture with
the Comments.” These pious men were assigned to this godly work
in Fort Orange and in New Amsterdam and Breuckelen. In Esopus
they had meetings every Sunday, “and one among us read
something for a postille.” Often special books of sermons were read
to the congregations.
In Fort Orange they had a domine before they had a church. The
patroon instructed Van Curler to build a church in 1642; but it was
not until 1646 that the little wooden edifice was really put up. It was
furnished at a cost of about thirty-two dollars by carpenter
Fredricksen, with a predickstoel, or pulpit, a seat for the magistrates,
—de Heerebanke,—one for the deacons, nine benches and several
corner-seats.

You might also like