100% found this document useful (2 votes)
11 views50 pages

An Introduction To Object Oriented Programming With Java 5th Edition by Thomas Wu 0073523305 9780073523309 Instant Download

The document is about the 5th edition of 'An Introduction to Object Oriented Programming with Java' by Thomas Wu, which emphasizes an object-first approach to teaching Java. It highlights key changes from previous editions, including a focus on Java 5.0 features, exclusive use of console input/output, and more examples from natural sciences. The book is structured to include programming exercises of varying difficulty levels to enhance learning.

Uploaded by

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

An Introduction To Object Oriented Programming With Java 5th Edition by Thomas Wu 0073523305 9780073523309 Instant Download

The document is about the 5th edition of 'An Introduction to Object Oriented Programming with Java' by Thomas Wu, which emphasizes an object-first approach to teaching Java. It highlights key changes from previous editions, including a focus on Java 5.0 features, exclusive use of console input/output, and more examples from natural sciences. The book is structured to include programming exercises of varying difficulty levels to enhance learning.

Uploaded by

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

An Introduction to Object Oriented Programming

With Java 5th Edition by Thomas Wu 0073523305


9780073523309 pdf download

https://ebookball.com/product/an-introduction-to-object-oriented-
programming-with-java-5th-edition-by-thomas-
wu-0073523305-9780073523309-17244/

Explore and download more ebooks or textbooks


at ebookball.com
We have selected some products that you may be interested in
Click the link to download now or visit ebookball.com
for more options!.

An Introduction to Object Oriented Programming With Java


5th Edition by Thomas Wu 0073523305 9780073523309

https://ebookball.com/product/an-introduction-to-object-oriented-
programming-with-java-5th-edition-by-thomas-
wu-0073523305-9780073523309-15256/

An Introduction to Object Oriented Programming With Java


5th Edition by Thomas Wu 0073523305 9780073523309

https://ebookball.com/product/an-introduction-to-object-oriented-
programming-with-java-5th-edition-by-thomas-
wu-0073523305-9780073523309-15330/

An Introduction to Object Oriented Programming with Java


5th Edition by Thomas Wu ISBN 9780073523309 0073523305

https://ebookball.com/product/an-introduction-to-object-oriented-
programming-with-java-5th-edition-by-thomas-wu-
isbn-9780073523309-0073523305-15552/

An Introduction to Object Oriented Programming with Java


5th Edition by Thomas Wu ISBN 0073523305 9780073523309

https://ebookball.com/product/an-introduction-to-object-oriented-
programming-with-java-5th-edition-by-thomas-wu-
isbn-0073523305-9780073523309-16398/
Object Oriented Programming with Java 1st edition By
Hanumanth Ladwa ISBN 8450193403 9788450193403

https://ebookball.com/product/object-oriented-programming-with-
java-1st-edition-by-hanumanth-ladwa-
isbn-8450193403-9788450193403-25034/

Microsoft Visual C# 2017 An Introduction to Object


Oriented Programming 7th Edition by Joyce Farrell ISBN
1337102100 9781337102100
https://ebookball.com/product/microsoft-visual-c-2017-an-introduction-
to-object-oriented-programming-7th-edition-by-joyce-farrell-
isbn-1337102100-9781337102100-25038/

Beginning C 3 0 an introduction to object oriented


programming 1st edition by Jack Purdum 0470261293
978-0470261293
https://ebookball.com/product/beginning-c-3-0-an-introduction-to-
object-oriented-programming-1st-edition-by-jack-
purdum-0470261293-978-0470261293-15238/

Object Oriented Programming Using C An Introduction 1st


Edition by Pardoe, King 0333692411 978-0333692417

https://ebookball.com/product/object-oriented-programming-using-c-an-
introduction-1st-edition-by-pardoe-
king-0333692411-978-0333692417-15282/

Object Oriented Programming and Java 1st Edition by Danny


Poo, Derek Kiong 9813083964 9789813083967

https://ebookball.com/product/object-oriented-programming-and-
java-1st-edition-by-danny-poo-derek-
kiong-9813083964-9789813083967-15306/
www.allitebooks.com
An Introduction to Object-Oriented
TM
Programming with Java
Fifth Edition

C.Thomas Wu
Naval Postgraduate School

www.allitebooks.com
AN INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING WITH JAVA™, FIFTH EDITION

Published by McGraw-Hill, a business unit of The McGraw-Hill Companies, Inc., 1221 Avenue of the
Americas, New York, NY 10020. Copyright © 2010 by The McGraw-Hill Companies, Inc. All rights reserved.
Previous editions © 2006, 2004, and 2001. No part of this publication may be reproduced or distributed in any
form or by any means, or stored in a database or retrieval system, without the prior written consent of The
McGraw-Hill Companies, Inc., including, but not limited to, in any network or other electronic storage or
transmission, or broadcast for distance learning.

Some ancillaries, including electronic and print components, may not be available to customers outside the
United States.

