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

Complete Download Learning Java An Introduction to Real World Programming with Java 5th Edition Marc Loy PDF All Chapters

Java

Uploaded by

botesbradde9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
68 views

Complete Download Learning Java An Introduction to Real World Programming with Java 5th Edition Marc Loy PDF All Chapters

Java

Uploaded by

botesbradde9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Learning Java An Introduction to Real World


Programming with Java 5th Edition Marc Loy

https://textbookfull.com/product/learning-java-an-
introduction-to-real-world-programming-with-java-5th-
edition-marc-loy/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Learning Java An Introduction to Real World Programming


with Java Marc Loy

https://textbookfull.com/product/learning-java-an-introduction-to-
real-world-programming-with-java-marc-loy/

textboxfull.com

Learning Java Beginning programming with java for dummies


First Edition John Bach

https://textbookfull.com/product/learning-java-beginning-programming-
with-java-for-dummies-first-edition-john-bach/

textboxfull.com

Introduction to Programming in Java An Interdisciplinary


Approach 2nd Edition Robert Sedgewick

https://textbookfull.com/product/introduction-to-programming-in-java-
an-interdisciplinary-approach-2nd-edition-robert-sedgewick/

textboxfull.com

Java An Introduction to Problem Solving and Programming


8th Edition Walter Savitch

https://textbookfull.com/product/java-an-introduction-to-problem-
solving-and-programming-8th-edition-walter-savitch/

textboxfull.com
Learning Network Programming with Java 1st Edition Reese
Richard M

https://textbookfull.com/product/learning-network-programming-with-
java-1st-edition-reese-richard-m/

textboxfull.com

The Real World An Introduction to Sociology 5th Edition


Kerry Ferris

https://textbookfull.com/product/the-real-world-an-introduction-to-
sociology-5th-edition-kerry-ferris/

textboxfull.com

Learning Java Functional Programming 1st Edition Reese


Richard M

https://textbookfull.com/product/learning-java-functional-
programming-1st-edition-reese-richard-m/

textboxfull.com

Java Coding Problems: Become an expert Java programmer by


solving over 200 brand-new, modern, real-world problems,
2nd edition Anghel Leonard
https://textbookfull.com/product/java-coding-problems-become-an-
expert-java-programmer-by-solving-over-200-brand-new-modern-real-
world-problems-2nd-edition-anghel-leonard/
textboxfull.com

Java Coding Problems, 2nd Edition: Become an expert Java


programmer by solving over 200 brand-new, modern, real-
world problems Anghel Leonard
https://textbookfull.com/product/java-coding-problems-2nd-edition-
become-an-expert-java-programmer-by-solving-over-200-brand-new-modern-
real-world-problems-anghel-leonard/
textboxfull.com
1. Preface
a. Who Should Read This Book
b. New Developments
i. New in This Edition (Java 11, 12, 13, 14)
c. Using This Book
d. Online Resources
e. Conventions Used in This Book
f. Using Code Examples
g. O’Reilly Online Learning
h. How to Contact Us
i. Acknowledgments

2. 1. A Modern Language
a. Enter Java
i. Java’s Origins
ii. Growing Up

b. A Virtual Machine
c. Java Compared with Other Languages
d. Safety of Design
i. Simplify, Simplify, Simplify…
ii. Type Safety and Method Binding
iii. Incremental Development
iv. Dynamic Memory Management
v. Error Handling
vi. Threads
vii. Scalability
e. Safety of Implementation

i. The Verifier
ii. Class Loaders
iii. Security Managers

f. Application and User-Level Security


g. A Java Road Map

i. The Past: Java 1.0–Java 11


ii. The Present: Java 14
iii. The Future
iv. Availability
3. 2. A First Application

a. Java Tools and Environment

i. Installing the JDK


ii. Installing OpenJDK on Linux
iii. Installing OpenJDK on Mac
iv. Installing OpenJDK on Windows
v. Configuring IntelliJ IDEA and Creating
a Project
vi. Running the Project
vii. Grabbing the Learning Java Examples
b. HelloJava

i. Classes
ii. The main() Method
iii. Classes and Objects
iv. Variables and Class Types
v. HelloComponent
vi. Inheritance
vii. The JComponent Class
viii. Relationships and Finger Pointing
ix. Package and Imports
x. The paintComponent() Method

c. HelloJava2: The Sequel

i. Instance Variables
ii. Constructors
iii. Events
iv. The repaint() Method
v. Interfaces

d. Goodbye and hello again


4. 3. Tools of the Trade

a. JDK Environment
b. The Java VM
c. Running Java Applications
i. System Properties

d. The Classpath

i. javap
ii. Modules
e. The Java Compiler
f. Trying Java
g. JAR Files

i. File Compression
ii. The jar Utility
iii. The pack200 Utility

h. Building up
5. 4. The Java Language
a. Text Encoding
b. Comments

i. Javadoc Comments
c. Variables and Constants
d. Types

i. Primitive Types
ii. Reference Types
iii. Inferring Types
iv. Passing References
v. A Word About Strings
e. Statements and Expressions
i. Statements
ii. Expressions
f. Arrays

i. Array Types
ii. Array Creation and Initialization
iii. Using Arrays
iv. Anonymous Arrays
v. Multidimensional Arrays
g. Types and Classes and Arrays, oh my!
6. 5. Objects in Java
a. Classes

i. Declaring and Instantiating Classes


ii. Accessing Fields and Methods
iii. Static Members

b. Methods
i. Local Variables
ii. Shadowing
iii. Static Methods
iv. Initializing Local Variables
v. Argument Passing and References
vi. Wrappers for Primitive Types
vii. Method Overloading
c. Object Creation
i. Constructors
ii. Working with Overloaded Constructors

d. Object Destruction
i. Garbage Collection

e. Packages
i. Importing Classes
ii. Custom Packages
iii. Member Visibility and Access
iv. Compiling With Packages

f. Advanced Class design


