Professional Documents
Culture Documents
Download pdf Big Java Early Objects 7Th Edition Cay S Horstmann ebook full chapter
Download pdf Big Java Early Objects 7Th Edition Cay S Horstmann ebook full chapter
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 ...
https://textbookfull.com/product/starting-out-with-java-from-
control-structures-through-objects-whats-new-in-computer-
science-7th-edition-gaddis/
https://textbookfull.com/product/transitional-objects-in-early-
childhood-the-value-of-transitional-objects-in-the-early-
years-1st-edition-amanda-norman/
https://textbookfull.com/product/fodor-s-big-island-of-
hawaii-7th-edition-fodors-travel-guides/
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/
https://textbookfull.com/product/java-for-dummies-7th-edition-
barry-a-burd/
https://textbookfull.com/product/beginning-java-9-fundamentals-
arrays-objects-modules-jshell-and-regular-expressions-sharan/
https://textbookfull.com/product/big-data-analytics-with-
java-1st-edition-rajat-mehta/
https://textbookfull.com/product/java-cookbook-problems-and-
solutions-for-java-developers-early-release-ian-f-darwin/
7/e
Cay Horstmann
Cay Horstmann
San Jose State University
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.
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.
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
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
iii
© 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.
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.
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.
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
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
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
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.
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.
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:
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.
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;
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
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.
Array a.length
String a.length()
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.
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)
{
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.
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
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
xv
9.2 Implementing Subclasses 310 10.8 Building Applications with Buttons 368
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
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
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
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
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
How Tos
CH AP TE R Common and
Errors
Worked Examples
© Steve Simzer/iStockphoto.
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
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
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.