This book is printed on acid-free paper.

1 2 3 4 5 6 7 8 9 0 DOC/DOC 0 9

ISBN 978–0–07–352330–9
MHID 0–07–352330–5

Global Publisher: Raghothaman Srinivasan


Director of Development: Kristine Tibbetts
Developmental Editor: Lorraine K. Buczek
Senior Marketing Manager: Curt Reynolds
Senior Project Manager: Jane Mohr
Lead Production Supervisor: Sandy Ludovissy
Lead Media Project Manager: Stacy A. Patch
Associate Design Coordinator: Brenda A. Rolwes
Cover Designer: Studio Montage, St. Louis, Missouri
(USE) Cover Image: © Getty Images
Compositor: Macmillan Publishing Solutions
Typeface: 10.5/12 Times Roman
Printer: R. R. Donnelley Crawfordsville, IN

All credits appearing on page or at the end of the book are considered to be an extension of the copyright page.

Library of Congress Cataloging-in-Publication Data

Wu, C. Thomas.
An introduction to object-oriented programming with Java / C. Thomas Wu (Otani).—5th ed.
p. cm.
Includes index.
ISBN 978–0–07–352330–9— ISBN 0–07–352330–5 (hard copy : alk. paper) 1. Object-oriented
programming (Computer science) 2. Java (Computer program language) I. Title.
QA76.64.W78 2010
005.1'17—dc22

2008053612

www.mhhe.com

www.allitebooks.com
To my family

www.allitebooks.com
www.allitebooks.com
Contents

Preface xi

0 Introduction to Computers and


Programming Languages 1
0.1 A History of Computers 2
0.2 Computer Architecture 4
0.3 Programming Languages 11
0.4 Java 12

1 Introduction to Object-Oriented Programming and


Software Development 15
1.1 Classes and Objects 16
1.2 Messages and Methods 18
1.3 Class and Instance Data Values 20
1.4 Inheritance 23
1.5 Software Engineering and Software
Life Cycle 24

2 Getting Started with Java 29


2.1 The First Java Program 30
2.2 Program Components 39
2.3 Edit-Compile-Run Cycle 49
2.4 Sample Java Standard Classes 52
2.5 Sample Development 69
v

www.allitebooks.com
vi Contents

3 Numerical Data 85
3.1 Variables 86
3.2 Arithmetic Expressions 94
3.3 Constants 99
3.4 Displaying Numerical Values 101
3.5 Getting Numerical Input 107
3.6 The Math Class 113
3.7 Random Number Generation 117
3.8 The GregorianCalendar Class 120
3.9 Sample Development 125
3.10 Numerical Representation (Optional) 136

4 Defining Your Own Classes—Part 1 151


4.1 First Example: Defining and Using a Class 152
4.2 Second Example: Defining and Using Multiple Classes 162
4.3 Matching Arguments and Parameters 166
4.4 Passing Objects to a Method 168
4.5 Constructors 173
4.6 Information Hiding and Visibility Modifiers 180
4.7 Class Constants 183
4.8 Local Variables 191
4.9 Calling Methods of the Same Class 193
4.10 Changing Any Class to a Main Class 197
4.11 Sample Development 198

5 Selection Statements 221


5.1 The if Statement 222
5.2 Nested if Statements 233
5.3 Boolean Expressions and Variables 239
5.4 Comparing Objects 247
5.5 The switch Statement 252
5.6 Drawing Graphics 256
5.7 Enumerated Constants 266
5.8 Sample Development 272

www.allitebooks.com
Contents vii

6 Repetition Statements 303


6.1 The while Statement 304
6.2 Pitfalls in Writing Repetition Statements 313
6.3 The do–while Statement 319
6.4 Loop-and-a-Half Repetition Control 323
6.5 The for Statement 327
6.6 Nested for Statements 332
6.7 Formatting Output 334
6.8 Loan Tables 339
6.9 Estimating the Execution Time 342
6.10 Recursive Methods (Optional) 346
6.11 Sample Development 351

7 Defining Your Own Classes—Part 2 373


7.1 Returning an Object from a Method 374
7.2 The Reserved Word this 378
7.3 Overloaded Methods and Constructors 386
7.4 Class Variables and Methods 391
7.5 Call-by-Value Parameter Passing 395
7.6 Organizing Classes into a Package 402
7.7 Using Javadoc Comments for
Class Documentation 403
7.8 The Complete Fraction Class 408
7.9 Sample Development 418

8 Exceptions and Assertions 445


8.1 Catching Exceptions 446
8.2 Throwing Exceptions and Multiple catch Blocks 453
8.3 Propagating Exceptions 458
8.4 Types of Exceptions 466
8.5 Programmer-Defined Exceptions 469
8.6 Assertions 471
8.7 Sample Development 477

www.allitebooks.com
viii Contents

9 Characters and Strings 495