i. Subclassing and Inheritance
ii. Interfaces
iii. Inner classes
iv. Anonymous inner classes
g. Organizing content and planning for failure
7. 6. Error Handling and Logging

a. Exceptions
i. Exceptions and Error Classes
ii. Exception Handling
iii. Bubbling Up
iv. Stack Traces
v. Checked and Unchecked Exceptions
vi. Throwing Exceptions
vii. try Creep
viii. The finally Clause
ix. Try with Resources
x. Performance Issues
b. Assertions

i. Enabling and Disabling Assertions


ii. Using Assertions

c. The Logging API

i. Overview
ii. Logging Levels
iii. A Simple Example
iv. Logging Setup Properties
v. The Logger
vi. Performance

d. Real-world Exceptions
8. 7. Collections and Generics
a. Collections

i. The Collection Interface


ii. Collection Types
iii. The Map Interface
b. Type Limitations

i. Containers: Building a Better


Mousetrap
ii. Can Containers Be Fixed?
c. Enter Generics

i. Talking About Types

d. “There Is No Spoon”

i. Erasure
ii. Raw Types
e. Parameterized Type Relationships

i. Why Isn’t a List<Date> a


List<Object>?

f. Casts

i. Converting between collections and


arrays
ii. Iterator

g. A closer look: The sort() Method


h. Application: Apples and trees on the field
i. Conclusion
9. 8. Text and Core Utilities

a. Strings
i. Constructing Strings
ii. Strings from Things
iii. Comparing Strings
iv. Searching
v. String Method Summary
b. Things from Strings

i. Parsing Primitive Numbers


ii. Tokenizing Text

c. Regular Expressions
i. Regex Notation
ii. The java.util.regex API

d. Math Utilities

i. The java.lang.Math Class


ii. Big/Precise Numbers

e. Dates and Times


i. Local Dates and Times
ii. Comparing and Manipulating Dates
and Times
iii. Time Zones
iv. Parsing and Formatting Dates and
Times
v. Parsing Errors
vi. Timestamps
f. Other Useful Utilities
10. 9. Threads

a. Introducing Threads

i. The Thread Class and the Runnable


Interface
ii. Controlling Threads
iii. Death of a Thread

b. Synchronization

i. Serializing Access to Methods


ii. Accessing class and instance Variables
from Multiple Threads

c. Scheduling and Priority

i. Thread State
ii. Time-Slicing
iii. Priorities
iv. Yielding

d. Thread Performance
i. The Cost of Synchronization
ii. Thread Resource Consumption
e. Concurrency Utilities

11. 10. Desktop Applications

a. Buttons and sliders and text fields, oh my!


i. Component hierarchies
ii. Model View Controller architecture
iii. Labels and Buttons
iv. Text components
v. Other components
b. Containers and layouts

i. Frames and windows


ii. JPanel
iii. Layout managers

c. Events
i. Mouse events
ii. Action events
iii. Change events
iv. Other events
d. Modals and popups

i. Message dialogs
ii. Confirmation dialogs
iii. Input dialogs

e. Threading considerations

i. SwingUtilities and component updates


ii. Timers
f. Next steps

i. Menus
ii. Preferences
iii. Custom components and Java2D
iv. JavaFX
g. User Interface and User Experience
12. 11. Networking and I/O
a. Streams

i. Basic I/O
ii. Character Streams
iii. Stream Wrappers
iv. The java.io.File Class
v. File Streams
vi. RandomAccessFile
b. The NIO File API

i. FileSystem and Path


ii. NIO File Operations

c. The NIO Package


i. Asynchronous I/O
ii. Performance
iii. Mapped and Locked Files
iv. Channels
v. Buffers
vi. Character Encoders and Decoders
vii. FileChannel
d. Network Programming
e. Sockets

i. Clients and Servers


ii. The DateAtHost Client
iii. A Distributed Game

f. More to explore
13. 12. Programming for the Web
a. Uniform Resource Locators
b. The URL Class
i. Stream Data
ii. Getting the Content as an Object
iii. Managing Connections
iv. Handlers in Practice
v. Useful Handler Frameworks
c. Talking to Web Applications
i. Using the GET Method
ii. Using the POST Method
iii. The HttpURLConnection
iv. SSL and Secure Web Communications
d. Java Web Applications

i. The Servlet Lifecycle


ii. Servlets
iii. The HelloClient Servlet
iv. The Servlet Response
v. Servlet Parameters
vi. The ShowParameters Servlet
vii. User Session Management
viii. The ShowSession Servlet
e. Servlet Containers
i. Configuration with web.xml and
Annotations
ii. URL Pattern Mappings
iii. Deploying HelloClient
f. The World-Wide Web is, well, wide
14. 13. Expanding Java
a. Java Releases
i. JCP and JSRs

b. Lambda Expressions
i. Retrofitting Your Code
c. Expanding Java beyond the core
d. Final wrap up and next steps
15. A. Code Examples and IntelliJ IDEA

a. Grabbing the Main Code Examples


b. Installing IntelliJ IDEA
i. Installing on Linux
ii. Installing on Mac
iii. Installing on Windows
c. Importing the Examples
d. Running the Examples
e. Grabbing the Web Code Examples
f. Working with Servlets
16. Glossary
17. Index
Learning Java
FIFTH EDITION

An Introduction to Real-World Programming with


Java

Marc Loy, Patrick Niemeyer, and Daniel


Leuck
Learning Java

by Marc Loy, Patrick Niemeyer, and Daniel Leuck

Copyright © 2020 Marc Loy, Patrick Niemeyer, Daniel Leuck. All


rights reserved.

Printed in the United States of America.

Published by O’Reilly Media, Inc., 1005 Gravenstein Highway


North, Sebastopol, CA 95472.

O’Reilly books may be purchased for educational, business, or


