100% found this document useful (6 votes)
23 views

Immediate download Java 17 Quick Syntax Reference: A Pocket Guide to the Java SE Language, APIs, and Library Mikael Olsson ebooks 2024

The document promotes the eBook 'Java 17 Quick Syntax Reference' by Mikael Olsson, available for download on ebookmeta.com. It includes links to various digital products related to programming and technology, emphasizing immediate availability. The book covers fundamental Java concepts, syntax, and features in a structured format.

Uploaded by

poetapozosp0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (6 votes)
23 views

Immediate download Java 17 Quick Syntax Reference: A Pocket Guide to the Java SE Language, APIs, and Library Mikael Olsson ebooks 2024

The document promotes the eBook 'Java 17 Quick Syntax Reference' by Mikael Olsson, available for download on ebookmeta.com. It includes links to various digital products related to programming and technology, emphasizing immediate availability. The book covers fundamental Java concepts, syntax, and features in a structured format.

Uploaded by

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

Get the full ebook with Bonus Features for a Better Reading Experience on ebookmeta.

com

Java 17 Quick Syntax Reference: A Pocket Guide to


the Java SE Language, APIs, and Library Mikael
Olsson

https://ebookmeta.com/product/java-17-quick-syntax-
reference-a-pocket-guide-to-the-java-se-language-apis-and-
library-mikael-olsson/

OR CLICK HERE

DOWLOAD NOW

Download more ebook instantly today at https://ebookmeta.com


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

Java 17 Quick Syntax Reference A Pocket Guide to the Java


SE Language APIs and Library 3rd Edition Mikael Olsson

https://ebookmeta.com/product/java-17-quick-syntax-reference-a-pocket-
guide-to-the-java-se-language-apis-and-library-3rd-edition-mikael-
olsson/
ebookmeta.com

C# 10 Quick Syntax Reference: A Pocket Guide to the


Language, APIs, and Library Mikael Olsson

https://ebookmeta.com/product/c-10-quick-syntax-reference-a-pocket-
guide-to-the-language-apis-and-library-mikael-olsson/

ebookmeta.com

Java 17 Quick Syntax Reference 3rd Edition Mikael Olsson

https://ebookmeta.com/product/java-17-quick-syntax-reference-3rd-
edition-mikael-olsson/

ebookmeta.com

Lectures on Random Lozenge Tilings Cambridge Studies in


Advanced Mathematics Series Number 193 1st Edition Vadim
Gorin
https://ebookmeta.com/product/lectures-on-random-lozenge-tilings-
cambridge-studies-in-advanced-mathematics-series-number-193-1st-
edition-vadim-gorin/
ebookmeta.com
War in the Modern World Course Guidebook The Great Courses
Wondrium 1st Edition David R. Stone

https://ebookmeta.com/product/war-in-the-modern-world-course-
guidebook-the-great-courses-wondrium-1st-edition-david-r-stone/

ebookmeta.com

Hair Story Nonieqa Ramos

https://ebookmeta.com/product/hair-story-nonieqa-ramos/

ebookmeta.com

Activist Affordances How Disabled People Improvise More


Habitable Worlds 1st Edition Arseli Dokumaci

https://ebookmeta.com/product/activist-affordances-how-disabled-
people-improvise-more-habitable-worlds-1st-edition-arseli-dokumaci/

ebookmeta.com

Designing Machine Learning Systems: An Iterative Process


for Production-Ready Applications Chip Huyen

https://ebookmeta.com/product/designing-machine-learning-systems-an-
iterative-process-for-production-ready-applications-chip-huyen/

ebookmeta.com

Hi-C Data Analysis 1st Edition Silvio Bicciato

https://ebookmeta.com/product/hi-c-data-analysis-1st-edition-silvio-
bicciato/

ebookmeta.com
Bioinformatics in Rice Research Theories and Techniques
1st Edition Manoj Kumar Gupta (Editor)

https://ebookmeta.com/product/bioinformatics-in-rice-research-
theories-and-techniques-1st-edition-manoj-kumar-gupta-editor/

ebookmeta.com
Java 17 Quick
Syntax Reference
A Pocket Guide to the Java
SE Language, APIs, and Library

Third Edition