9.1 Characters 496
9.2 Strings 499
9.3 Pattern Matching and Regular Expression 510
9.4 The Pattern and Matcher Classes 517
9.5 Comparing Strings 521
9.6 StringBuffer and StringBuilder 523
9.7 String Processing and Bioinformatics 529
9.8 Sample Development 533

10 Arrays and Collections 555


10.1 Array Basics 556
10.2 Arrays of Objects 567
10.3 The For-Each Loop 577
10.4 Passing Arrays to Methods 582
10.5 Two-Dimensional Arrays 589
10.6 Lists and Maps 596
10.7 Sample Development 609

11 Sorting and Searching 633


11.1 Searching 634
11.2 Sorting 638
11.3 Heapsort 646
11.4 Sample Development 659

12 File Input and Output 685


12.1 File and JFileChooser Objects 686
12.2 Low-Level File I/O 695
12.3 High-Level File I/O 700

www.allitebooks.com
Contents ix

12.4 Object I/O 709


12.5 Sample Development 716

13 Inheritance and Polymorphism 733


13.1 A Simple Example 734
13.2 Defining Classes with Inheritance 737
13.3 Using Classes Effectively with Polymorphism 741
13.4 Inheritance and Member Accessibility 744
13.5 Inheritance and Constructors 749
13.6 Abstract Superclasses and Abstract Methods 753
13.7 Inheritance versus Interface 758
13.8 Sample Development 759

14 GUI and Event-Driven Programming 787


14.1 Simple GUI I/O with JOptionPane 790
14.2 Customizing Frame Windows 793
14.3 GUI Programming Basics 799
14.4 Text-Related GUI Components 808
14.5 Layout Managers 820
14.6 Effective Use of Nested Panels 830
14.7 Other GUI Components 839
14.8 Menus 857
14.9 Handling Mouse Events 861

15 Recursive Algorithms 881


15.1 Basic Elements of Recursion 882
15.2 Directory Listing 883
15.3 Anagram 885
15.4 Towers of Hanoi 888
15.5 Quicksort 890
15.6 When Not to Use Recursion 895

www.allitebooks.com
x Contents

Appendix A How to Run Java Programs 903

Appendix B Sample Programs 911

Appendix C Standard Classes and Interfaces 933

Appendix D UML Diagrams 955

Index 963
Preface

T his book is an introduction to object-oriented programming using the Java


programming language. We use the object-first approach where objects are used
from the first sample program. Object-oriented thinking is emphasized and pro-
moted from the beginning. Students learn how to use objects first and then learn
how to define their own objects.

Key Changes in the 5th Edition


The key differences between this edition and the fourth edition are as follows:
1. More Discussion on Java 5.0 Features and Java 6.0 Compatibility. Many
of the new Java 5.0 features are explained and used in the sample programs.
They include the enumerator type, the for-each loop construct, auto boxing
and unboxing, and the generics.
2. Exclusive Use of Console Input and Output. All the GUI related topics,
including the JOptionPane class, are moved to Chapter 14. Sample programs
before Chapter 14 use the standard console input (Scanner) and output
(System.out). Those who want to use JOptionPane for simple input and output
can do so easily by covering Section 14.1 before Chapter 3.
3. More Examples from Natural Sciences. In several key chapters, we illus-
trate concepts using examples from biology and chemistry. For example, in
Chapter 4, we use the elements in the periodic table to illustrate the concept of
programmer-defined classes. In Chapter 9, we demonstrate how the string
processing techniques are applied to implement DNA sequencing and other
common DNA operations.
4. Level-by-level Organization for Programming Exercises. Programming
exercises at the end of chapters are organized into three levels of difficulties.
The one-star level exercises require the basic understanding of the materials
covered in the chapter. The two-star level exercises require some additional
thinking beyond the basic understanding. The three-star level exercises are

xi
xii Preface

most difficult and require significant effort. For some of the three-star exer-
cises, students must find or study additional information beyond those pre-
sented in the book. Please keep in mind that the level of difficulties is only a
general guideline. One student may find some level-three exercises much eas-
ier than level-two exercises, for example.

Book Organization
There are 16 chapters in this book, numbered from 0 to 15. The first 11 chapters
cover the core topics that provide the fundamentals of programming. Chapters 11 to
15 cover intermediate-level topics such as sorting, searching, recursion, inheritance,
polymorphism, and file I/O. There are more than enough topics for one semester.
After the first 11 chapters (Ch 0 to Ch 10), instructors can mix and match materials
from Chapters 11 to 15 to suit their needs. We first show the dependency relation-
ships among the chapters and then provide a brief summary of each chapter.

Chapter Dependency
For the most part, chapters should be read in sequence, but some variations are
possible, especially with the optional chapters. Here’s a simplified dependency
graph:

0
1

4
5

6
7

8 9 10
*Note: Some examples use arrays,
11 12 13 14* 15 but the use of arrays is not an
integral part of the examples.
These examples can be modified
to those that do not use arrays.
Many topics from the early part
of the chapter can be introduced
as early as after Chapter 2.
Preface xiii