sales promotional use. Online editions are also available for
most titles (http://oreilly.com). For more information, contact
our corporate/institutional sales department: 800-998-9938 or
[email protected].

Acquisitions Editor: Suzanne McQuade

Developmental Editor: Amelia Blevins

Production Editor: Beth Kelly

Copyeditor: Sonia Saruba

Proofreader:

Indexer:
Interior Designer: David Futato

Cover Designer: Karen Montgomery

Illustrator: Rebecca Demarest

July 2020: Fifth Edition

Revision History for the Early Release


2019-11-14: First Early Release
2020-01-13: Second Early Release
2020-02-05: Third Early Release

See http://oreilly.com/catalog/errata.csp?isbn=9781449319243
for release details.

The O’Reilly logo is a registered trademark of O’Reilly Media,


Inc. Learning Java, the cover image, and related trade dress
are trademarks of O’Reilly Media, Inc.

While the publisher and the authors have used good faith
efforts to ensure that the information and instructions
contained in this work are accurate, the publisher and the
authors disclaim all responsibility for errors or omissions,
including without limitation responsibility for damages resulting
from the use of or reliance on this work. Use of the information
and instructions contained in this work is at your own risk. If
any code samples or other technology this work contains or
describes is subject to open source licenses or the intellectual
property rights of others, it is your responsibility to ensure that
your use thereof complies with such licenses and/or rights.

978-1-492-05627-0

[LSI]
Preface
This book is about the Java programming language and
environment. Whether you are a software developer or just
someone who uses the Internet in your daily life, you’ve
undoubtedly heard about Java. Its introduction was one of the
most exciting developments in the history of the Web and Java
applications have powered much of the growth of business on
the Internet. Java is, arguably, the most popular programming
language in the world, used by millions of developers on
almost every kind of computer imaginable. Java has surpassed
languages such as C++ and Visual Basic in terms of developer
demand and has become the de facto language for certain
kinds of development—especially for web-based services. Most
universities are now using Java in their introductory courses
alongside the other important modern languages. Perhaps you
are using this text in one of your classes right now!

This book gives you a thorough grounding in Java


fundamentals and APIs. Learning Java, Fifth Edition, attempts
to live up to its name by mapping out the Java language and
its class libraries, programming techniques, and idioms. We’ll
dig deep into interesting areas and at least scratch the surface
of other popular topics. Other titles from O’Reilly pick up where
we leave off and provide more comprehensive information on
specific areas and applications of Java.

Whenever possible, we provide compelling, realistic, and fun


examples and avoid merely cataloging features. The examples
are simple, but hint at what can be done. We won’t be
developing the next great “killer app” in these pages, but we
hope to give you a starting point for many hours of
experimentation and inspired tinkering that will lead you to
develop one yourself.

Who Should Read This Book


This book is for computer professionals, students, technical
people, and Finnish hackers. It’s for everyone who has a need
for hands-on experience with the Java language with an eye
toward building real applications. This book could also be
considered a crash course in object-oriented programming,
networking, and user interfaces. As you learn about Java, you’ll
also learn a powerful and practical approach to software
development, beginning with a deep understanding of the
fundamentals of Java and its APIs.

Superficially, Java looks like C or C++, so you’ll have a tiny


head start in using this book if you have some experience with
one of these languages. If you do not, don’t worry. Don’t make
too much of the syntactic similarities between Java and C or
C++. In many respects, Java acts like more dynamic
languages such as Smalltalk and Lisp. Knowledge of another
object-oriented programming language should certainly help,
although you may have to change some ideas and unlearn a
few habits. Java is considerably simpler than languages such
as C++ and Smalltalk. If you learn well from concise examples
and personal experimentation, we think you’ll like this book.

The last part of this book branches out to discuss Java in the
context of web applications, web services, and request
processing, so you should be familiar with the basic ideas
behind web browsers, servers, and documents.

New Developments
This edition of Learning Java is actually the seventh edition—
updated and retitled—of our original, popular Exploring Java.
With each edition, we’ve taken great care not only to add new
material covering additional features, but to thoroughly revise
and update the existing content to synthesize the coverage
and add years of real-world perspective and experience to
these pages.

One noticeable change in recent editions is that we’ve


deemphasized the use of applets, reflecting their diminished
role in recent years in creating interactive web pages. In
contrast, we’ve greatly expanded our coverage of Java web
applications and web services which are now mature
technologies.
We cover all of the important features of the latest “long-term
support” release of Java, officially called Java Standard Edition
(SE) 11, OpenJDK 11, but we also add in a few details from
the “feature” releases of Java 12, Java 13, and Java 14. Sun
(Java’s keeper before Oracle) has changed the naming scheme
many times over the years. Sun coined the term Java 2 to
cover the major new features introduced in Java version 1.2
and dropped the term JDK in favor of SDK. With the sixth
release, Sun skipped from Java version 1.4 to Java 5.0, but
reprieved the term JDK and kept its numbering convention
there. After that, we had Java 6, Java 7, and so on and now
we reach Java 14.

This release of Java reflects a mature language with occasional


syntactic changes and updates to APIs and libraries. We’ve
tried to capture these new features and update every example
in this book to reflect not only the current Java practice, but
style as well.

New in This Edition (Java 11, 12, 13, 14)


This edition of the book continues our tradition of rework to be
as complete and up-to-date as possible. It incorporates
changes from both the Java 11—again, the long term support
version—and Java 12, 13, and 14 feature releases. (More on
the specifics of the Java features included and excluded in
recent releases in Chapter 13.) New topics in this edition
include:
New language features, including type inference in
generics and improved exception handling and
automatic resource management syntax

New interactive playground, jshell, for trying out


code snippets

The proposed switch expression

Basic lambda expressions

Updated examples and analysis throughout the book

Using This Book


This book is organized roughly as follows:

Chapters Chapter 1 and Chapter 2 provide a basic


introduction to Java concepts and a tutorial to give you
a jump start on Java programming.

Chapter 3 discusses fundamental tools for developing


with Java (the compiler, the interpreter, jshell, and
the JAR file package).

Chapters Chapter 4 and Chapter 5 introduce


programming fundamentals then describe the Java
language itself, beginning with the basic syntax and
then covering classes and objects, exceptions, arrays,
enumerations, annotations, and much more.

Chapter 6 covers exceptions, errors, and the logging


facilities native to Java.

Chapter 7 covers collections alongside generics and


parameterized types in Java.

Chapter 8 covers text processing, formatting, scanning,


string utilities, and much of the core API utilities.

Chapter 9 covers the language’s built-in thread


facilities.

Chapter Chapter 10 covers the basics of graphical user


interface (GUI) development with Swing.

Chapter 11 covers Java I/O, streams, files, sockets,


networking, and the NIO package.

Chapter 12 covers web applications using servlets,


servlet filters, and WAR files, as well as web services.

Chapter 13 introduces the Java Community Process


and highlights how to track future changes to Java
while helping you retrofit existing code with new
features such as the lambda expressions introduced in
Java 8.
If you’re like us, you don’t read books from front to back. If
you’re really like us, you usually don’t read the Preface at all.
However, on the off chance that you will see this in time, here
are a few suggestions:

If you are already a programmer and just need to learn


Java in the next five minutes, you are probably looking
for the examples. You might want to start by glancing
at the tutorial in Chapter 2. If that doesn’t float your
boat, you should at least look at the information in
Chapter 3, which explains how to use the compiler and
interpreter. This should get you started.

Chapter 11 and Chapter 12 are the places to head if


you are interested in writing network or web-based
applications and services. Networking remains one of
the more interesting and important parts of Java.

Chapter 10 discusses Java’s graphics features and


component architecture. You should read this if you are
interested in writing desktop graphical Java
applications.

Chapter 13 discusses how to stay on top of changes to


the Java language itself regardless of your particular
focus.
Online Resources
There are many online sources for information about Java.

Oracle’s official website for Java topics is


https://www.oracle.com/technetwork/java/index.html; look
here for the software, updates, and Java releases. This is
where you’ll find the reference implementation of the JDK,
which includes the compiler, the interpreter, and other tools.

Oracle also maintains the OpenJDK site. This is the primary


open-source version of Java and the associated tools. We’ll be
using the OpenJDK for all the examples in this book.

You should also visit O’Reilly’s site at http://oreilly.com/. There


you’ll find information about other O’Reilly books for both Java
and a growing array of other topics. You should also check out
the online learning and conference options—O’Reilly is a real
champion for education in all its forms.

And of course, you can check the home page for Learning
Java!

Conventions Used in This Book


The font conventions used in this book are quite simple.

Italic is used for:

Pathnames, filenames, and program names


Internet addresses, such as domain names and URLs

New terms where they are defined

Program names, compilers, interpreters, utilities, and


commands

Threads

Constant width is used for:

Anything that might appear in a Java program,


including method names, variable names, and class
names

Tags that might appear in an HTML or XML document

Keywords, objects, and environment variables

Constant width bold is used for:

Text that is typed by the user on the command line or


in a dialog

Constant width italic is used for:

Replaceable items in code

In the main body of text, we always use a pair of empty


parentheses after a method name to distinguish methods from
Other documents randomly have
different content
The Two Were Holding a Friendly Talk in the Garden
At this mistress went quickly down the stairs, and when I next saw
her, she had captured the timorous creature, and the two were
holding a friendly chat in the garden. After that Guy made the little
waif a comfortable bed in the basement, and mistress gave her the
name of “Daisy,” while Guy named the yellow cat “Buttercup.”
Maple Road down our way was richly blessed with children in those
days, so much so that the boys called it “Youngsters’ Boulevard.”
And they were all such dear children.
On our right was Charlie Watt, and on our left were the Moody
children, Marie, Anita, Madeline and Charlie. On the opposite side of
the street were Florence and Lee Harrison, and a little way down the
street were our friends Don and Winifred, whose pictures we had
often seen above the bookcase.
Often when mistress went over to Winifred’s house, Toddy and I
followed her, and we used to play with Winifred and Katy—her dolly.
Budge is too bashful to go out in company, so he usually stayed
under the porch till we returned. I guess this is why Guy called him
the “Home Guard.”
Very often Winifred came to visit us. But she never ran after us nor
mauled us around as children are so apt to do. She would sit down
on our cushion and wait till we went and sat by her side. This is why
we all like her so well. If all children would do this, it would be much
more pleasant for us to live with them.
I cannot tell you how much I would like to see Jack and Dennis, but
since I have found so many lovely friends in our new home, I don’t
miss them as much as I did at first.
XXI
OUR WINGED FRIENDS

We soon discovered that cats and dogs were not our only new
neighbors on Maple Road, for one morning early we noticed a pair of
robins flitting around the upper piazza. It was plain that they had
come to stay for a while at least, for they were building a nest among
the vines, and they had it nearly completed. The nest was about half-
way between the two posts. If it had only been at the post, we cats
could have seen what was inside of it.
Two little red-breasted robins were flying back and forth, fetching all
sorts of things in their beaks; straw and strings and moss and grass,
which they twined around in the most curious fashion. One would
step inside and pat it down with his breast, while the other went after
more stuff. At one time one of them brought a black rag, which they
both looked at, and chattered over a great deal, but evidently
concluded not to use for they dropped it on the ground. Then, in her
endeavor to help the robins mistress carried out a loose wad of cut
worsted and placed it near the nest, but they did not make use of
that either. Evidently they knew what they needed better than
anybody else, in the building of their little home.
A day or two after the nest was finished, Guy stepped on a chair and
looked inside, and found one little blue egg in it. After this mistress
and Guy were very careful not to go on the piazza while the robins
were in the nest, for fear they would be frightened, and would desert
their eggs.
About three days later Guy looked again into the nest, and saw two
eggs in it; and a week later when he looked again, there were four.
After the four eggs were laid, one of the robins stayed on the nest
nearly all the time, the other one coming many times during the day,
always bringing his mate something to eat. Mistress named them
Robert and Rena.
We cats wanted to go out on the piazza the worst way during those
days, but the door was always shut.
Sometimes when both robins were away, mistress or Guy would go
on the piazza and scatter bread crumbs, but the naughty little
sparrows would come and take them away from the robins.
It was very hard for me to be a good cat in those days, especially
when mistress would be standing inside the screen door, and Robert
on the flower box answering her call. She would say “Pretty Robbie”
and he would say, “Take care”—I suppose he meant by that she
should take care not to let any harm come to his little mate. But just
as soon as mistress opened the door, he would fly on the
neighboring roof and scold very hard till she shut the door again.
Sometimes when I sat on the window-sill behind the glass pane,
Robert would come just as close to me as he could, talking bird-talk
to me. I think he said: “You can’t catch me,” for he seemed to think
the screen or the window-pane made the porch railing a very safe
place for him.
Robert and Rena seemed to have it all understood between them
how their housekeeping was to be managed. Robert continued very
faithfully to bring food to Rena, and occasionally she would fly out for
a little exercise, Robert staying in the nest till she returned.
After a time we began to hear very queer sounds coming from the
piazza, and a great commotion seemed to be going on in the little
nest. Tiny beaks could be seen, reaching above the edge, and Papa
Robert seemed to be busier than ever. He would bring so much food
at a time that the worms and insects could be seen dangling on each
side of his beak. Sometimes he gave it to Rena, and she would chew
it up and drop a portion into each little beak while he went off for
more; and sometimes he would feed the little ones himself.
They say that accidents happen even in the best regulated
households, so it’s not surprising that they came near having one in
Robert’s family. I was sitting on the window-sill, and Rena was
standing on the flower box chatting with mistress who stood just
inside the door. The screen door happened to be unfastened and
Toddy forced it open without mistress noticing it. So swiftly did he
dart upon the flower box, that he nearly toppled over, and poor Rena
just barely escaped his claws.
As soon as Rena reached a safe distance in the maple tree, she
turned to Toddy and gave him a dreadful scolding. “You ugly cat,”
said she, “aren’t you ashamed to think of robbing my poor little
babies of their mother? You are more cruel than the horrid
huntermen who shoot poor birds with their guns; because they
wouldn’t think of coming in babytime.” Toddy was evidently very
much ashamed, for he sneaked into the house and went straight to
his basket, and didn’t show his face again that day.
If I had had Toddy’s chance of getting out onto the porch, I should
have done quite differently. I would have climbed up on the wire
netting and the vines to the nest where the little birdies were,
because they couldn’t fly away. Oh, what a feast that would have
been—four birds, one after the other. It sets my teeth on edge to
think of it.
One afternoon, when both the robins happened to be away, mistress
went on the piazza to await their return.
Rena came first, and perched on the neighboring housetop, chatting
with mistress, although I think it sounded more as if she were
scolding. Gradually she came nearer the piazza, and finally perched
on the vines opposite the nest. But although her poor little babies
cried most piteously, she would not go near them. But when mistress
went into the house, hardly had she shut the door, when Rena flew
to the nest and began feeding her babies.
That evening a gentleman called upon Aunt Minnie, who was visiting
us, and Mistress told him about the queer conduct of Rena.
“That’s easily explained,” said the gentleman: “Robins are noted for
concealing their young, although they will build their nests in the
most frequented places. If you will take notice after the young are
hatched, there will not be a sign of the shells lying around, neither
will you find any in the nest after they leave, for they carry them all
away.”
“Do you think they will come again next year?” inquired mistress.
“They may if left to themselves, and their nest not tampered with in
the meantime,” said the gentleman.
It was not many days before it became evident that the birdies were
outgrowing their little home. Before their wings were well covered
with feathers, they could be seen stretching them at full length, and
fluttering over the nest, and one day when both Robert and Rena
were out, Guy teased his mother to let him look into the nest.
Mistress consented, so he took a chair out unto the piazza; but
unfortunately the screen door slipped from his grasp and closed with
a very loud noise. This so frightened the birdies that a regular
struggle began in the little nest, and one was forced out over the
side. The poor thing spread his little bare wings and tried to fly, but it
was a desperate effort, and after fluttering aimlessly about, he finally
landed on Buttercup’s porch. Both mistress and Guy went down in
great haste to get him, but the little truant would not be caught, and
his wings seemed to be gaining strength with every second of
exercise. He fluttered across the street, and hovered around on the
lawn, till finally Mr. Harrison picked him up and put him in a tree, and
there Robert and Rena found him and took care of him. I watched
him from the window-sill, and I couldn’t help having some thoughts
that are hardly proper for a good cat.
By the time mistress returned to the piazza, every one of the robins
had left the nest, and we cats saw them no more.
Mistress gave many anxious sighs during that afternoon, and Guy
tried to comfort her as best he could. “If God takes care of the
sparrows,” said he, “don’t you suppose He will also take care of the
robins?”
Mistress did not speak for some moments, then she said: “Well, my
boy, some day you will be leaving your home just as the birdies left
theirs to-day, and dangers will surround you. Then my dear, may you
lean hard on the Book wherein you read that God takes care of the
sparrows.”
I am very glad I have had a chance to get acquainted with the robins,
and I hope next spring they will come to us again.
XXII
NEW NEIGHBORS

In the rear of our yard there was a very tall fence post with a flat top,
and on it I loved to sit in the sun and watch the chickens in the
adjoining yard.
Near the chicken-coop was a kennel wherein lived Napoleon, a black
shepherd dog, whom they called “Nap” for short. When I first knew
Nap he was chained almost constantly, and often for days at a time
he was without food or water. His howls and cries were pitiful, and all
the neighbors talked about what an outrage it was to treat a dog so
mean. One day our mistress called Nap’s mistress over to the fence
and engaged her in a friendly talk, and after a while she asked why
Nap was always chained. The lady said it was because her husband
considered him a very valuable dog, and did not wish to lose him.
“Have you ever tried to bind him to his home with love and
affection?” said mistress. “I have found in my experience with
animals that it will forge a chain far stronger than iron.”
The lady said she would speak to her husband, and I am sure she
has, for after that Nap had his meals more regularly, and he was free
to roam where he pleased; and he proved himself very useful to the
old hens in helping to keep strange cats out of the yard, while their
chicks were small.
One Sunday morning when mistress was out in the yard with us,
Nap came over to our fence barking for joy, and peeping in at us
between the pickets. He seemed so happy to be at liberty. Mistress
had brought a lunch out for us, and she offered him some of the
meat, which he devoured greedily. I was glad to share my breakfast
with him, for having known Dennis so long, I cannot help feeling very
friendly toward all dogs.
But Budge and Toddy evidently did not care to share their meat with
Nap, so they did what cats often do when they meet with an
unpleasant surprise; they sang a song. Budge’s voice is a baritone,
Toddy’s a tenor and mine a soprano. But I did not join them on this
occasion.
I suppose you have often listened to cat concerts, and perhaps you
have wondered why cats’ music is always so sad and doleful. The
reason for this is that cats sing only when they are sad or in trouble,
when they are contented and happy, they purr.
As soon as the song was ended, Napoleon began to whine, and
thrust his nose between the pickets again. I think he wanted more
song, but Toddy evidently thought he wanted more breakfast, for the
moment his nose was well through between the pickets, Toddy made
a lunge for it, and this proved to be Napoleon’s Waterloo. Before he
could withdraw, his nose was a perfect network of scratches, with
blood oozing out of them like so many small beads.
After Napoleon had retreated, mistress called us into the house, but
in the afternoon I went out there again and jumped over on Nap’s
side of the fence into the tall grass. But the old speckled hen drove
me back with her cackle as she had often done before. She probably
thought I was another naughty cat like Buttercup who stole her
chickies; but, really, I was only looking for grasshoppers. Now,
although I am not much acquainted with Napoleon, I have given him
a place in my book, because I want my readers to stop and think
how cruel it is to keep a dog chained all the time, and to leave him
without his regular supply of food and water.
I will now tell you about Bunny, a little Manx cat that came to our
house every evening at supper-time. She did not offer to stay only
just long enough to get something to eat. Guy named her “Bunny”
because she has only a little stump of a tail, and when running she
would raise her back just like a rabbit. I think Bunny must have come
from the same country that Jack did, for she was the same kind of a
cat, only she was gray, just like Budge. In fact she resembled Budge
so much that we were all horrified the first time we saw her. We
thought it was Budge himself, and that some one had cut off his tail.
But while Toddy and I were busy smelling of the stranger, and
mistress was bewailing the sad fate of her pet, in walked Budge, tail
and all, carrying in his mouth a dead sparrow, which he laid at
mistress’ feet with a great deal of pride. Then Toddy and I left off
examining Bunny and turned our attention to the bird.
Mistress often used to say she wondered where Bunny got the rest
of her meals, and where she kept herself; so one evening after
Bunny had eaten her supper, Guy and I followed her; and what do
you suppose we found? We traced Bunny into a vacant lot, and
there under some shrubs was a little cave, dug into a bank of
autumn leaves. This was Bunny’s home, and in it she had living with
her five as chipper and lively little Manx cats as one could wish to
see. Guy interested Don and Teddie in the little Bunnies, and the two
boys brought them food mornings and noons; so that thereafter they
had three square meals a day. The boys also found good homes for
them as soon as they were old enough to leave their mother.
In the rear part of Mrs. Watt’s yard the grass is allowed to stand all
summer so it becomes very tall. It was just a capital place for us cats
to play hide-and-go-seek, and to catch grasshoppers. I heard
mistress say to Charlie one day that she wondered what we cats
found to interest us so much in his back yard; so I thought I would
show her. The following Sunday, when she sat on the piazza, I
carried a hopper up-stairs and laid him down at her feet. She was
busy reading and did not notice him at once; but when he began
flying around and I after him, she laid her book down and watched
us. After the hopper had landed on the floor several times, and I had
had several rounds with him, he seemed pretty well tired out, and
remained still for a few moments. Mistress picked him up, and
seeing he was not the least bit injured, she placed him on the vines,
which was very nice for the hopper, but rather cruel to me, I thought.
But nothing daunted, I went down-stairs and fetched another one. As
I laid him on the floor mistress seemed horrified, for she thought I
had mutilated him carrying him so far. She had not known up to this
time where the first one came from. She was just reaching out to
take my treasure from me, when Mr. Hopper flew toward the ceiling,
which led her to conclude that he must be all right, and she did not
interfere with me any further. Thus during the warm summer weather
I had many pleasant times with my little playfellow, the grasshopper.
XXIII
OUR SUMMER OUTING

When the time came again for mistress and Guy to take their outing,
they were quite puzzled what to do with so many cats.
“It was easy enough,” said mistress, “to take one cat when we
traveled by boat, and went to grandpa’s. But three cats, and traveling
on wheels, and stopping at hotels, is quite a different thing.”
“Perhaps you can make an arrangement with Charlie Watt to take
care of them,” said Guy.
Mrs. Watt was sitting on her veranda, and before mistress went away
that morning, she went over and asked whether Charlie could take
care of us during her absence; and as Charlie was present and said
he would be delighted to do it, his mother assented.
I was very thankful, for Charlie and his mother had always been very
kind to us.
Soon after that, one morning, two gentlemen called, and mistress
and Guy rode away with them. Our basket and plate had been
placed in Mrs. Watt’s kitchen, and Charlie fixed us a very nice meal
at dinner-time, and we played with the grasshoppers in his yard, so
the first day went off all right.
But the very next day we saw what threatened to destroy our peace
of mind at Charlie Watt’s. His neighbor had a great fat pug dog, who
acted very ungentlemanly from the first, and tried his best to frighten
us, peeping between the fence pickets and barking as loud as he
could. That very morning the grocer had left our gate open, and Pug
who had been watching for such a chance, came in, snorting with
rage. It was clearly a declaration of war; but to my great surprise,
Budge, who is usually very timid, was the first to take up arms
against the enemy. With the most artistic curve in his back, and
bristling his tail to suit the occasion, he started out, single-handed
and alone. Of course, Toddy and I were not slow to follow such a
courageous leader, and for a time the peaceful yard resembled a
torrid race-track, with Pug in the lead and myself on the home-
stretch.
As round after round took a little wider range, Pug was nearing the
corner where the ash pile is located, and stumbling over a tin can, he
fell to the ground, and we three on top of him. Being such a fat
fellow, he was much more easily exhausted than we, who are lithe
and agile; and once down, surrounded as he was, his defeat was
complete. Nothing remained but an ignominious surrender. He
crouched like the coward that he was, begging for mercy. But we did
not let him off until we had thoroughly humbled him, chasing him
back several times when he attempted to go, and that was the last
difficulty we ever had with Pug.
One night during mistress’ absence, we heard a terrible noise, and
the next morning Buttercup’s mangled and bleeding body lay in our
front yard. It was said that a dog had done the awful deed.
But the cat population was not diminished by Buttercup’s sudden
taking off, for on that very same morning, Daisy had a little spreckled
kitty in her basket—only one. But that was enough for poor little
Daisy to take care of, for she had a rattle in her throat, which Dr.
Smith called “consumption.” I think that is why Daisy was not invited
to go with us to Mrs. Watt’s. But Charlie gave her food and water
daily at the basement window, and after Buttercup was gone, she
had her own little kitten to keep her company.
We were just enjoying our vacation very nicely, when one morning
Budge disappeared, and that night we could not find him anywhere,
although we could hear his doleful cry coming from some place, no
one knew just where. I tremble to think what would have become of
poor Budge, if mistress hadn’t come home in time to save him.
Late the next afternoon she and Guy rode up to the curb. I was lying
on the grass, and Toddy was in the hammock with Charlie.
As soon as I heard mistress’ voice, I rushed out to meet her, and she
picked me up and petted me, and said how glad she was to get
home again. Then Mrs. Watt told her the distressing news that
Budge had not been seen for two days. As soon as Guy reached his
room up-stairs, he heard a muffled “meow” coming out of the wall,
and in reply to his name Budge answered “meow,” “meow.” In the
cellar his voice could be heard very plainly, so mistress went there
and tried to coax him down with a piece of raw beefsteak. He was
just above the studding; having taken fright at something, and
crawled up between the boards of the inside and outside wall, to the
second story.
After trying for several hours to coax him down, mistress went at ten
o’clock at night to get a carpenter to open the wall. The good man
had already gone to bed, but he arose and came with mistress. He
pried away a base board in Guy’s room, and Budge stuck his head
through the opening, and mistress pulled him out. Toddy and I were
very glad to have our companion with us again, and I hope another
time Budge will know enough to run up a tree, instead of getting
himself into such a predicament.
The day before mistress came home, a water spaniel puppy arrived
from the country, that had been sent to Charlie as a present. He
looked just like Dennis, and I hoped he would grow to be as good
and wise a dog; but it was not to be so, for he only lived a few days
after he came. They named him “Brownie.” So innocent and
unsuspecting was he, he would walk right up to us cats and kiss our
noses. If he had been a big handsome dog like Dennis, we would not
have objected so much. But lady cats don’t care to be kissed by silly
little puppy dogs. But no matter how many times Toddy scratched his
face, Brownie was so forgiving; the very next minute he would go up
to him again. As for Budge, whenever Brownie came near him, he
growled so deep down in his throat that once mistress actually
looked up into the sky and asked Guy whether he heard that
thundering, and Brownie did not venture any farther. After getting
several more scratches and a good many taps, he finally stayed
away from Toddy. But he came to me whenever he wanted to, and I
tried to teach them by my example that a little innocent, harmless
puppy is not to be treated like a big, saucy, ferocious dog.
If Brownie had not disobeyed his mistress I think he would be with us
still; but the day after we returned home he came into our yard
between the fence pickets and helped himself to a dinner that was
intended for three cats, a little more than a puppy dog ought to
attempt at a single meal. But Brownie evidently thought himself
equal to it, and when he went away, our plate was empty. He could
not go back the way he came, but had to go around the house and
through the gate. That was Brownie’s last visit to us, for that same
evening, after suffering dreadful agonies in spite of all that mistress
and Mrs. Watt did for him, poor Brownie lay down on the lawn and
died.
I couldn’t help thinking of poor Dappledun, of whom it is written:

“He ran in clover up to his knees,


His trough was filled with stuff;
Yet he’d jump the neighbor’s fence, and act
As if he hadn’t enough.

“If only he could have been content


With his feed of oats and hay,
Poor headstrong, foolish Dappledun
Had been alive to-day.

“But one night when the rack was filled


With what he ought to eat,
He thrust his nose out of his stall,
And into a bin of wheat.

“And there he ate, and ate, and ate,


And when he reached the tank
Where Johnny watered him next morn,
He drank, and drank, and drank.

“And when that night John carried him


The sweet hay from the rick,
He lay and groaned, and groaned, and groaned,
For Dappledun was sick.

“And when another morning came


And John rose from his bed,
And went to water Dappledun,
Poor Dappledun was dead!”

Early the following morning I saw Mr. Watt carry the little stiff body
out to the rear part of the yard, where he dug a deep, dark hole.
There he planted Brownie just as the rays of the rising sun were
gleaming over the housetop; and it seemed as though even the
proud and stately hollyhocks were bending their heads in sorrow
over our young friend’s untimely taking off.
So you see we had all sorts of experiences during our summer
vacation.
XXIV
RAISING A FAMILY

Very soon after we had gone to Maple Road to live, one night a lot
of little kittens came into my basket; I suppose the kind Providence
had sent them, for it was not yet time for Santa Claus to be around
again. The little things squirmed and whined most pitifully, and I
covered them with my body to keep them warm.
As soon as it was daylight I took a look at my visitors, and there,
behold, were six little blind, helpless creatures, two tigers, two
Maltese and two black. “What will my mistress say,” thought I, “when
she sees this?” I must confess I awaited her coming with some
misgiving, fearing very much that she would be displeased.
When mistress opened the door in the morning I arose and went to
meet her as usual, and I apologized as best I could; but she did not
even seem surprised. She petted me just as she was wont to do, or
if anything even more fondly, and my saucer of milk that morning
tasted as if it was more than half cream. While I was eating my
breakfast, Guy came out, and together they examined my kittens,
and praised them. “Aren’t they beauts,” said he, as he fondled one
after the other; “I wish we could keep them all.”
After breakfast mistress lifted the pad with my kittens out of the
basket and made us up a fresh clean bed with an old comfortable,
which was large enough to fall over the rim of the basket, and so
prevented any draughts from striking my little ones. Then for many
days mistress brought my food and water to me, for with so many
kittens I was busy every minute washing them to keep them sweet
and clean.
At the end of about ten days my kittens began to open their eyes;
and to be able to crawl over each other, and over me as well. One by
one, as their eyesight became stronger, they would crawl up on the
comfortable and look over the edge of the basket; and very often one
would step over a little too far, lose his balance and tumble over unto
the floor. Then after a few minutes of groping around he would begin
to cry, and I had to go and bring him back, unless Guy or mistress
happened to be there.
One day I heard mistress say to Guy: “These kittens seem to be
strong in their bodies but weak in their limbs, they topple over when
they attempt to walk.”
“They need to exercise their limbs more,” said Guy. “They ought to
have a larger place to move around in.”
Then mistress spread an old comfortable on the floor in a sheltered
corner of her room, and placed a market-basket in the middle of it, in
the bottom of which was a bag full of stones to keep it from falling
over when the kittens should climb up on the side of it. Mistress then
put the kittens on the comfortable, and in an instant they began
hobbling around and in and out of the basket. I lay on the
comfortable with them, and watched them with great pleasure.
Whenever one got far enough away from the “gym” (as Guy called
the basket) to feel lonesome, he would whine; but at my call would
follow the direction of my voice, and promptly return. By degrees
they became so independent that they would walk clear to the edge
of the thick comfortable, tumble over the “embankment,” and
meander off at their own sweet will; and so they grew daily stronger.
One pleasant Sunday when mistress and Guy were at home, the
comfortable was spread on the garden lawn, with the basket upon it
as usual. At first I protested most seriously against this innovation,
and started to take my kittens back to their accustomed place in the
house. But they had grown so large, it was impossible for me to
carry them up the steps, and I had to let them stay. I soon found,
however, that the radiant sunshine was as a tonic to them, filling
them with joy and strength and courage, and before the afternoon
was gone, I had become well pleased with the change.
Just as soon as the sunshine disappeared, Guy put the kittens into
the basket and carried them back into the house, and after that I
never objected when they were given an outing.
Oh, how very happy I was in those days, with my little ones basking
around me in the beautiful sunshine, for even in the house mistress
always saw to it that our comfortable was in a sunny place. The
basket became the scene of most wonderful activity. Guy said it was
horizontal bar, side horse, long horse and race-track all in one; and
here were performed some remarkable acrobatic feats, all of which
served to make my little ones strong and steady. Of course I was
very busy training them in various ways, and first of all I took great
care to teach them clean and orderly habits. In this respect mistress
was always very helpful, for she left each day a little box of fresh
earth beside my basket, and whenever she saw one hunt around
and get into a corner, she would go after him and set him into the
box, and very soon they understood what it was there for.
As soon as they were old enough I tried to teach them to lap milk
with me from the saucer, and this proved to be the hardest task of
all. They seemed to get the milk all up into their noses, instead of on
their tongues, and it was a veritable sneezing bee. Then again some
seemed to think that the saucer was a bath tub. Topsy, one of the
black ones, walked deliberately into the dish, and when in the middle
of it, sat down and took a sitz bath. Guy said he guessed she wanted
to change her complexion. But in a few moments she landed safely
on the other side. Meow Junior, one of the tigers, was satisfied to
merely face about and dip his tail into the milk, much to the disgust
of the rest. But in a few days they had learned to lap milk very nicely,
and I thought it was time to take the next step in their education; so I
carried my piece of beef to them, to teach them how to chew
something solid.
When mistress saw it she was quite alarmed, and promptly took the
meat away. But I persisted, fetching it back several times, till finally
she let me have my way, saying that a mother was the best judge of
what was good for her children. Then seeing that only one could get
access to the piece, because he would growl so fiercely as to
frighten the others away, she gave a piece of meat to each one. Of
course, they could not chew very much as yet, and the pieces were
too large to swallow whole, but it was excellent exercise for their
jaws and teeth, and a pleasant pastime as well.
On the first day that my kittens began to feed from a dish, they also
began to practice at washing themselves, and it was a winsome
sight to watch their earnest endeavors to do their very best. I was so
thankful that mistress did not forget to keep a saucer of water in a
convenient place for them. Then, having made their toilet, usually
they would lie down in groups of two, or three, and take their after
dinner nap.
One day when I was on mistress’ bed with my kittens, Guy laid his
hat down by us, and Topsy went over and lay on the crown of it. It
being a soft felt, her weight caused the crown to cave in, but this
seemed to suit Topsy all the better. She settled down contentedly in
the little round box and began to purr so loudly as to attract the
attention of the other kittens. Meow Junior, seeing that Topsy had
found such a good thing, concluded to join her; and so one by one
they all deserted me, and meandered in the direction of the hat.
When I looked up, to my great amusement the five kittens were lying
in a circle on the rim with Topsy in the middle, and the hat had the
appearance of being trimmed with cats.
In telling this incident I hope I shall not set any one to thinking that
kittens would make suitable ornaments instead of the poor unhappy
birds that do such melancholy duty on some ladies’ hats.
Thus for many weeks I devoted myself so constantly to my little ones
that mistress called me “the good little mother.”
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like