Mikael Olsson
Java 17 Quick Syntax
Reference
A Pocket Guide to the Java SE
Language, APIs, and Library
Third Edition

Mikael Olsson
Java 17 Quick Syntax Reference: A Pocket Guide to the Java SE Language,
APIs, and Library

Mikael Olsson
Hammarland, Länsi-Suomi, Finland

ISBN-13 (pbk): 978-1-4842-7370-8 ISBN-13 (electronic): 978-1-4842- 7371-5


https://doi.org/10.1007/978-1-4842-7371-5

Copyright © 2022 by Mikael Olsson


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or
part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Steve Anglin
Development Editor: Matthew Moodie
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image by Janco Ferlic on Unsplash (www.unsplash.com)
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY
10004, U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com,
or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member
(owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance
Inc is a Delaware corporation.
For information on translations, please e-mail booktranslations@springernature.com; for
reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is
available to readers on GitHub via the book’s product page, located at www.apress.com/
9781484273708. For more detailed information, please visit http://www.apress.com/
source-­code.
Printed on acid-free paper
Table of Contents
About the Author���������������������������������������������������������������������������������xi

About the Technical Reviewer�����������������������������������������������������������xiii


Introduction����������������������������������������������������������������������������������������xv

Chapter 1: Hello World��������������������������������������������������������������������������1


Installing���������������������������������������������������������������������������������������������������������������1
Creating a Project�������������������������������������������������������������������������������������������������1
Hello World������������������������������������������������������������������������������������������������������������2
Code Hints�������������������������������������������������������������������������������������������������������������4

Chapter 2: Compile and Run�����������������������������������������������������������������5


Running from the IDE��������������������������������������������������������������������������������������������5
Running from a Console Window��������������������������������������������������������������������������5
Comments�������������������������������������������������������������������������������������������������������������6
Preview Features��������������������������������������������������������������������������������������������������7

Chapter 3: Variables�����������������������������������������������������������������������������9
Data Types�������������������������������������������������������������������������������������������������������������9
Declaring Variables���������������������������������������������������������������������������������������������10
Assigning Variables���������������������������������������������������������������������������������������������10
Using Variables���������������������������������������������������������������������������������������������������10
Integer Types�������������������������������������������������������������������������������������������������������11
Floating-Point Types��������������������������������������������������������������������������������������������11

iii
Table of Contents

Char Type������������������������������������������������������������������������������������������������������������12
Boolean Type�������������������������������������������������������������������������������������������������������12
Variable Scope����������������������������������������������������������������������������������������������������13
Anonymous Block�����������������������������������������������������������������������������������������������13
Type Inference�����������������������������������������������������������������������������������������������������14

Chapter 4: Operators��������������������������������������������������������������������������15
Arithmetic Operators�������������������������������������������������������������������������������������������15
Assignment Operators����������������������������������������������������������������������������������������16
Increment and Decrement Operators������������������������������������������������������������������16
Comparison Operators����������������������������������������������������������������������������������������17
Logical Operators������������������������������������������������������������������������������������������������17
Bitwise Operators�����������������������������������������������������������������������������������������������18
Operator Precedence������������������������������������������������������������������������������������������18

Chapter 5: String��������������������������������������������������������������������������������21
Combining Strings�����������������������������������������������������������������������������������������������21
Escape Characters����������������������������������������������������������������������������������������������22
String Compare���������������������������������������������������������������������������������������������������23
StringBuffer Class�����������������������������������������������������������������������������������������������23
Text Blocks����������������������������������������������������������������������������������������������������������24

Chapter 6: Arrays��������������������������������������������������������������������������������27
Array Declaration������������������������������������������������������������������������������������������������27
Array Allocation���������������������������������������������������������������������������������������������������27
Array Assignment������������������������������������������������������������������������������������������������28
Multidimensional Arrays�������������������������������������������������������������������������������������28
ArrayList Class����������������������������������������������������������������������������������������������������29

iv
Table of Contents

Chapter 7: Conditionals����������������������������������������������������������������������31
If Statement��������������������������������������������������������������������������������������������������������31
Switch Statement�����������������������������������������������������������������������������������������������32
Switch Expression�����������������������������������������������������������������������������������������������33
Ternary Operator�������������������������������������������������������������������������������������������������35

Chapter 8: Loops���������������������������������������������������������������������������������37
While Loop����������������������������������������������������������������������������������������������������������37
Do While Loop�����������������������������������������������������������������������������������������������������38
For Loop��������������������������������������������������������������������������������������������������������������38
For Each Loop�����������������������������������������������������������������������������������������������������39
Break and Continue���������������������������������������������������������������������������������������������39
Labeled Block�����������������������������������������������������������������������������������������������������40

Chapter 9: Methods����������������������������������������������������������������������������41
Defining Methods������������������������������������������������������������������������������������������������41
Calling Methods��������������������������������������������������������������������������������������������������42
Method Parameters��������������������������������������������������������������������������������������������42
Return Statement������������������������������������������������������������������������������������������������43
Method Overloading��������������������������������������������������������������������������������������������44
Passing Arguments���������������������������������������������������������������������������������������������45

Chapter 10: Class�������������������������������������������������������������������������������47


Object Creation���������������������������������������������������������������������������������������������������47
Accessing Object Members��������������������������������������������������������������������������������48
Constructor���������������������������������������������������������������������������������������������������������49
This Keyword������������������������������������������������������������������������������������������������������50
Constructor Overloading�������������������������������������������������������������������������������������50

v
Table of Contents

Constructor Chaining������������������������������������������������������������������������������������������51
Initial Field Values�����������������������������������������������������������������������������������������������51
Default Constructor���������������������������������������������������������������������������������������������52
Null����������������������������������������������������������������������������������������������������������������������52
Default Values�����������������������������������������������������������������������������������������������������53
Garbage Collector�����������������������������������������������������������������������������������������������53

Chapter 11: Static�������������������������������������������������������������������������������55


Accessing Static Members���������������������������������������������������������������������������������56
Static Methods����������������������������������������������������������������������������������������������������56
Static Fields��������������������������������������������������������������������������������������������������������57
Static Initialization Blocks�����������������������������������������������������������������������������������57
Instance Initialization Blocks������������������������������������������������������������������������������58

Chapter 12: Inheritance����������������������������������������������������������������������59


Upcasting������������������������������������������������������������������������������������������������������������60
Downcasting�������������������������������������������������������������������������������������������������������60
Instanceof Operator��������������������������������������������������������������������������������������������60
Pattern Matching Switch������������������������������������������������������������������������������������62
Restricting Inheritance����������������������������������������������������������������������������������������62

Chapter 13: Overriding�����������������������������������������������������������������������65


Overriding Methods���������������������������������������������������������������������������������������������65
Override Annotation��������������������������������������������������������������������������������������������66
Hiding Methods���������������������������������������������������������������������������������������������������67
Hiding Fields�������������������������������������������������������������������������������������������������������68
Accessing Redefined Members��������������������������������������������������������������������������69
Calling Parent Constructor����������������������������������������������������������������������������������69

vi
Table of Contents

Chapter 14: Packages and Import������������������������������������������������������71


Accessing Packages�������������������������������������������������������������������������������������������72

Chapter 15: Modules��������������������������������������������������������������������������75


Creating a Module�����������������������������������������������������������������������������������������������75
Using a Module���������������������������������������������������������������������������������������������������77

Chapter 16: Access Levels������������������������������������������������������������������79


Private Access�����������������������������������������������������������������������������������������������������79
Package-Private Access��������������������������������������������������������������������������������������80
Protected Access������������������������������������������������������������������������������������������������81
Public Access������������������������������������������������������������������������������������������������������82
Top-Level Access������������������������������������������������������������������������������������������������83
Nested Class Access�������������������������������������������������������������������������������������������83
Access-Level Guideline���������������������������������������������������������������������������������������84

Chapter 17: Constants������������������������������������������������������������������������85


Local Constants���������������������������������������������������������������������������������������������������85
Constant Fields���������������������������������������������������������������������������������������������������85
Constant Method Parameters�����������������������������������������������������������������������������86
Compile-Time and Runtime Constants����������������������������������������������������������������86
Constant Guideline����������������������������������������������������������������������������������������������87

Chapter 18: Interface��������������������������������������������������������������������������89


Interface Members����������������������������������������������������������������������������������������������89
Interface Example�����������������������������������������������������������������������������������������������90
Functionality Interface����������������������������������������������������������������������������������������91
Class Interface����������������������������������������������������������������������������������������������������92
Interface Classes������������������������������������������������������������������������������������������������93

vii
Table of Contents

Default Interface Methods����������������������������������������������������������������������������������94


Static Interface Methods�������������������������������������������������������������������������������������94

Chapter 19: Abstract��������������������������������������������������������������������������97


Abstract Class Example��������������������������������������������������������������������������������������97
Abstract Classes and Interfaces�������������������������������������������������������������������������99

Chapter 20: Enum�����������������������������������������������������������������������������101


Enum Class�������������������������������������������������������������������������������������������������������102

Chapter 21: Exception Handling�������������������������������������������������������105


Try-Catch�����������������������������������������������������������������������������������������������������������105
Catch Block�������������������������������������������������������������������������������������������������������106
Finally Block������������������������������������������������������������������������������������������������������107
Throwing Exceptions�����������������������������������������������������������������������������������������109
Checked and Unchecked Exceptions����������������������������������������������������������������109
Exception Hierarchy������������������������������������������������������������������������������������������110

Chapter 22: Boxing and Unboxing����������������������������������������������������111


Autoboxing and Autounboxing��������������������������������������������������������������������������112
Primitive and Wrapper Guideline�����������������������������������������������������������������������112

Chapter 23: Generics������������������������������������������������������������������������113


Generic Classes������������������������������������������������������������������������������������������������113
Generic Methods�����������������������������������������������������������������������������������������������114
Calling Generic Methods�����������������������������������������������������������������������������������115
Generic Interfaces���������������������������������������������������������������������������������������������116
Generic Type Parameters����������������������������������������������������������������������������������117
Generic Variable Usages�����������������������������������������������������������������������������������117

viii
Table of Contents

Bounded Type Parameters��������������������������������������������������������������������������������118


Generics and Object������������������������������������������������������������������������������������������120

Chapter 24: Lambda Expressions�����������������������������������������������������123


Lambda Objects������������������������������������������������������������������������������������������������123
Lambda Parameters������������������������������������������������������������������������������������������125

Index�������������������������������������������������������������������������������������������������127

ix
About the Author
Mikael Olsson is a professional web
entrepreneur, programmer, and author. He
works for an R&D company in Finland where
he specializes in software development. In
his spare time, he writes books and creates
websites that summarize various fields of
interest. The books he writes are focused on
teaching their subject in the most efficient way
possible, by explaining only what is relevant
and practical without any unnecessary
repetition or theory.

xi
About the Technical Reviewer
Manuel Jordan Elera is an autodidactic
developer and researcher who enjoys learning
new technologies for his own experiments
and creating new integrations. Manuel won
the Springy Award – Community Champion
and Spring Champion 2013. In his little free
time, he reads the Bible and composes music
on his guitar. Manuel is known as dr_pompeii.
He has tech-reviewed numerous books
for Apress, including Pro Spring MVC with
WebFlux (2020), Pro Spring Boot 2 (2019), Rapid Java Persistence and
Microservices (2019), Java Language Features (2018), Spring Boot 2 Recipes
(2018), and Java APIs, Extensions and Libraries (2018). Read his 13 detailed
tutorials about many Spring technologies, contact him through his blog
at www.manueljordanelera.blogspot.com, and follow him on his Twitter
account, @dr_pompeii.

xiii
Introduction
Java is a high-level object-oriented programming language developed by
Sun Microsystems, which became part of Oracle Corporation in 2010. The
language is very similar to C++ but has been simplified to make it easier
to write bug-free code. Most notably, unlike C++, there are no pointers
in Java—instead, all memory allocation and deallocation is handled
automatically.
Despite simplifications like this, Java has considerably more
functionality than C++, due to its large class library. Java programs
also have high performance and can be made very secure, which
has contributed to making Java the most popular general-purpose
programming language in use today.
Another key feature of Java is that it is platform independent. This is
achieved by only compiling programs halfway, into platform-independent
instructions called bytecode. The bytecode is then interpreted, or run,
by the Java Virtual Machine (JVM). That means any system that has
this program and its accompanying libraries installed can run Java
applications.
To allow Java to be used in a variety of environments, there are four
different editions: Java ME, Java SE, Java EE, and Java FX. Each edition
contains a JVM and a set of class libraries. Java SE (Standard Edition)
provides the standard JVM along with the commonly used libraries for
building applications, in particular desktop applications. Java ME (Micro
Edition) is a small-footprint version of Java SE designed for running on
small devices such as mobile phones. Java EE (Enterprise Edition) is an
extended version of Java SE that includes libraries for building large-scale

xv
Introduction

web applications. The most recently added edition is JavaFX, a lightweight


version intended for building desktop and rich web applications. This
edition includes a new library for making graphical user interfaces (GUIs),
which is intended to replace the standard GUI library called Swing used in
Java SE.
To allow Java to be used in a variety of environments, there are four
different editions: Java SE, Java ME, Java EE, and Java FX. Each edition
contains a JVM and a set of class libraries. Java SE (Standard Edition)
provides the standard JVM along with the commonly used libraries for
building applications, in particular desktop applications. Java ME (Micro
Edition) is a small-footprint version of Java SE designed for running on
small devices such as mobile phones. Java EE (Enterprise Edition) is an
extended version of Java SE that includes libraries for building large-scale
web applications. The most recently added edition is Java FX, a lightweight
version intended for building rich web applications.
The Java language and class libraries have undergone major changes
since their initial release in 1996. The naming conventions for the versions
have gone through a few revisions as well, mainly for marketing reasons.
The major releases include JDK 1.0, JDK 1.1, J2SE 1.2, J2SE 1.3, J2SE 1.4,
J2SE 5.0, followed by Java SE 6 to Java SE 17, with Java SE 17 being the
current version as of writing. For the sake of simplicity, the Java versions
will be referred to as Java 1–17 in this book. Note that Java is designed to be
backward-compatible. Therefore, the Virtual Machine for Java 17 can still
run Java 1 applications.

xvi
CHAPTER 1

Hello World
I nstalling
Before you can program in Java, you need to download and install a Java
Development Kit (JDK), such as the Standard Edition (JDK SE) from
Oracle’s website.1 Among other things, the JDK includes the Java compiler,
the class libraries, and the virtual machine needed to run Java applications.
You should also download an Integrated Development Environment (IDE)
as it will make development in Java much easier. One such Java IDE is
Apache NetBeans,2 which is available for free on Windows, macOS, and
Linux. If you don’t want to use any IDE at all, using a regular text editor is
also an option. To work without an IDE, you can create an empty file with
the .java extension—for example, MyApp.java—and open it in your text
editor of choice.

C
 reating a Project
If you decide to use an IDE (recommended), you need to create a
project, which will manage the Java source files and other resources.
To create a project in NetBeans, click File ➤ New Project. In the dialog

1
www.oracle.com/java/technologies/javase-downloads.html
2
https://netbeans.org

© Mikael Olsson 2022 1


M. Olsson, Java 17 Quick Syntax Reference, https://doi.org/10.1007/978-1-4842-7371-5_1
Another Random Scribd Document
with Unrelated Content
The Project Gutenberg eBook of Stories of the
War of 1812, and the Mexican War
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: Stories of the War of 1812, and the Mexican War

Author: Anonymous

Release date: August 3, 2024 [eBook #74180]

Language: English

Original publication: Philadelphia, PA: W. A. Leary & Co, 1851

Credits: Brian Wilsden and the Online Distributed Proofreading


Team at https://www.pgdp.net (This file was produced
from images generously made available by The Internet
Archive)

*** START OF THE PROJECT GUTENBERG EBOOK STORIES OF THE


WAR OF 1812, AND THE MEXICAN WAR ***
ADVANCE OF GENERAL KEARNEY INTO CALIFORNIA.

STORIES
OF THE
WAR OF 1812,
AND THE
MEXICAN WAR.
WITH NUMEROUS ENGRAVINGS.

PHILADELPHIA:
W. A. LEARY & Co.
No. 138 NORTH SECOND ST.
1854.

Entered according to Act of Congress, in the year 1851, by


J. & J. L. GIHON,
In the Clerk’s Office of the District Court of the
United States, in and for the Eastern District of Pennsylvania.
PREFACE.

The following pages contain a collection of Stories of the War of


1812, with Great Britain; and of the Recent War, with the Republic of
Mexico.
Rightly considered, the first of these national wars was a supplement
to the glorious War of Independence. Up to the time when our
government boldly threw down the gauntlet of defiance to the most
powerful nation of Europe, in defence of Free Trade and Sailor’s
Rights, the British nation regarded us as revolted subjects,
successful for the moment, but destined always to be governed by
British influence and ultimately to be reconquered.
The events of the second war with Great Britain finished what the
first had begun, and set the seal on our Independence. From the
period of its conclusion, our flag was respected by Britain and all
other nations. Our naval prowess was recognized as a fixed fact.
The recent war with Mexico has taught the world another lesson. It
has shown that with a standing army of very few men, and a good
militia system, the republic is capable of raising large and efficient
armies, and conquering a military republic, of immense population,
wealth, and resources, possessing a powerful standing army;
accustomed, in consequence of the distracted state of the country,
to frequent action and constant discipline.
The wars which teach these lessons are worthy the attention of the
youth of our country; and we have endeavored to render these
stories of the wars sufficiently attractive to win that degree of
attention and interest which will insure a future study of American
history.
DETROIT.

THE WAR OF 1812.

SURRENDER OF DETROIT.
In June, 1812, the United States declared war against Great Britain.
The chief cause of the war was the impressment of American
seamen by the British. General Hull, with twenty-five hundred men,
took post at Detroit, in Michigan. Soon afterward, the British general,
Brock, with thirteen hundred men, appeared before Detroit, erected
batteries, and summoned Hull to surrender. He refused, and the
British opened their fire upon the works. On the 26th, they crossed
the river and moved forward to the attack. The American troops
were prepared to receive them, and eager for the conflict. But as the
British approached, Hull ordered his men to retire into the fort, and
hoisted a white flag. In a short time, terms of surrender were agreed
upon, and the whole American army, with all its ammunition and
stores were given up to the British. This surrender excited the
indignation of the people. Hull was accused of cowardice, tried by a
court martial, and sentenced to be shot. The President, however, in
consideration of his age and services, remitted the punishment, but
ordered his name to be stricken from the rolls of the army.
BATTLE OF QUEENSTOWN.

BATTLE OF QUEENSTOWN.
Early in October, 1812, about three thousand five hundred men,
under command of General Van Rensselaer, were assembled on the
Niagara frontier. General Van Rensselaer resolved to make an attack
on the British position at Queenstown, eight miles below Niagara
Falls. At daybreak on the 13th of October, the troops began to
embark to cross the river. The British opened a fire upon them,
which was returned by the American batteries. Colonel Van
Rensselaer, with about one hundred men, reached the shore, and
stormed the fort of the British, though not without severe loss. The
Americans drove the enemy from the field, and the victory was
supposed to be gained, when another reinforcement arrived, and the
conflict was renewed. At this critical moment, General Van
Rensselaer crossed the river to bring a reinforcement for his gallant
little band, and found that the militia would not obey his orders.
Colonel Christie maintained the fight on the opposite shore, against
overwhelming numbers, until seeing no hope of relief, he
surrendered the remnant of his force. The Americans lost one
thousand men in all, in this battle. The loss of the enemy was
somewhat less, but their noble commander, the gallant Brock, was
slain.
DEFENCE OF FORT HARRISON.

DEFENCE OF FORT HARRISON.


Fort Harrison was a post on the Wabash river, in the heart of the
Indian country. It consisted of two blockhouses, stockade works, and
a few buildings for stores or magazines. In September 1812, sixteen
men, under the command of Captain Zachary Taylor, formed the
garrison of this post. On the 3d of September, two men, who were
working in the field near it, were murdered by the Indians, and on
the night of the 4th, the savages set fire to one of the blockhouses,
and commenced an assault. Captain Taylor, though suffering from
sickness displayed the greatest coolness and resolution. Two of his
men leaped over the stockade and fled, and the others were seized
with a panic. But he restored their hopes, and by tearing off the roof
of the barracks, and other means, succeeded in quenching the fire.
The savages poured a steady fire into the fort. The invalids of the
garrison returned it, and the conflict was fierce and desperate until
daybreak, when the enemy retreated beyond the reach of the fort.
They beleaguered the garrison, however, for twelve days, when a
large body of troops arrived, and forced them to raise the siege.
CAPTURE OF THE GUERRIERE.

COMMODORE HULL.
CAPTURE OF THE GUERRIERE.
At the commencement of the war, the navy of Great Britain was
looked upon as invincible. But an important victory changed the
opinion of the people of the United States. The frigate Constitution,
commanded by Captain Isaac Hull, sailed from Annapolis on the 25th
of July, 1812, for New York. Falling in with a British fleet, she only
escaped by great skill and seamanship. Soon after she sailed from
Boston, and on the 19th of August encountered the British frigate,
Guerriere, commanded by Captain Dacres. A fierce conflict of about
half an hour’s length ensued. The Guerriere was reduced to a wreck,
and after her surrender, burned. In this action the Americans had
seven men killed, and seven wounded. The British loss was fifteen
killed, sixty-two wounded, and twenty-four missing. The effect of
this victory was to give the Americans confidence in the skill and
bravery of their seamen.
CAPTURE OF THE FROLIC.

CAPTURE OF THE FROLIC.


The United States sloop-of-war Wasp, of eighteen guns, commanded
by Captain Jacob Jones, sailed from the Delaware, on the 13th of
October; and on the 18th of the month, after a long and heavy gale,
fell in with a convoy of six merchantmen, four of them strongly
armed, under the protection of His Britannic Majesty sloop-of-war
Frolic, of twenty-two guns, Captain Whinyates. At half-past eleven in
the morning, the action commenced at the distance of about fifty
yards. But, during the action, so near did they come to each other,
that the rammers of the Wasp’s cannon struck against the side of
the Frolic. The fire of the English vessel soon slackened; and after a
most sanguinary action of forty-three minutes, every brace of the
Wasp being shot away, and the rigging so much torn, that Captain
Jones resolved to board the enemy. With this view he wore ship and
running down upon the enemy, the vessels struck. The officers
surrendered the vessel, and the colors were hauled down by
Lieutenant Biddle. The Frolic was in a shocking condition; the berth-
deck was filled with dead and wounded. No sooner had the
engagement ceased, than the British ship, Poictiers, of seventy four
guns, came up, and captured both vessels.
DEATH OF GENERAL PIKE.

ATTACK ON YORK.
General Dearborn, the commander of the United States forces on the
Ontario frontier, having resolved to attack York, the capital of Upper
Canada, embarked seventeen hundred troops, and left Sackett’s
Harbor on the 25th of April. On the 27th, the troops, under the
command of General Pike, effected a landing and drove a much
superior force of the enemy from the shore. But they returned to the
attack, and the contest was renewed. The enemy were again
defeated and driven to their works. The whole force of the
Americans having reached the shore, and being arranged in the
order for attack, General Pike pressed forward, carried one of the
enemy’s batteries, and was moving towards the main works, when a
sudden and tremendous explosion of the magazine occurred, hurling
upon the advancing troops immense masses of stone and timber,
and for a time checking them by the havoc it made. General Pike
was mortally wounded. But the troops under command of Colonel
Pearce, pressed on, and captured the town, with all the land and
naval forces in and about it. The total loss of the Americans was
three hundred and twenty men. General Pike was greatly lamented.
The British loss was four hundred killed or wounded, and three
hundred prisoners.
CAPTURE OF FORT GEORGE.

CAPTURE OF FORT GEORGE.


After the capture of York, General Dearborn resolved to attempt the
capture of Fort George. On the morning of the 27th of May, the light
troops under Colonel Scott and Major Forsyth, supported by Colonel
Porter’s light artillery and General Lewis’s division, crossed the
Niagara river, and attacked the fort. Other brigades of troops
followed. Commodore Chauncey had made judicious arrangements
with his small ships, to silence the enemy’s batteries at the point of
landing. The descent was warmly contested at the water’s edge, by
the British; but they were soon compelled to give way, and the
landing was completed. The American batteries soon succeeded in
rendering the fort untenable. The British, retiring from the banks of
the river, re-entered the fort, fired a few shot, set fire to the
magazine, and then moved off in different directions. Of the British
regular troops, ninety were killed, one hundred and sixty wounded,
and one hundred captured. The Americans lost seventeen killed, and
sixty wounded.

FORT GEORGE.
DEFENCE OF SACKETT’S HARBOR.

DEFENCE OF SACKETT’S HARBOR.


To retaliate for the capture of York, Sir George Prevost, the British
general-in-chief, determined to make a descent on Sackett’s Harbor,
the chief American depot for stores, on the lakes. Accordingly, on the
27th of May, 1813, Prevost, with nearly a thousand men, embarked
in small boats, and proceeded, under convoy of the British fleet. The
fleet being seen on the lake, preparations were made for the
defence of the post. General Brown, with six hundred militia, came
to the aid of the few regular troops, and made wise disposition for
the reception of the enemy. Prevost arrived, and commenced the
attack on the evening of the 28th. The first line of the militia fired,
and then gave way. But Brown, with the rest of his troops,
maintained his ground against the assault, and poured such a well
aimed fire into the enemy, that they were checked. The success was
followed up, and at length, the British were driven to their boats.
Through some mistake the American stores were burned by the
officer set to guard them. This victory brought the military talents of
General Brown to light.
DEFENCE OF FORT STEPHENSON.

DEFENCE OF FORT STEPHENSON.


The defence of Fort Stephenson, at Lower Sandusky, was one of the
most brilliant exploits in the annals of war. It was an unfinished
stockade fort, garrisoned by one hundred and fifty men, under the
command of Major George Croghan. General Harrison had sent word
to the major, that he should abandon the fort on the approach of the
enemy. But he did not think a retreat possible, and, moreover, was
determined to perish, rather than surrender. On the 28th of May,
Proctor, with twenty-two hundred British and Indians, appeared
before the fort, and summoned the garrison to surrender. Receiving
the most heroic refusal, he opened a heavy fire, which was
continued during the night and all next day, when the enemy
advanced to the assault. Croghan had but one six-pounder in the
fort. This was masked, and other preparations made to receive the
foe. The assault was furious, but the fire of the heroic garrison
committed such havoc that the British were compelled to fall back in
confusion, and soon after they abandoned the siege, having lost
over two hundred men. Croghan’s loss was trifling.
BUILDING THE FLEET ON LAKE ERIE.

COMMODORE PERRY.
BUILDING OF THE FLEET ON LAKE ERIE.
Early in the spring of 1813, the attention of the government of the
United States, was directed to the important object of obtaining the
command of Lake Erie. The earnest representations of General
Harrison had awakened the administration to a proper sense of the
necessity of this measure. The British already had an efficient naval
force upon the lake, and it gave them great advantages. Two brigs
and several schooners were ordered to be built, under the direction
of Captain Oliver H. Perry. That able and active officer saw that the
work was carried on with the greatest rapidity, and on the 2d of
August, he was able to sail in quest of the enemy’s squadron. The
British, though much superior in force, did not venture out to meet
the new squadron.
BATTLE OF LAKE ERIE.

BATTLE OF LAKE ERIE.


On the morning of the 10th of September, while Perry’s squadron
was lying in Put-in-bay, in Bass Island, the enemy’s fleet was
discovered standing out from the port of Malden, with the wind in
their favor. The American fleet immediately weighed anchor, cleared
the islands at the head of the lake, and was formed in line of battle.
A little before twelve o’clock, the action commenced, the British
having the weathergage. For some time, the fire of the enemy was
concentrated upon the St. Lawrence, Perry’s flag-ship, and she was
much cut up, most of her crew killed or wounded, and her guns
disabled. In the midst of the lire, Captain Perry passed in an open
boat from the Lawrence to the Niagara, and succeeded in bringing
the rest of his fleet into action. A well directed fire was then opened
upon the enemy, and the battle then became close and warm. At
length the British vessels having suffered severely from the superior
gunnery of the Americans, struck their colors. The Lawrence, whose
flag had been hauled down soon after Perry had left her, had been
enabled to hoist it before the end of the contest, the enemy not
being able to take possession of her. The American loss was twenty-
five killed, and ninety-six wounded; that of the enemy, forty-one
killed, and ninety-five wounded.

You might also like