Brief Chapter Summary


Here is a short description of each chapter:
• Chapter 0 is an optional chapter. We provide background information on
computers and programming languages. This chapter can be skipped or as-
signed as an outside reading if you wish to start with object-oriented pro-
gramming concepts.
• Chapter 1 provides a conceptual foundation of object-oriented programming.
We describe the key components of object-oriented programming and illus-
trate each concept with a diagrammatic notation using UML.
• Chapter 2 covers the basics of Java programming and the process of editing,
compiling, and running a program. From the first sample program presented in
this chapter, we emphasize object-orientation. We will introduce the standard
classes String, Date, and SimpleDateFormat so we can reinforce the notion of
object declaration, creation, and usage. Moreover, by using these standard
classes, students can immediately start writing practical programs. We describe
and illustrate console input with System.in and the Scanner class and output with
System.out.
• Chapter 3 introduces variables, constants, and expressions for manipulating
numerical data. We explain the standard Math class from java.lang and
introduce more standard classes (GregorianCalendar and DecimalFormat) to
continually reinforce the notion of object-orientation. We describe additional
methods of the Scanner class to input numerical values. Random number
generation is introduced in this chapter. The optional section explains how the
numerical values are represented in memory space.
• Chapter 4 teaches the basics of creating programmer-defined classes. We
keep the chapter accessible by introducting only the fundamentals with illus-
trative examples. The key topics covered in this chapter are constructors, vis-
ibility modifiers (public and private), local variables, and passing data to
methods. We provide easy-to-grasp illustrations that capture the essence of
the topics so the students will have a clear understanding of them.
• Chapter 5 explains the selection statements if and switch. We cover boolean
expressions and nested-if statements. We explain how objects are compared
by using equivalence (==) and equality (the equals and compareTo methods).
We use the String and the programmer-defined Fraction classes to make the
distinction between the equivalence and equality clear. Drawing 2-D graphics
is introduced, and a screensaver sample development program is developed.
We describe the Java 5.0 feature called enumerated type in this chapter.
• Chapter 6 explains the repetition statements while, do–while, and for. Pitfalls
in writing repetition statements are explained. One of the pitfalls to avoid is
the use of float or double for the data type of a counter variable. We illustrate
this pitfall by showing a code that will result in infinite loop. Finding the great-
est common divisor of two integers is used as an example of a nontrivial loop
statement. We show the difference between the straightforward (brute-force)
and the clever (Euclid’s) solutions. We introduce the Formatter class and show
xiv Preface

how the output can be aligned nicely. The optional last section of the chapter
introduces recursion as another technique for repetition. The recursive version
of a method that finds the greatest common divisor of two integers is given.
• Chapter 7 is the second part of creating programmer-defined classes. We
introduce new topics related to the creation of programmer-defined classes
and also repeat some of the topics covered in Chapter 4 in more depth. The
key topics covered in this chapter are method overloading, the reserved
word this, class methods and variables, returning an object from a method,
and pass-by-value parameter passing. As in Chapter 4, we provide many
lucid illustrations to make these topics accessible to beginners. We use the
Fraction class to illustrate many of these topics, such as the use of this and
class methods. The complete definition of the Fraction class is presented in
this chapter.
• Chapter 8 teaches exception handling and assertions. The focus of this chap-
ter is the construction of reliable programs. We provide a detailed coverage of
exception handling in this chapter. We introduce an assertion and show how it
can be used to improve the reliability of finished products by catching logical
errors early in the development.
• Chapter 9 covers nonnumerical data types: characters and strings. Both the
String and StringBuffer classes are explained in the chapter. Another string
class named StringBuilder is briefly explained in this chapter. An important ap-
plication of string processing is pattern matching. We describe pattern match-
ing and regular expression in this chapter. We introduce the Pattern and
Matcher classes and show how they are used in pattern matching. One section
is added to discuss the application of string processing in bioinformatics.
• Chapter 10 teaches arrays. We cover arrays of primitive data types and of ob-
jects. An array is a reference data type in Java, and we show how arrays are
passed to methods. We describe how to process two-dimensional arrays and
explain that a two-dimensional array is really an array of arrays in Java. Lists
and maps are introduced as a more general and flexible way to maintain a col-
lection of data. The use of ArrayList and HashMap classes from the java.util
package is shown in the sample programs. Also, we show how the WordList
helper class used in Chapter 9 sample development program is implemented
with another map class called TreeMap.
• Chapter 11 presents searching and sorting algorithms. Both N2 and Nlog2N
sorting algorithms are covered. The mathematical analysis of searching and
sorting algorithms can be omitted depending on the students’ background.
• Chapter 12 explains the file I/O. Standard classes such as File and JFile-
Chooser are explained. We cover all types of file I/O, from a low-level byte
I/O to a high-level object I/O. We show how the file I/O techniques are used
to implement the helper classes—Dorm and FileManager—in Chapter 8 and 9
sample development programs. The use of the Scanner class for inputting data
from a textfile is also illustrated in this chapter.
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of Captain John

Crane, 1800-1815
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

Title: Captain John Crane, 1800-1815

Author: Thomas Wallace Knox

Illustrator: Charles Edward Boutwood

Release date: March 31, 2020 [eBook #61715]


Most recently updated: October 17, 2024

Language: English

Credits: Produced by Carlos Colón, the Harvard University and


the
Online Distributed Proofreading Team at
https://www.pgdp.net
(This book was produced from images made available
by the
HathiTrust Digital Library.)

*** START OF THE PROJECT GUTENBERG EBOOK CAPTAIN JOHN


CRANE, 1800-1815 ***
Transcriber's Notes:

Blank pages have been eliminated.

Variations in spelling and hyphenation have been left as


in the original.

A few typographical errors have been corrected.

The cover page was created by the transcriber and can


be considered public domain.
My mother broke down and cried. Page 19.
CAPTAIN JOHN CRANE
1800-1815

BY
THOMAS W. KNOX
AUTHOR OF "A CLOSE SHAVE," "THE TALKING HANDKERCHIEF,"
"THE LOST ARMY," "DECISIVE BATTLES SINCE WATERLOO," "THE
BOY TRAVELLERS" (15 VOLUMES), "THE YOUNG NIMRODS" (3
VOLUMES), ETC., ETC.

ILLUSTRATED
NEW YORK
THE MERRIAM COMPANY
67 FIFTH AVENUE
Copyright, 1895,
By The Merriam Company.

Typography by C. J. Peters & Son,


Boston, U.S.A.
CONTENTS

PAGE
Chapter I. Who and What I am.—My Early Life.—Leaving
Home, and Why I left It. 7
Chapter II. Walking to Boston.—Suspected to be
Runaways.—Find a Ship and Sign Articles. 21
Chapter III. Departure from Boston.—Out at Sea.—What
happened to Me.—Meeting a Stranger. 35
Chapter IV. Overhauled by a British War-Ship.—Search for
Deserters.—The Captain plays a Yankee Trick. 48
Chapter V. The Flying Dutchman and His History.—Meeting
a Ship with a Starving Crew.—Relief and Sailing in
Company. 64
Chapter VI. In Danger from a Waterspout.—Caught in a
Gale.—Separated from Our Consort.—A Ghost on the
Washington. 78
Chapter VII. The Ghosts and How They were laid.—
Admiral Hosier's Ghost.—The Warwick Again.—
Encountering an Algerian Pirate. 92
Chapter VIII. A Congreve Rocket among Algerine Pirates.
—Arrival at Gibraltar.—Arrested and in Prison. 105
Chapter IX. Trouble between the United States and
Algiers.—The War with France.—What our Navy did.—
From Gibraltar to Marseilles. 120
Chapter X. Escorted beyond Danger.—Daily Work on
Shipboard.—We save a Boatful of Castaways.—How We
found Them. 135
Chapter XI. How the Evelyn was lost.—I am transferred
from Forecastle to Cabin.—Our Passengers.—Arrival at
Boston. 150
Chapter XII. A Voyage to China.—Crossing the Line.—
Malay Pirates.—Whampoa Anchorage.—More Troubles
with Great Britain. 165
Chapter XIII. David and I visit Our Old Home.—Return to
Boston, and Meet Bill and Joe.—Bill's Adventure on the
Chesapeake.—An "Unlucky" Ship. 181
Chapter XIV. The Chesapeake and the Shannon.—Another
Voyage to China.—More about Impressment.—I become
a Captain and receive Orders. 195
Chapter XV. Fitting for Sea.—War Declared.—Out on a
Cruise.—My First Prize.—Old Friends. 209
Chapter XVI. A Conspiracy, and How It was defeated.—
Another Prize.—Views of Privateering.—A Cartel.—In the
Jaws of a British Man-of-War. 224
Chapter XVII. Safe Return to New York.—Offer of a New
Ship.—My Friends the Grahams.—Off Again.—The
Constitution's Escape and Mine. 238
Chapter XVIII. Destruction of the Guerrière by the
Constitution.—Captain Hull's Wager.—How I tricked a
British Captain.—David's Ruse.—Fortune Frowns. 252
Chapter XIX. Escaping from a British Fleet.—Destruction
of the Marguerite.—Captured by an Old Acquaintance.—
Prisoner at Plymouth and Dartmoor. 266
Chapter XX. Prison Life at Dartmoor.—Reminiscences of
Privateering.—Achievements of the Rossie, Highflier,
Governor Tompkins, and Others.—I am summoned to the
Captain's Office. 280
Chapter XXI. Released on Parole.—Go to Portsmouth.—
Old Friends.—Declaration of Peace.—Return to America.—
Wedding Bells. 294
LIST OF ILLUSTRATIONS.

My Mother broke down and cried. Frontispiece.


The Officer walked slowly Along in Front of
Facing Page
Them. 49
The Sight That met His Eyes was a Terrible
" "
One. 65
He brought His Glass to bear Upon the
" "
Object. 113
"This is Jack Crane," said Captain Dawson. " " 145
He was just fairly stowed away When Haines
" "
came. 193
The Crew hauled away on the Rope. " " 241
"Are You John Crane, Captain of the Late
" "
Privateer Marguerite?" 289
CAPTAIN JOHN CRANE.
CHAPTER I.
WHO AND WHAT I AM.—MY EARLY LIFE.—LEAVING HOME,
AND WHY I LEFT IT.

I am a modest, bashful sort of man, though I say it myself, and have


been a sailor for a goodly number of years. Perhaps on board a ship
I am not so bashful, and especially when in command of her. I don't
feel altogether at home on shore, although I've given up the sea,
and propose to spend the rest of my life on land. I was born on the
25th of November, 1783, the day of the evacuation of the city of
New York by the British, at the end of the Revolutionary War.
It is proper to say that my arrival into the United States (and the
world) on that day attracted much less attention throughout the
country than did the departure of our enemies, but there's nothing
surprising in that. I suppose you might have found, a few years ago,
a good many people throughout these United States who were born
on the same day as George Washington; but they haven't attracted
any attention, while he has filled the eyes of the world. At any rate,
he filled the stomachs of the British with all the fighting they wanted
when they came here to subjugate the colonies.
My name is John Crane, or, rather, Captain Crane, at your service. I
am, or rather was, a sea-captain, and for a pretty fair time too.
People keep on calling me "Captain," although I've given up sea life
and settled down on shore. But that's the way of things generally;
which, after all, isn't so bad. If a man has done something and won
a handle to his name, I think it is fair to let him keep it, and so I
never correct folks when they call me Captain Crane. But when I
sign a paper of any sort, no matter whether it's a letter to anybody
or a legal document, I always write "John Crane," and nothing more.
I never stick Captain on in front of it, as some do that I know.
Since I settled down on land I've told a good many of my
experiences to neighbors and friends, and they've urged me to write
a book. I've hesitated a good while about it,—there's where my
bashfulness comes in,—but, after all, I don't see why I shouldn't do
as others have done. There's many a book on sea life by men who
have never been on blue water a tenth part as much as I've been
there.
I can't spell very well, that was always a weak point with me; but I'll
leave it to the printer to correct my spelling, and also my grammar, if
I slip up in it. I never had a chance for much schooling; I had a little
of the three R's, Reading, 'Riting, and 'Rithmetic, but precious little it
was.
I was born among the hills of New Hampshire, in the township of
Pembroke, about fifty miles from Portsmouth, a seaport of that
State, and sixty or seventy miles from Boston.
As my birth occurred on what we may consider the last day of the
War for Independence, I can't be supposed to remember anything
about it of my own knowledge, but my earliest recollections are very
much concerned with it. It was the great topic of conversation
among the people in the region where I lived. My father, and nearly
every other man in the neighborhood, had fought in the Continental
Army, and they were very fond of "fighting their battles o'er again"
in front of their firesides. My father was a soldier from the beginning
of the war until 1777, when he was badly wounded and came home.
It was late in 1778 when he recovered, but he wasn't able to go
back to the army again. So he married, and you'll know about his
family farther on.
My early life was one of hardship. My parents had a small farm
which we cultivated,—father and mother, and three brothers of us,—
with our own hands. In fact, we could not well do otherwise, as we
were too poor to hire any help. When he was twenty-one years old,
James, my eldest brother, left home, went to a neighboring town,
where he hired out with a farmer, and in less than a year was
married to the farmer's daughter. Luckily for him, his wife's father
had a good-sized farm, and she was an only child. So it happened
that the newly married pair settled down on the farm to take care of
the old folks; and in due time, when they were gathered to their
fathers, my brother and his wife fell into possession of the farm and
the property connected with it.
My second brother followed the example of the first, except that he
did not marry a farm along with his girl. I was seventeen years old
at the time he became engaged. Months, yes, I may say years,
before this event, I had thought and dreamed about going to sea.
Neither of my brothers cared for it, but I believe I was a born sailor
if there ever was one. I longed to look upon the ocean and sail upon
it, and felt that I would gladly pass the whole of my life on the
waters. I read all that I could find about it; but I'm sorry to say that
books were scarce in our neighborhood, and opportunities for
reading were very small. I was greatly impressed by various
passages in the Bible referring to the sea, especially the one in the
Psalms which reads,—

"They that go down to the sea in ships, that do business in


great waters; these see the works of the Lord and His
wonders in the deep."

So, when the family was talking about my second brother's future
prospects, I suggested that it was time for me to be doing
something, and if father and mother consented, I would go to sea.
There was some objection at first; but finally it was agreed and
settled upon that my second brother should bring his bride to the
house, and the twain would live there and care for the old folks, just
as my elder brother and his wife were caring for her parents, while I
would go to sea.
Then the question arose, "Should I go from Portsmouth or from
Boston?" It was finally decided that as Boston was the larger place,
and had a greater amount of shipping than Portsmouth, I had better
go to Boston, and sail from there.
It was along in winter when this decision was reached. My departure
was deferred until spring, not that there was very much for me to do
at home in that season of the year, but because the traveling would
be very bad when the roads were covered with snow and the
weather cold.
As the time approached for me to leave home I began to feel
reluctant at going away. One day I was talking with David Taylor, one
of my friends and schoolmates, at least he was my schoolmate for
eight or ten weeks every year, and about my own age.
When I told him I was going to sea he jumped at the idea, and said
he would like to go too; like myself, he had thought and dreamed
about the ocean, and nothing would suit him better than sailing over
it. He said he would speak to his father that very evening, and try
and get his consent. The Taylor family was situated very much like
mine, and I thought it quite likely that David would have no difficulty
in obtaining the paternal permission.
The next morning, when we met at school, David shook his head,
and said,—
"I'm afraid I can't go with you, John. I spoke to father last night, and
what do you think he said?"
"From the way you talk, David," said I, "I suppose he wouldn't listen
to your going to sea."
"Yes, that's it exactly. He said I had better stay at home, and if there
wasn't room for me on the farm I could hire out among the
neighbors. 'There's Major M'Clary,' said he, 'who has a big farm, and
hires half a dozen hands most of the time, and a dozen of them in
haying-time. You can hire out with him, I know. I fought under him
at Bunker Hill, and I know he'd be willing to help along a son of
mine.'"
"Well," I answered, "what did you say to that?"
"I told him I didn't want to hire out as a farm hand, and possibly be
a hired man all my life. I'd rather go away and try to do something
in the world, and I believed there was a chance for me if I'd only try
it."
"We didn't have a very long talk about it," continued David; "but at
the end of what we had to say father remarked that he would think
it over, and perhaps would see Mr. Crane and talk with him about it."
"That's all right, David," I said, "that's all right. If Mr. Taylor has
consented to think it over and talk with my father, I'm pretty sure
that you'll go with me in the spring. I haven't seen much of the
world, and don't know many folks in it; but when a man is willing to
consider a thing, and talk about it with somebody else who has
already considered it, it shows that he's a reasonable being, and I
feel sure my father will make Mr. Taylor understand that it will be
better for you to go out into the world than stay here at home.
There are already too many mouths to feed in your family, and you'll
have to go away from home very soon, anyway."
Then I told David some of the things I had read about the sea and a
sailor's life. I told him particularly of the prize money that was
obtained whenever a ship-of-war captured an enemy's vessel. Then I
spoke of the wages that sailors obtained, especially after they got to
be mates and captains; in fact, I dwelt a good deal more on the
captain's wages than I did on those of the mariner before the mast.
I had already said the same things to my father and mother, and
that was one of the reasons why they consented to my going to sea.
My mother, bless her loving heart! believed that her son would come
home a captain before the end of the year.
Ambitious as I was, I could not take her rosy view of the case, but I
did not undeceive her. My father was less sanguine; but of course he
was proud of his son, and believed I would succeed. A mother's love
and hopes are always far greater than a father's, but in saying this I
do not mean to cast any aspersion upon the head of our family. He
was affectionate to us all; and though he was severe at times, he
was always kind and just.
Well, it was not long before Mr. Taylor and his wife came to our
house and spent an evening. I was sent on a visit at Mr. Taylor's in
order to have me out of the way during the conference, and my
brother Charles went to call on the girl to whom he was engaged.
The evening was an anxious one for both David and myself, and the
time passed slowly. We tried to lay plans and talk of our future, but
it was very difficult to do this when we did not know whether David
would be permitted to accompany me or not. I went home at half-
past eight o'clock, the time agreed upon, and met David's father and
mother about half-way between our two houses.
I stopped and talked with them a moment, said that I had had a
pleasant visit at their house, and they in return said they had passed
an agreeable evening at my home. I hoped they would tell me what
decision had been reached, but they said not a word on the subject
that was uppermost in my heart. I had half a mind to ask them, but
concluded that it would be impertinent for me to do so. So I bade
them good-night, and proceeded on my way.
When I reached home my mother had gone to bed, and my father
was just going. With some hesitation I asked if it had been
determined whether David would go to sea or not.
"No," was the reply, "it hasn't yet been decided positively, as Mr.
Taylor said he must sleep on it. He would never decide anything of
such importance without sleeping on it at least one night."
"Do you think he will consent?" I asked.
"I hardly know what to say on that point," replied my father; "but I
think he will say yes when the time comes to decide. He is just as
sorry to have David go away from home as we are to have you go;
but he realizes that his farm is small, like ours, there are several
mouths to feed, and times are very hard. I think you may take it for
granted that David will go to sea with you, but don't be too certain
about it."
With that my father bade me good-night, and I went away to my
bed in the garret. We boys slept up under the roof, for the reason
that there was no other convenient place for us to sleep in. The roof
was so low that we had to stoop, except directly under the ridge-
pole, in order to avoid hitting our heads. The place was hot in
summer, but cool enough in winter, as there were plenty of cracks to
let in the air and cold. In the place where I lay the roof was not
more than two feet above me; and many a night, when rain was
falling, I have been lulled to sleep by the pattering of the drops on
the roof.
I did not see David the next day, as for some reason or other he did
not come to school. The second morning afterwards he was there
bright and early; and before he spoke I could see by the luster of his
eye, and the pleased expression on his face, that the decision had
been reached, and was in favor of what he wanted to do. As he
rushed toward me he said,—
"What do you suppose father told me this morning?"
"I don't suppose anything about it," said I; "I know that he gave his
permission for you to go to sea with me."
"Yes, that's it exactly," he replied; "but how did you find it out?"
"A little bird from the sky told me," I answered evasively; "never
mind how I found it out; I'll tell you sometime."
In the five or ten minutes that passed before the teacher arrived and
school was called to order, we talked as rapidly as our tongues
would permit. We had a great deal to say, and we said it quickly. It
was the same at the noon recess, when we strolled off together and
indulged in that boyish occupation of building castles in the air. In
imagination we went to sea together, as boys do in the story books;
we did our duty faithfully and zealously, and were rewarded by rapid
promotion. In less than three years we were both captains of ships,
and regretted that the United States did not possess a powerful
navy, so that we might both reach the grade of commodore or
admiral before we had attained the age of twenty-five. At least, that
was David's view of the matter; but I suggested to him that I never
read of an admiral under fifty or sixty years at least. This cooled his
ardor somewhat, but by no means discouraged him.
The winter wore on, and spring arrived in due time. Meanwhile, the
traveling outfits for David and myself were prepared. In our
township there were two or three women whose husbands were
killed during the Revolution, and who supported themselves by
making clothing for men and boys in cases where the garments
could not be made by their wives or mothers. Usually my mother
made the clothing for my father and the boys, and an economical
method was pursued, a suit of clothes doing duty through the whole
masculine part of the family.
Father would have a new suit of homespun, and when it became a
little shabby it was made over for my brother James. After him it
was made over for my second brother Charles, and after Charles for
myself. Being the youngest, I was permitted to wear the suit out,
and it was a pretty bad looking lot of garments by the time I was
through with it. Sometimes I had a suit that had been made for
Charles, but never do I remember having a brand new one.
As I was going away from home it was deemed important that I
should have a specially good suit. Consequently, Mrs. Green was
called in to construct it, and I was very proud of the garments when
they were finished. It was the best suit of clothes I had ever
possessed, and I wore them to church every Sunday after their
completion until my departure. Extra stockings and an extra shirt
completed my wardrobe; and these, with the new suit of clothes,
made a fairly good bundle, which I was to carry on my shoulder. The
last suit which brother Charles had discarded was made over for me
to wear on my journey, so that when I was ready to leave home I
presented quite a respectable appearance.
When the time came for us to start it was a great pain for me to say
good-by to parents and brothers. I was anxious enough to go, and
my young head and heart were full of ambition and of high hopes
for the future. But at the same time I realized that I might be going
away never to return; and, though none of us said so, I'm sure that
the same thought was in every mind.
My mother broke down and cried when I kissed her farewell; my
father made a great effort to preserve his composure, but I could
see the tears standing in his eyes as he shook my hand and gave me
his blessing with a choked voice. I learned afterward that when I
stepped out of the door he yielded to his sorrow, as my mother had
already done, and sank speechless and almost fainting into a chair.
It was practically the same at David's house; yes, there was more
grief there than at my own home, as David had two sisters, while I
had none. The girls were very fond of their brother, and when the
time came for him to bid them good-by they were so heart-broken
that they were unable to speak.
I am not ashamed to say that I cried, and bitterly too, when I left
my father's house. I said so to David before the day was out, and he
frankly acknowledged that he had cried too when he left home.
Mr. Taylor's house was nearer to Boston than was my father's; and
so it was agreed that David would watch for me on the morning
when we were to start, and come out and join me as I passed. You
may wonder why I did not go into the house to say good-by to the
Taylor family. The fact is, I foresaw that I might not be wanted there
at that moment, and so I called at David's house the evening before,
partly to arrange our plans, but more especially to say good-by to
the Taylors. You already understand that I was much attached to
David, and I will add that I was especially fond of his eldest sister,
who was a year younger than himself. To say good-by to her was no
small effort for me, and I felt that it would be better for us to make
our adieus in the evening, rather than in the morning, when the
whole household would be plunged in grief at David's departure.
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!

ebookball.com

You might also like