Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (5 votes)
579 views

Full Introduction To Java Programming, Comprehensive Version 10th Edition - Ebook PDF Ebook All Chapters

Java

Uploaded by

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

Full Introduction To Java Programming, Comprehensive Version 10th Edition - Ebook PDF Ebook All Chapters

Java

Uploaded by

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

Download the full version of the ebook now at ebooksecure.

com

Introduction to Java Programming,


Comprehensive Version 10th edition- eBook PDF

https://ebooksecure.com/download/introduction-to-
java-programming-comprehensive-version-ebook-pdf/

Explore and download more ebook at https://ebooksecure.com


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

(eBook PDF) Introduction to JAVA Programming and Data


Structures Comprehensive Version 11

https://ebooksecure.com/product/ebook-pdf-introduction-to-java-
programming-and-data-structures-comprehensive-version-11/

ebooksecure.com

(eBook PDF) Introduction to Java Programming and Data


Structures, Comprehensive Version, 11th Global Edition

https://ebooksecure.com/product/ebook-pdf-introduction-to-java-
programming-and-data-structures-comprehensive-version-11th-global-
edition/
ebooksecure.com

(eBook PDF) Introduction to Java Programming, Brief


Version, Global Edition 11th Edition

https://ebooksecure.com/product/ebook-pdf-introduction-to-java-
programming-brief-version-global-edition-11th-edition/

ebooksecure.com

(eBook PDF) Human Resources Management in Canada 13th


Canadian

https://ebooksecure.com/product/ebook-pdf-human-resources-management-
in-canada-13th-canadian/

ebooksecure.com
(eBook PDF) Principles of Microeconomics by Betsey
Stevenson

https://ebooksecure.com/product/ebook-pdf-principles-of-
microeconomics-by-betsey-stevenson/

ebooksecure.com

(eBook PDF) CFIN 5th Edition by Scott Besley

https://ebooksecure.com/product/ebook-pdf-cfin-5th-edition-by-scott-
besley/

ebooksecure.com

(eBook PDF) Brief C++: Late Objects, 3rd Edition

https://ebooksecure.com/product/ebook-pdf-brief-c-late-objects-3rd-
edition/

ebooksecure.com

(eBook PDF) Encyclopedia of Ocean Sciences 3rd Edition

https://ebooksecure.com/product/ebook-pdf-encyclopedia-of-ocean-
sciences-3rd-edition/

ebooksecure.com

Research Methods in Accounting 4th Edition (eBook PDF)

https://ebooksecure.com/product/research-methods-in-accounting-4th-
edition-ebook-pdf/

ebooksecure.com
(eBook PDF) Business Ethics Concepts and Cases 8th Edition

https://ebooksecure.com/product/ebook-pdf-business-ethics-concepts-
and-cases-8th-edition/

ebooksecure.com
INTRODUCTION TO

JAVA
®

PROGRAMMING
COMPREHENSIVE VERSION

Tenth Edition

Y. Daniel Liang
Armstrong Atlantic State University

Boston Columbus Indianapolis New York San Francisco Upper Saddle River
Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto
Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo
To Samantha, Michael, and Michelle

Editorial Director, ECS: Marcia Horton Cover Designer: Marta Samsel


Executive Editor: Tracy Johnson (Dunkelberger) Permissions Supervisor: Michael Joyce
Editorial Assistant: Jenah Blitz-Stoehr Permissions Administrator: Jenell Forschler
Director of Marketing: Christy Lesko Director, Image Asset Services: Annie Atherton
Marketing Manager: Yez Alayan Manager, Visual Research: Karen Sanatar
Marketing Assistant: Jon Bryant Image Permission Coordinator:
Director of Program Management: Erin Gregg Cover Art: © Blend Images—PBNJ Productions/Getty
Program Management-Team Lead: Scott Disanno Images
Program Manager: Carole Snyder Media Project Manager: Renata Butera
Project Management-Team Lead: Laura Burgess Full-Service Project Management: Haseen Khan,
Project Manager: Robert Engelhardt Laserwords Pvt Ltd
Procurement Specialist: Linda Sager

Credits and acknowledgments borrowed from other sources and reproduced, with permission, in this textbook
appear on the appropriate page within text.

Microsoft® and Windows® are registered trademarks of the Microsoft Corporation in the U.S.A. and other
countries. Screen shots and icons reprinted with permission from the Microsoft Corporation. This book is not
sponsored or endorsed by or affiliated with the Microsoft Corporation.

Copyright © 2015, 2013, 2011 Pearson Education, Inc., publishing as Prentice Hall, 1 Lake Street, Upper Saddle
River, New Jersey, 07458. All rights reserved. Printed in the United States of America. This publication is protected
by Copyright, and permission should be obtained from the publisher prior to any prohibited reproduction, storage in
a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording,
or likewise. To obtain permission(s) to use material from this work, please submit a written request to Pearson
Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax
your request to 201-236-3290.

Many of the designations by manufacturers and sellers to distinguish their products are claimed as trademarks.
Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations
have been printed in initial caps or all caps.

Library of Congress Cataloging-in-Publication Data available upon request.

10 9 8 7 6 5 4 3 2 1

ISBN 10: 0-13-376131-2


ISBN 13: 978-0-13-376131-3
PREFACE
Dear Reader,

Many of you have provided feedback on earlier editions of this book, and your comments and
suggestions have greatly improved the book. This edition has been substantially enhanced in
presentation, organization, examples, exercises, and supplements. The new edition:
■ Replaces Swing with JavaFX. JavaFX is a new framework for developing Java GUI pro- what is new?
grams. JavaFX greatly simplifies GUI programming and is easier to learn than Swing.
■ Introduces exception handling, abstract classes, and interfaces before GUI programming to
enable the GUI chapters to be skipped completely if the instructor chooses not to cover GUI.
■ Covers introductions to objects and strings earlier in Chapter 4 to enable students to use
objects and strings to develop interesting programs early.
■ Includes many new interesting examples and exercises to stimulate student interests. More
than 100 additional programming exercises are provided to instructors only on the Com-
panion Website.
Please visit www.pearsonhighered.com/liang for a complete list of new features as well as
correlations to the previous edition.
The book is fundamentals first by introducing basic programming concepts and techniques fundamentals-first
before designing custom classes. The fundamental concepts and techniques of selection
statements, loops, methods, and arrays are the foundation for programming. Building this
strong foundation prepares students to learn object-oriented programming and advanced Java
programming.
This book teaches programming in a problem-driven way that focuses on problem solv- problem-driven
ing rather than syntax. We make introductory programming interesting by using thought-
provoking problems in a broad context. The central thread of early chapters is on problem
solving. Appropriate syntax and library are introduced to enable readers to write programs for
solving the problems. To support the teaching of programming in a problem-driven way, the
book provides a wide variety of problems at various levels of difficulty to motivate students.
To appeal to students in all majors, the problems cover many application areas, including
math, science, business, financial, gaming, animation, and multimedia.
The book seamlessly integrates programming, data structures, and algorithms into one text. data structures
It employs a practical approach to teach data structures. We first introduce how to use various
data structures to develop efficient algorithms, and then show how to implement these data
structures. Through implementation, students gain a deep understanding on the efficiency of
data structures and on how and when to use certain data structures. Finally we design and
implement custom data structures for trees and graphs.
The book is widely used in the introductory programming, data structures, and algorithms
courses in the universities around the world. This comprehensive version covers fundamentals comprehensive version
of programming, object-oriented programming, GUI programming, data structures, algorithms,
concurrency, networking, database, and Web programming. It is designed to prepare students
to become proficient Java programmers. A brief version (Introduction to Java Programming, brief version
Brief Version, Tenth Edition) is available for a first course on programming, commonly known AP Computer Science
as CS1. The brief version contains the first 18 chapters of the comprehensive version. The first
13 chapters are appropriate for preparing the AP Computer Science exam.
The best way to teach programming is by example, and the only way to learn program- examples and exercises
ming is by doing. Basic concepts are explained by example and a large number of exercises

iii
iv Preface
with various levels of difficulty are provided for students to practice. For our programming
courses, we assign programming exercises after each lecture.
Our goal is to produce a text that teaches problem solving and programming in a broad
context using a wide variety of interesting examples. If you have any comments on and sug-
gestions for improving the book, please email me.
Sincerely,

Y. Daniel Liang
y.daniel.liang@gmail.com
www.cs.armstrong.edu/liang
www.pearsonhighered.com/liang

ACM/IEEE Curricular 2013 and ABET


Course Assessment
The new ACM/IEEE Computer Science Curricular 2013 defines the Body of Knowledge
organized into 18 Knowledge Areas. To help instructors design the courses based on this book,
we provide sample syllabi to identify the Knowledge Areas and Knowledge Units. The sample
syllabi are for a three semester course sequence and serve as an example for institutional cus-
tomization. The sample syllabi are available to instructors at www.pearsonhighered.com/liang.
Many of our users are from the ABET-accredited programs. A key component of the ABET
accreditation is to identify the weakness through continuous course assessment against the course
outcomes. We provide sample course outcomes for the courses and sample exams for measuring
course outcomes on the instructor Website accessible from www.pearsonhighered.com/liang.

What’s New in This Edition?


This edition is completely revised in every detail to enhance clarity, presentation, content,
examples, and exercises. The major improvements are as follows:
■ Updated to Java 8.
■ Since Swing is replaced by JavaFX, all GUI examples and exercises are revised using
JavaFX.
■ Lambda expressions are used to simplify coding in JavaFX and threads.
■ More than 100 additional programming exercises with solutions are provided to the
instructor on the Companion Website. These exercises are not printed in the text.
■ Math methods are introduced earlier in Chapter 4 to enable students to write code using
math functions.
■ Strings are introduced earlier in Chapter 4 to enable students to use objects and strings to
develop interesting programs early.
■ The GUI chapters are moved to after abstract classes and interfaces so that these chapters
can be easily skipped if the instructor chooses not to cover GUI.
■ Chapters 4, 14, 15, and 16 are brand new chapters.
■ Chapters 28 and 29 have been substantially revised with simpler implementations for min-
imum spanning trees and shortest paths.
Preface v

Pedagogical Features
The book uses the following elements to help students get the most from the material:
■ The Objectives at the beginning of each chapter list what students should learn from the
chapter. This will help them determine whether they have met the objectives after completing
the chapter.
■ The Introduction opens the discussion with representative problems to give the reader an
overview of what to expect from the chapter.
■ Key Points highlight the important concepts covered in each section.
■ Check Points provide review questions to help students track their progress as they read
through the chapter and evaluate their learning.
■ Problems and Case Studies, carefully chosen and presented in an easy-to-follow style,
teach problem solving and programming concepts. The book uses many small, simple, and
stimulating examples to demonstrate important ideas.
■ The Chapter Summary reviews the important subjects that students should under-
stand and remember. It helps them reinforce the key concepts they have learned in the
chapter.
■ Quizzes are accessible online, grouped by sections, for students to do self-test on pro-
gramming concepts and techniques.
■ Programming Exercises are grouped by sections to provide students with opportunities
to apply the new skills they have learned on their own. The level of difficulty is rated as
easy (no asterisk), moderate (*), hard (**), or challenging (***). The trick of learning
programming is practice, practice, and practice. To that end, the book provides a great
many exercises. Additionally, more than 100 programming exercises with solutions are
provided to the instructors on the Companion Website. These exercises are not printed in
the text.
■ Notes, Tips, Cautions, and Design Guides are inserted throughout the text to offer valu-
able advice and insight on important aspects of program development.

Note
Provides additional information on the subject and reinforces important concepts.

Tip
Teaches good programming style and practice.

Caution
Helps students steer away from the pitfalls of programming errors.

Design Guide
Provides guidelines for designing programs.

Flexible Chapter Orderings


The book is designed to provide flexible chapter orderings to enable GUI, exception handling,
recursion, generics, and the Java Collections Framework to be covered earlier or later. The
diagram on the next page shows the chapter dependencies.
vi Preface
Part I: Fundamentals of Part II: Object-Oriented Part III: GUI Programming Part IV: Data Structures and Part V: Advanced Java
Programming Programming Algorithms Ch 16 Programming
Chapter 1 Introduction to Chapter 9 Objects and Classes Chapter 14 JavaFX Basics Ch 7 Chapter 18 Recursion Chapter 30 Multithreading and
Computers, Programs, and Parallel Programming
Java
Chapter 10 Thinking in Objects Chapter 15 Event-Driven Ch 13 Chapter 19 Generics
Programming and Chapter 31 Networking
Chapter 2 Elementary Animations
Chapter 11 Inheritance and Chapter 20 Lists, Stacks, Queues,
Programming
Polymorphism and Priority Queues Chapter 32 Java Database
Chapter 16 JavaFX Controls Programming
Chapter 3 Selections and Multimedia
Chapter 12 Exception Chapter 21 Sets and Maps
Handling and Text I/O Chapter 33 JavaServer Faces
Chapter 4 Mathematical Chapter 34 Advanced GUI Chapter 22 Developping
Functions, Characters, Chapter 13 Abstract Classes Programming Efficient Algorithms
and Strings and Interfaces Chapter 35 Advanced Database
Programming
Chapter 23 Sorting
Chapter 5 Loops Chapter 17 Binary I/O

Chapter 24 Implementing Lists, Chapter 36 Internationalization


Chapter 6 Methods Stacks, Queues, and Priority
Queues

Chapter 7 Single-Dimensional Chapter 37 Servlets


Arrays Chapter 25 Binary Search Trees

Note: Chapters 1–18 are in the Chapter 38 JavaServer Pages


Chapter 8 Multidimensional Chapter 26 AVL Trees
brief version of this book.
Arrays
Note: Chapters 1–33 are in the Chapter 27 Hashing Chapter 39 Web Services
comprehensive version.

Note: Chapters 34–42 are bonus Chapter 28 Graphs and


chapters available from the Applications
Companion Website.
Chapter 29 Weighted Graphs
and Applications

Chapter 40 2-4 Trees and B-


Trees

Chapter 41 Red-Black Trees Ch 9 Chapter 42 Testing Using JUnit


Preface vii

Organization of the Book


The chapters can be grouped into five parts that, taken together, form a comprehensive introduc-
tion to Java programming, data structures and algorithms, and database and Web programming.
Because knowledge is cumulative, the early chapters provide the conceptual basis for under-
standing programming and guide students through simple examples and exercises; subsequent
chapters progressively present Java programming in detail, culminating with the development
of comprehensive Java applications. The appendixes contain a mixed bag of topics, including an
introduction to number systems, bitwise operations, regular expressions, and enumerated types.

Part I: Fundamentals of Programming (Chapters 1–8)


The first part of the book is a stepping stone, preparing you to embark on the journey of learning
Java. You will begin to learn about Java (Chapter 1) and fundamental programming techniques
with primitive data types, variables, constants, assignments, expressions, and operators (Chapter 2),
selection statements (Chapter 3), mathematical functions, characters, and strings (Chapter 4), loops
(Chapter 5), methods (Chapter 6), and arrays (Chapters 7–8). After Chapter 7, you can jump to
Chapter 18 to learn how to write recursive methods for solving inherently recursive problems.

Part II: Object-Oriented Programming (Chapters 9–13, and 17)


This part introduces object-oriented programming. Java is an object-oriented programming
language that uses abstraction, encapsulation, inheritance, and polymorphism to provide
great flexibility, modularity, and reusability in developing software. You will learn program-
ming with objects and classes (Chapters 9–10), class inheritance (Chapter 11), polymorphism
(Chapter 11), exception handling (Chapter 12), abstract classes (Chapter 13), and interfaces
(Chapter 13). Text I/O is introduced in Chapter 12 and binary I/O is discussed in Chapter 17.

Part III: GUI Programming (Chapters 14–16 and Bonus Chapter 34)
JavaFX is a new framework for developing Java GUI programs. It is not only useful for
developing GUI programs, but also an excellent pedagogical tool for learning object-oriented
programming. This part introduces Java GUI programming using JavaFX in Chapters 14–16.
Major topics include GUI basics (Chapter 14), container panes (Chapter 14), drawing shapes
(Chapter 14), event-driven programming (Chapter 15), animations (Chapter 15), and GUI
controls (Chapter 16), and playing audio and video (Chapter 16). You will learn the architec-
ture of JavaFX GUI programming and use the controls, shapes, panes, image, and video to
develop useful applications. Chapter 34 covers advanced features in JavaFX.

Part IV: Data Structures and Algorithms (Chapters 18–29 and Bonus Chapters 40–41)
This part covers the main subjects in a typical data structures and algorithms course. Chapter 18
introduces recursion to write methods for solving inherently recursive problems. Chapter 19
presents how generics can improve software reliability. Chapters 20 and 21 introduce the
Java Collection Framework, which defines a set of useful API for data structures. Chapter 22
discusses measuring algorithm efficiency in order to choose an appropriate algorithm for
applications. Chapter 23 describes classic sorting algorithms. You will learn how to implement
several classic data structures lists, queues, and priority queues in Chapter 24. Chapters 25 and
26 introduce binary search trees and AVL trees. Chapter 27 presents hashing and implement-
ing maps and sets using hashing. Chapters 28 and 29 introduce graph applications. The 2-4
trees, B-trees, and red-black trees are covered in Bonus Chapters 40–41.

Part V: Advanced Java Programming (Chapters 30–33 and Bonus Chapters 35–39, 42)
This part of the book is devoted to advanced Java programming. Chapter 30 treats the use
of multithreading to make programs more responsive and interactive and introduces parallel
programming. Chapter 31 discusses how to write programs that talk with each other from
different hosts over the Internet. Chapter 32 introduces the use of Java to develop database
viii Preface
projects. Chapter 33 introduces modern Web application development using JavaServer Faces.
Chapter 35 delves into advanced Java database programming. Chapter 36 covers the use of
internationalization support to develop projects for international audiences. Chapters 37 and
38 introduce how to use Java servlets and JavaServer Pages to generate dynamic content from
Web servers. Chapter 39 discusses Web services. Chapter 42 introduces testing Java programs
using JUnit.

Appendixes
This part of the book covers a mixed bag of topics. Appendix A lists Java keywords.
Appendix B gives tables of ASCII characters and their associated codes in decimal and in
hex. Appendix C shows the operator precedence. Appendix D summarizes Java modifiers and
their usage. Appendix E discusses special floating-point values. Appendix F introduces num-
ber systems and conversions among binary, decimal, and hex numbers. Finally, Appendix G
introduces bitwise operations. Appendix H introduces regular expressions. Appendix I covers
enumerated types.

Java Development Tools


You can use a text editor, such as the Windows Notepad or WordPad, to create Java programs
and to compile and run the programs from the command window. You can also use a Java
development tool, such as NetBeans or Eclipse. These tools support an integrated develop-
ment environment (IDE) for developing Java programs quickly. Editing, compiling, building,
executing, and debugging programs are integrated in one graphical user interface. Using these
tools effectively can greatly increase your programming productivity. NetBeans and Eclipse
IDE tutorials are easy to use if you follow the tutorials. Tutorials on NetBeans and Eclipse can be found
under Tutorials on the Student Companion Website at www.pearsonhighered.com/liang.

Student Resource Website


The Student Resource Website www.pearsonhighered.com/liang provides access to some of the
following resources. Other resources are available using the student access code printed on the
inside front cover of this book. (For students with a used copy of this book, you can purchase
access to the premium student resources through www.pearsonhighered.com/liang.)
■ Answers to review questions
■ Solutions to even-numbered programming exercises
■ Source code for the examples in the book
■ Interactive quiz (organized by sections for each chapter)
■ Supplements
■ Debugging tips
■ Algorithm animations
■ Errata

Instructor Resource Website


The Instructor Resource Website, accessible from www.pearsonhighered.com/liang, provides
access to the following resources:
■ Microsoft PowerPoint slides with interactive buttons to view full-color, syntax-highlighted
source code and to run programs without leaving the slides.
■ Solutions to all programming exercises. Students will have access to the solutions of even-
numbered programming exercises.
Preface ix
■ More than 100 additional programming exercises organized by chapters. These exercises
are available only to the instructors. Solutions to these exercises are provided.
■ Web-based quiz generator. (Instructors can choose chapters to generate quizzes from a
large database of more than two thousand questions.)
■ Sample exams. Most exams have four parts:
■ Multiple-choice questions or short-answer questions
■ Correct programming errors
■ Trace programs
■ Write programs
■ ACM/IEEE Curricula 2013. The new ACM/IEEE Computer Science Curricula 2013
defines the Body of Knowledge organized into 18 Knowledge Areas. To help instructors
design the courses based on this book, we provide sample syllabi to identify the Knowl-
edge Areas and Knowledge Units. The sample syllabi are for a three semester course
sequence and serve as an example for institutional customization. Instructors can access
the syllabi at www.pearsonhighered.com/liang.
■ Sample exams with ABET course assessment.
■ Projects. In general, each project gives a description and asks students to analyze, design,
and implement the project.
Some readers have requested the materials from the Instructor Resource Website. Please
understand that these are for instructors only. Such requests will not be answered.

Online Practice and Assessment


with MyProgrammingLab
MyProgrammingLab helps students fully grasp the logic, semantics, and syntax of pro-
gramming. Through practice exercises and immediate, personalized feedback, MyProgram-
mingLab improves the programming competence of beginning students who often struggle
with the basic concepts and paradigms of popular high-level programming languages.
A self-study and homework tool, a MyProgrammingLab course consists of hundreds of
small practice problems organized around the structure of this textbook. For students, the sys-
tem automatically detects errors in the logic and syntax of their code submissions and offers
targeted hints that enable students to figure out what went wrong—and why. For instructors,
a comprehensive gradebook tracks correct and incorrect answers and stores the code inputted
by students for review.
MyProgrammingLab is offered to users of this book in partnership with Turing’s Craft, the
makers of the CodeLab interactive programming exercise system. For a full demonstration,
to see feedback from instructors and students, or to get started using MyProgrammingLab in
your course, visit www.myprogramminglab.com.

VideoNotes
We are excited about the new VideoNotes feature that is found in this new edition. These VideoNote

videos provide additional help by presenting examples of key topics and showing how to
solve problems completely, from design through coding. VideoNotes are available from
www.pearsonhighered.com/liang.
Visit https://testbankfan.com
now to explore a rich
collection of testbank or
solution manual and enjoy
exciting offers!
x Preface

Algorithm Animations
Animation We have provided numerous animations for algorithms. These are valuable pedagogical tools
to demonstrate how algorithms work. Algorithm animations can be accessed from the Com-
panion Website.

Acknowledgments
I would like to thank Armstrong Atlantic State University for enabling me to teach what I
write and for supporting me in writing what I teach. Teaching is the source of inspiration for
continuing to improve the book. I am grateful to the instructors and students who have offered
comments, suggestions, bug reports, and praise.
This book has been greatly enhanced thanks to outstanding reviews for this and previous
editions. The reviewers are: Elizabeth Adams (James Madison University), Syed Ahmed (North
Georgia College and State University), Omar Aldawud (Illinois Institute of Technology), Stefan
Andrei (Lamar University), Yang Ang (University of Wollongong, Australia), Kevin Bierre
(Rochester Institute of Technology), David Champion (DeVry Institute), James Chegwidden
(Tarrant County College), Anup Dargar (University of North Dakota), Charles Dierbach (Towson
University), Frank Ducrest (University of Louisiana at Lafayette), Erica Eddy (University of
Wisconsin at Parkside), Deena Engel (NewYork University), Henry A. Etlinger (Rochester Institute
of Technology), James Ten Eyck (Marist College), Myers Foreman (Lamar University), Olac
Fuentes (University of Texas at El Paso), Edward F. Gehringer (North Carolina State University),
Harold Grossman (Clemson University), Barbara Guillot (Louisiana State University), Stuart
Hansen (University of Wisconsin, Parkside), Dan Harvey (Southern Oregon University), Ron
Hofman (Red River College, Canada), Stephen Hughes (Roanoke College), Vladan Jovanovic
(Georgia Southern University), Edwin Kay (Lehigh University), Larry King (University of
Texas at Dallas), Nana Kofi (Langara College, Canada), George Koutsogiannakis (Illinois
Institute of Technology), Roger Kraft (Purdue University at Calumet), Norman Krumpe (Miami
University), Hong Lin (DeVry Institute), Dan Lipsa (Armstrong Atlantic State University),
James Madison (Rensselaer Polytechnic Institute), Frank Malinowski (Darton College),
Tim Margush (University of Akron), Debbie Masada (Sun Microsystems), Blayne Mayfield
(Oklahoma State University), John McGrath (J.P. McGrath Consulting), Hugh McGuire (Grand
Valley State), Shyamal Mitra (University of Texas at Austin), Michel Mitri (James Madison
University), Kenrick Mock (University of Alaska Anchorage), Frank Murgolo (California
State University, Long Beach), Jun Ni (University of Iowa), Benjamin Nystuen (University of
Colorado at Colorado Springs), Maureen Opkins (CA State University, Long Beach), Gavin
Osborne (University of Saskatchewan), Kevin Parker (Idaho State University), Dale Parson
(Kutztown University), Mark Pendergast (Florida Gulf Coast University), Richard Povinelli
(Marquette University), Roger Priebe (University of Texas at Austin), Mary Ann Pumphrey (De
Anza Junior College), Pat Roth (Southern Polytechnic State University), Amr Sabry (Indiana
University), Ben Setzer (Kennesaw State University), Carolyn Schauble (Colorado State
University), David Scuse (University of Manitoba), Ashraf Shirani (San Jose State University),
Daniel Spiegel (Kutztown University), Joslyn A. Smith (Florida Atlantic University), Lixin
Tao (Pace University), Ronald F. Taylor (Wright State University), Russ Tront (Simon Fraser
University), Deborah Trytten (University of Oklahoma), Michael Verdicchio (Citadel), Kent
Vidrine (George Washington University), and Bahram Zartoshty (California State University
at Northridge).
It is a great pleasure, honor, and privilege to work with Pearson. I would like to thank Tracy
Johnson and her colleagues Marcia Horton, Yez Alayan, Carole Snyder, Scott Disanno, Bob
Engelhardt, Haseen Khan, and their colleagues for organizing, producing, and promoting this
project.
As always, I am indebted to my wife, Samantha, for her love, support, and encouragement.
BRIEF CONTENTS
1 Introduction to Computers, Programs, 29 Weighted Graphs and Applications 1061
and Java 1 30 Multithreading and Parallel Programming 1097
2 Elementary Programming 33 31 Networking 1139
3 Selections 75 32 Java Database Programming 1173
4 Mathematical Functions, Characters, 33 JavaServer Faces 1213
and Strings 119
5 Loops 157
6 Methods 203
7 Single-Dimensional Arrays 245 Chapters 34–42 are bonus Web chapters
8 Multidimensional Arrays 287 34 Advanced JavaFX 34-1
9 Objects and Classes 321 35 Advanced Database Programming 35-1
10 Object-Oriented Thinking 365 36 Internationalization 36-1
11 Inheritance and Polymorphism 409 37 Servlets 37-1
12 Exception Handling and Text I/O 449 38 JavaServer Pages 38-1
13 Abstract Classes and Interfaces 495 39 Web Services 39-1
14 JavaFX Basics 535 40 2-4 Trees and B-Trees 40-1
15 Event-Driven Programming 41 Red-Black Trees 41-1
and Animations 585 42 Testing Using JUnit 42-1
16 JavaFX UI Controls and Multimedia 629
17 Binary I/O 677
18 Recursion 705 Appendixes
19 Generics 737 A Java Keywords 1263
20 Lists, Stacks, Queues, B The ASCII Character Set 1266
and Priority Queues 761
C Operator Precedence Chart 1268
21 Sets and Maps 797
D Java Modifiers 1270
22 Developing Efficient Algorithms 821
E Special Floating-Point Values 1272
23 Sorting 861
F Number Systems 1273
24 Implementing Lists, Stacks, Queues,
and Priority Queues 895 G Bitwise Operatoirns 1277
25 Binary Search Trees 929 H Regular Expressions 1278
26 AVL Trees 965 I Enumerated Types 1283
27 Hashing 985
28 Graphs and Applications 1015 Index 1289

xi
CONTENTS
Chapter 1 Introduction to Computers, Programs,
and Java 1
1.1 Introduction 2
1.2 What Is a Computer? 2
1.3 Programming Languages 7
1.4 Operating Systems 9
1.5 Java, the World Wide Web, and Beyond 10
1.6 The Java Language Specification, API, JDK, and IDE 11
1.7 A Simple Java Program 12
1.8 Creating, Compiling, and Executing a Java Program 15
1.9 Programming Style and Documentation 18
1.10 Programming Errors 20
1.11 Developing Java Programs Using NetBeans 23
1.12 Developing Java Programs Using Eclipse 25

Chapter 2 Elementary Programming 33


2.1 Introduction 34
2.2 Writing a Simple Program 34
2.3 Reading Input from the Console 37
2.4 Identifiers 39
2.5 Variables 40
2.6 Assignment Statements and Assignment Expressions 41
2.7 Named Constants 43
2.8 Naming Conventions 44
2.9 Numeric Data Types and Operations 44
2.10 Numeric Literals 48
2.11 Evaluating Expressions and Operator Precedence 50
2.12 Case Study: Displaying the Current Time 52
2.13 Augmented Assignment Operators 54
2.14 Increment and Decrement Operators 55
2.15 Numeric Type Conversions 56
2.16 Software Development Process 59
2.17 Case Study: Counting Monetary Units 63
2.18 Common Errors and Pitfalls 65

Chapter 3 Selections 75
3.1 Introduction 76
3.2 boolean Data Type 76
3.3 if Statements 78
3.4 Two-Way if-else Statements 80
3.5 Nested if and Multi-Way if-else Statements 81
3.6 Common Errors and Pitfalls 83
3.7 Generating Random Numbers 87
3.8 Case Study: Computing Body Mass Index 89
3.9 Case Study: Computing Taxes 90
3.10 Logical Operators 93
3.11 Case Study: Determining Leap Year 97
3.12 Case Study: Lottery 98
3.13 switch Statements 100
3.14 Conditional Expressions 103
xii
xiii
3.15 Operator Precedence and Associativity 104
3.16 Debugging 106

Chapter 4 Mathematical Functions, Characters,


and Strings 119
4.1 Introduction 120
4.2 Common Mathematical Functions 120
4.3 Character Data Type and Operations 125
4.4 The String Type 130
4.5 Case Studies 139
4.6 Formatting Console Output 145

Chapter 5 Loops 157


5.1 Introduction 158
5.2 The while Loop 158
5.3 The do-while Loop 168
5.4 The for Loop 170
5.5 Which Loop to Use? 174
5.6 Nested Loops 176
5.7 Minimizing Numeric Errors 178
5.8 Case Studies 179
5.9 Keywords break and continue 184
5.10 Case Study: Checking Palindromes 187
5.11 Case Study: Displaying Prime Numbers 188

Chapter 6 Methods 203


6.1 Introduction 204
6.2 Defining a Method 204
6.3 Calling a Method 206
6.4 void Method Example 209
6.5 Passing Arguments by Values 212
6.6 Modularizing Code 215
6.7 Case Study: Converting Hexadecimals to Decimals 217
6.8 Overloading Methods 219
6.9 The Scope of Variables 222
6.10 Case Study: Generating Random Characters 223
6.11 Method Abstraction and Stepwise Refinement 225

Chapter 7 Single-Dimensional Arrays 245


7.1 Introduction 246
7.2 Array Basics 246
7.3 Case Study: Analyzing Numbers 253
7.4 Case Study: Deck of Cards 254
7.5 Copying Arrays 256
7.6 Passing Arrays to Methods 257
7.7 Returning an Array from a Method 260
7.8 Case Study: Counting the Occurrences of Each Letter 261
7.9 Variable-Length Argument Lists 264
7.10 Searching Arrays 265
7.11 Sorting Arrays 269
7.12 The Arrays Class 270
7.13 Command-Line Arguments 272

Chapter 8 Multidimensional Arrays 287


8.1 Introduction 288
8.2 Two-Dimensional Array Basics 288
xiv Contents
8.3 Processing Two-Dimensional Arrays 291
8.4 Passing Two-Dimensional Arrays to Methods 293
8.5 Case Study: Grading a Multiple-Choice Test 294
8.6 Case Study: Finding the Closest Pair 296
8.7 Case Study: Sudoku 298
8.8 Multidimensional Arrays 301

Chapter 9 Objects and Classes 321


9.1 Introduction 322
9.2 Defining Classes for Objects 322
9.3 Example: Defining Classes and Creating Objects 324
9.4 Constructing Objects Using Constructors 329
9.5 Accessing Objects via Reference Variables 330
9.6 Using Classes from the Java Library 334
9.7 Static Variables, Constants, and Methods 337
9.8 Visibility Modifiers 342
9.9 Data Field Encapsulation 344
9.10 Passing Objects to Methods 347
9.11 Array of Objects 351
9.12 Immutable Objects and Classes 353
9.13 The Scope of Variables 355
9.14 The this Reference 356

Chapter 10 Object-Oriented Thinking 365


10.1 Introduction 366
10.2 Class Abstraction and Encapsulation 366
10.3 Thinking in Objects 370
10.4 Class Relationships 373
10.5 Case Study: Designing the Course Class 376
10.6 Case Study: Designing a Class for Stacks 378
10.7 Processing Primitive Data Type Values as Objects 380
10.8 Automatic Conversion between Primitive Types
and Wrapper Class Types 383
10.9 The BigInteger and BigDecimal Classes 384
10.10 The String Class 386
10.11 The StringBuilder and StringBuffer Classes 392

Chapter 11 Inheritance and Polymorphism 409


11.1 Introduction 410
11.2 Superclasses and Subclasses 410
11.3 Using the super Keyword 416
11.4 Overriding Methods 419
11.5 Overriding vs. Overloading 420
11.6 The Object Class and Its toString() Method 422
11.7 Polymorphism 423
11.8 Dynamic Binding 424
11.9 Casting Objects and the instanceof Operator 427
11.10 The Object’s equals Method 431
11.11 The ArrayList Class 432
11.12 Useful Methods for Lists 438
11.13 Case Study: A Custom Stack Class 439
11.14 The protected Data and Methods 440
11.15 Preventing Extending and Overriding 442

Chapter 12 Exception Handling and Text I/O 449


12.1 Introduction 450
12.2 Exception-Handling Overview 450
Exploring the Variety of Random
Documents with Different Content
The Project Gutenberg eBook of A British army,
as it was,--is,--and ought to be
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: A British army, as it was,--is,--and ought to be


illustrated by examples during the Peninsular War; with
observations upon India; the United States of America;
Canada; the boundary line; the navy; steam warfare, &c.

Author: Lt. Col. James Campbell

Release date: January 18, 2024 [eBook #72747]

Language: English

Original publication: T. & W. Boone, 1840

Credits: Brian Coe, Graeme Mackreth 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 A BRITISH


ARMY, AS IT WAS,--IS,--AND OUGHT TO BE ***
New original cover art included with this eBook is granted to the
public domain.

A BRITISH ARMY,
AS IT WAS,—IS,—AND OUGHT TO BE:

ILLUSTRATED BY

EXAMPLES DURING THE PENINSULAR WAR:

WITH OBSERVATIONS

UPON

INDIA—THE UNITED STATES OF AMERICA—


CANADA—THE BOUNDARY LINE—THE NAVY—
STEAM WARFARE, &c.

BY LIEUT.-COLONEL JAMES CAMPBELL,


LATE BRIGADE-MAJOR 3RD DIVISION,
AND FORMERLY OF THE 45TH AND 50TH REGIMENTS.
LONDON:

T. & W. BOONE, 29, NEW BOND STREET.

1840.
TO

GENERAL SIR THOMAS M. BRISBANE,

BART., G.C.B., &c. &c. &c.


Sir,
As a soldier who has seen much service in all parts of the world, and
commanded large bodies of troops in the field, you can decide if my
views are correct or not. As a General of the 3rd division, you must
know whether I have erred (certainly unintentionally) in my
statements; and I also trust you will be able to bear me out when I
say, that the honour and renown of my companions in arms, and the
good of the army in general, are my sole objects in appearing before
the public.
I wish to dedicate the fruits of my experience to you, as a trifling
tribute of the gratitude I feel for the friendship and kindness you have
shown me on many occasions.
I can with truth say, my motives in the following work are pure and
disinterested; but my views are not those of the generality of writers
of the day. I know, as well as they do, that British soldiers will always
follow their gallant officers in any attempt, if even requiring the most
supernatural efforts; but I am not, as they almost all seem to be,
blind to the great imperfections of too many of those allowed to enter
our regiments. I can gladly leave them the reputation of possessing
the most undaunted courage of any soldiers in the world, and the
nation the honour and glory their deeds in battle have acquired. Let
both pride themselves, as they have a right to do, upon these; but for
the time to come, we want, and ought to have, the good and true
men of the British Empire brought into the ranks of our armies; and
of whom many—very many—can be found, if called upon, as they
should be, to serve their Sovereign and their country as they might
hereafter be served by a British army, formed, as it ought to be, to
suit the times.
I have the honour to be,

Sir,

Your truly devoted humble servant,

THE AUTHOR.

Ravensdale, June 10, 1840.


CONTENTS
CHAP. I.
What a British Army was, is still, and the commencement of
certain introductory matter, intended to show in part what it
ought to be 1
CHAP. II.
Continuation of the subject, and pointing out what is required to
render the army more suitable to the times 31
CHAP. III.
Continuation of the subject, and showing how essential it is that
corps for East India service, and for our colonies, should be
formed, with a view to rendering the regular army perfectly
efficient.—Various changes recommended and reasons
assigned for them being necessary.—Some observations 60
CHAP. IV.
Continuation of the subject, with observations upon various
matters connected with the efficiency and discipline of the army.
—Veterans unfit for service in North America.—Remarks upon
proposed changes in our militia.—Attention called to various
subjects.—Improvements in system, &c. suggested.—Numbers
of men taken away upon service from corps as bat-men, &c., its
evil effects, and a remedy proposed.—Baggage and followers
of an army in the field, &c. 88
CHAP. V.
Introductory observations upon the staff of an army.—Remarks 126
upon the état-major of the French army.—The staff wanted for a
British army.—Remarks upon the battle of Talavera.—Staff of
an army continued.—An efficient and highly respectable police
for an army in the field recommended.—Some of its duties
alluded to.—Important remarks upon military police and courts-
martial.—Staff duties continued.—Medical department and its
establishments in the field.—The commissariat department in
the field.—Observations
CHAP. VI.
Farther observations.—Insufficiency of allowance of practice
ammunition for corps.—Hints for the maintenance of discipline
in quarters and in the field.—Attention to the religious and
general education of regiments strongly urged.—A plan for this
purpose proposed.—Various necessary observations, &c.—
Lord Wellington's letter to generals commanding divisions and
brigades, with remarks.—Useful observations upon the
storming of Ciudad Rodrigo.—Remarks and general order
relating to the 3rd division in the retreat from Elbodon to
Guinaldo.—Storming of the castle of Badajoz.—Conduct of our
troops there given to show the composition and conduct of a
British army in the field 171
CHAP. VII.
The escalade of the castle of Badajoz held up as an example to
future commanders of such enterprises.—The part performed
by the 3rd division under Sir Edward Pakenham at Salamanca,
with remarks, &c.—The French generals and état-major before
the lines of Torres Vedras, &c.—Marshal Soult and his état-
major before the battle of Toulouse, &c.—The 3rd division at
Toulouse, &c.—Part performed by the 3rd division at Vittoria,
with remarks.—Some occurrences at the Nivelle, with useful
observations.—A few necessary remarks upon the battle of the
Pyrenees. The 3rd division at Orthes, and shewing its style of
fighting there, and upon other occasions.—This farther
illustrated at the Vic Bigore, with other matters 219
CHAP. VIII.
Observations upon the United States of America.—Their 264
present position as regards Great Britain, the Canadas, &c.—
Attention particularly called to that country, with observations
upon naval and military matters.—Expedition to Plattsburg, with
other matters of importance; such as the question of the
Boundary line, &c. and some official documents respecting our
North American territories.—Instructions of a military nature,
respecting Lower Canada in 1814, with useful hints and matters
of consequence to be attended to by Great Britain.—Future
combined naval and military enterprises, with necessary and
useful observations.—Concluding general remarks
ON THE BRITISH ARMY,
&c. &c.
CHAP. I.
I have imposed upon myself a task which may probably expose me
to much annoyance, or perhaps severe criticism; so much so, that I
am almost deterred from entering upon it, in consequence of feeling
that although I may fancy I understand the subjects I intend to write
upon, yet at the same time I greatly fear I am unequal to do them
that justice which they require; but something I shall neither attempt
to describe, nor analyze, urges me on in what I consider, as an
officer of some experience, I ought to undertake; and let the
consequences be what they may, I have the consolation to think, that
my motives, at all events, are pure and disinterested.
Many well-meaning men, and many mischievous men, have for
years past been exerting themselves, with unwearied assiduity, to
have the corporal punishment of flogging done away with in our
army; but no experienced officer, or person acquainted with the
subject, when he considers its former and present composition, can
for an instant entertain such an idea, unless some other mode of
punishment can be thought of, as a substitute, equally prompt, and
which, from its consequences, would keep the transgressor as short
a time from the performance of his duties as flagellation does.
I do not presume to say, that the conduct of all corps of cavalry,
infantry and artillery, were alike; but such officers as have been much
employed with a British army in the field, must be aware of what he
had to contend with, to prevent irregularities, and above all
drunkenness, and the crimes arising out of its demoralizing effects,
into which our soldiers invariably fell; so much so, that the greater
part of them could never be trusted out of the sight of those who had
the charge of them; and the annoyances and sufferings of the
unlucky officers who had too often to bear the blame for their
disorderly conduct, especially in going to and returning from the
several hospital stations, and upon escort, and other duties, which
took them away from their corps in Portugal, Spain, and other
countries, cannot have forgotten what they had to encounter, and
they must fully bear me out when I say, that it was perfect misery to
have any thing to do with them; and nothing but the certainty of
being flogged, if caught by the Provost absent from their corps, kept
many of them in the line of march, or in their camps afterwards; and
as for their conduct at sieges, and upon other occasions, when they
had the power of breaking loose, or from under the watchful eyes of
their officers, the less that is here said by me upon the subject the
better.
This is really a melancholy picture to draw of most of our soldiers;
but I lament to say it is a true one, and I am also reluctantly obliged
to admit, that the almost only redeeming quality which they
possessed, was undaunted courage in battle. But to show that I do
not make these assertions on slight grounds (and I would never have
been induced to do so without an important object in view), I must
beg that the words of his Grace the Duke of Wellington, upon several
occasions, may be duly considered.
In the month of May, 1809, he thus, in general orders, addresses his
army—"The Commander of the Forces is much concerned to be
obliged again to complain of the conduct of the troops; not only have
outrages been committed by whole corps, but there is no description
of property of which the unfortunate inhabitants of Portugal have not
been plundered by the British soldiers, whom they have received into
their houses, or by stragglers from the different regiments of the
army. The Commander of the Forces apprehends that the interior
discipline of the regiments is materially relaxed, &c. &c."
After establishing certain regulations for the maintenance of
discipline, his Grace further observes that, "the object of these
visitings is to see that the soldiers conduct themselves regularly in
their quarters, to ascertain if there are any complaints by their
landlords, and of whom, and that the men are in their quarters,
instead of marauding in search of plunder." And after calling upon
officers of all ranks to perform the duties required of them, he thus
concludes—"The people of Portugal deserve well of the army; they
have in every instance treated the soldiers well; and there never was
an army so well supplied, or which had so little excuse for plunder, if
any excuse can in any case exist. But if the Commander of the
Forces should not by these and other measures be enabled to get
the better of these practices, he is determined to report to His
Majesty, and send into garrison those corps who shall continue
them, as he prefers a small but disciplined and well-conducted body
of troops to a rabble, however numerous; and he is resolved not to
be the instrument of inflicting upon the people of this country the
miseries which result from the operations of such a body. The
regulations of these orders are to be understood as applicable to the
dragoons and the artillery as well as the infantry."
Again, in the month of June, 1812, we read—"The soldiers must not
be allowed to quit their corps to plunder, and Assistant-Provosts
attached to divisions must see that the orders of the army on this
subject are not disobeyed. The Commander of the Forces is sorry to
observe, that the outrages so frequently committed by the soldiers
when absent from their regiments, and the disgraceful scenes which
occurred upon the storming of Badajoz, have had the effect of
rendering the people of the country the enemies, instead of being the
friends of the army. It is the duty of all officers to prevent the soldiers
from plundering, and the Commander of the Forces calls upon them
to perform it. He declares his determination to punish any person
who may be found plundering on any occasion, and to make the
soldiers give up any money or other valuable articles that they may
have plundered.
"As these acts of outrage are generally committed by parties of men,
the parties shall be put under stoppages to make good the damage
which they shall do upon any occasion," And His Grace concludes
this order by calling upon the officers, and non-commissioned
officers, to assist in putting a stop to such disgraceful crimes and
irregularities.
We again read in the General Orders of the 31st of July, 1812:—
"The Commander of the Forces requests to have returns of the
several men missing from their regiments in the march of the 10th
instant. It is reported to the Commander of the Forces that the
enemy have in their power above a hundred men, British soldiers,
taken on that day, straggling in the rear, and in the flanks of the
army. As the army did not march more than ten or twelve miles on
that day, and the country was perfectly open, the straggling of the
soldiers, and their being prisoners, must be attached to the neglect
of the officers of their regiments. It is quite obvious that if the soldiers
cannot be made to march in their ranks at all times, the army cannot
effect a march in face of an enemy, and it is so far unfit for service,
&c. &c."
I do not at present wish to give many extracts from the Duke of
Wellington's orders; but another dated Paris, the 9th of August,
1815, will be sufficient to prove that the character of British soldiers
had not changed from 1812 up to that period.
No. 4. "The Field Marshal receives constant complaints of the
robberies committed on the road from Neuilly to Paris, and he
therefore now desires that guards may be mounted by the divisions
encamped at Neuilly, and in the Bois de Bologne, so as to have
sentries in communication with each other from Neuilly to the barrier
de L'Etoile."
I consider it also necessary to give here two division orders nearly to
the same effect:
"D.O. Madrid, 28th August, 1812.
"1. The officer commanding the escort of prisoners furnished by the
3rd division, which rejoined this morning, has reported that the men
composing that detachment, were extremely irregular while absent,
and some individuals were disobedient to a great degree.
"2. The disobedient non-commissioned officers and soldiers are to
be tried by a Division Court Martial, and the soldiers composing the
remainder of the detachment are to stand under arms from six
o'clock every evening till nine at night, for seven successive days,
when they are to be marched into their quarters, to which they are
also to be confined for the same period.
"3. No soldier of this detachment is to be suffered to take his duty for
seven days, but must make it up afterwards.
"4. Any man of this detachment who shall fall sick before the
expiration of punishment, must stand under arms after recovery.
"5. The British Brigade will ultimately furnish three sergeants to
superintend this disgrace under the orders of the Provost-martial,
who will correct, on the spot, any soldier who may commit further
irregularity.
"Severity and shame are required to bring soldiers to a sense of
duty, who forget every principle when detached, and require force to
command them."
"D.O. Moimenta de Beira, 24th Dec. 1812.
"1. The detachment of recovered men that left Celorico on the 15th
instant, were irregular and disobedient.
"2. So much has been said on the subject of soldiers forgetting their
duty when detached, that Major-General Pakenham, for the present,
gives up the idea of bringing the troops to a sense of discipline by
reason.
"3. When punishment has made the unprincipled sensible of their
crimes, and the good soldiers know they will be supported if they will
take the lead, then reason shall again be referred to.
"4. The soldiers composing the detachment of Lieutenant Walsh, 5th
regiment, are to be assembled at the head-quarters of their
respective brigades, for the purpose of being kept under arms, for
ten days, from daylight till nightfall.
"5. The said soldiers are afterwards to be drilled for one month with
the young soldiers, and they are not to have either spirits or wine for
the whole period.
"6. The Provost-martial and assistant will frequently visit this
punishment and notice any impropriety.
"7. Officers commanding brigades will report the manner in which the
detachment joined the several battalions on the 22d instant."
Many more of Lord Wellington's observations upon the conduct of
soldiers might be adduced, but what I have given, and the orders of
Sir Edward Pakenham, are deemed sufficient for the object now in
view. But his Grace throughout the whole of his campaigns threw
most of the blame for such outrages occurring upon the officers,
whom he constantly accused of neglect of duty, or such crimes could
not have been perpetrated. I beg leave, however, to observe, and I
am alone induced to do so in some measure to justify officers in
general, that many of them were both active and zealous in the
performance of their duties, but the men they had to deal with were
very incorrigible; and those who were then subalterns must well
remember that the chief responsibility rested most heavily upon
them; for the soldiers were almost never allowed to leave their
camps but under their charge; for it was too well known, and I regret
to say it, that many of the non-commissioned officers could not be
much more trusted than the privates.
As a regimental officer of long experience, not only at home and
abroad, but also in the field; as a staff officer during the greater part
of the Peninsular war; and with the army of occupation in France,
and in other parts of the world, I unhesitatingly declare, that corporal
punishment as now inflicted in the army, cannot be dispensed with,
but at the risk of the total subversion of all discipline: indeed the
hampering commanding officers in this respect, as has been the
fashion of late years; and its being fancied, or pretended, that he is
the best commander of a regiment, who returns the smallest number
of soldiers punished, is, to say the least, very impolitic, and most
injurious to the interests of the army; for crimes which should have
called for punishment, must in consequence have been passed over,
or so inadequately visited upon the offenders, that other men could
not have been deterred from being guilty of similar conduct, and the
effects of this, I fear, must in the end be dangerous; for what we
frequently hear of and read respecting military punishments, in some
of the newspapers, can scarcely, when coupled with an unavoidably
relaxed state of discipline, be expected to have any other tendency.
Solitary confinement, to be at all efficacious in preventing or
punishing crimes in the army, keeps the soldier too long away from
his necessary exercises and duties, and if it takes place in our
common jails, whatever he may have gone into them, he certainly
must come out matured in crime, from being the associate of
criminals of the worst description; for what jail can contain sufficient
cells to separate all who may be sent there. Offenders' lists, common
and marching order drills, confinement to barracks, &c. &c., are all
well enough, in these quiet times, for trifling offences or irregularities
at home or abroad, so long as the soldier knows that he can be
brought to the halberts for any act of insubordination on such
occasions; but in case of war, and should it be necessary for our
army to take the field, this system would never answer. I must beg,
however, that it may not be supposed, that I am by any means an
advocate for continuing corporal punishments, or that I have any
intention of extenuating or justifying what was sometimes practised
by officers, under generally, I feel convinced, a mistaken idea, that
they were only doing what their duty required of them; but my
surprise often was, how officers who composed courts-martial, could
by their sentences, always so readily lend themselves to the views,
or perhaps badly regulated feelings of their commanders: indeed the
trials I have witnessed were sometimes little else than mere matter
of form, and they could not well be otherwise, for I have seen a
soldier receive two or three hundred, or even more lashes, inflicted
with great severity, under a sentence awarded by a drum-head court-
martial, after an investigation of a few minutes duration of the
charges brought against him. Such arbitrary proceedings as these,
were generally abuses of power, with which many men are unfit to
be entrusted; and from habit we really thought little of such matters,
and the soldiers themselves were only thereby rendered the more
callous. I declare, however, that I am at a loss to say, which is
preferable—the prompt manner of acting in our navy, where a
captain when he orders the punishment of a man, does so on his
own serious responsibility, or that of a commanding officer of a
regiment, who can generally act as he pleases, whilst all he does is
sanctioned by a court martial.
I could easily bring forward many occurrences which would show in
the strongest light, how much a serious consideration of both our old
and present system in the army, as regards punishments, is
required; but so heartily do I detest flogging, that my thoughts have
been long directed to devise means of getting rid of it; but I always
tremble at the obvious alternative—capital punishments—which
must be resorted to, and I should fear, very frequently, as in the
French armies, especially upon service, as a substitute for flogging
for the maintenance of discipline; for an army without it, is, as the
Duke of Wellington observed in one of the orders I have given, a
rabble, and must be far more dangerous to the country to which it
belongs, than formidable to its enemies.
For years past, I have given this subject most serious consideration.
I have weighed all its difficulties, and I can see no way of doing away
with flogging in a British army, so long as it is composed of the
present description of men. But I am inclined to hope, and I must
now beg that all I have to say may be heard with patience—that this
most desirable object may be attained by a completely new
organisation of our regiments, and bringing into their ranks a totally
different description of men, from those who generally offer
themselves as recruits—men with other ideas, and altogether other
feelings.
But as I wish to bring the subjects I intend to discuss, candidly and
fairly before the reader, I must beg leave to transcribe what Sir
George Murray lately said at a great public meeting in London, as
taken from "the Times." "The British Army did not consist of the
constrained conscripts of arbitrary power, but of citizens voluntarily in
arms to defend their country, to obey and respect her laws at home,
and to resist and repel, with their utmost energy, every effort of her
foreign foes, &c. &c." Sir George Murray, as the world knows, and as
the British Army in particular knows, is a most able and
accomplished Quarter Master General; but as such he could not
have had much to say to the maintenance of discipline, for that
comes under the Adjutant-General; yet still he will no doubt be
looked upon as good authority in such matters, so much so, that I
have been induced thus to give what may be considered as his
opinion, and which the sequel will still more show to be contrary to
mine: indeed, if I were not borne out by the evidence I have even
already adduced, my attempting to do any thing towards
improvement in our army would seem to be unnecessary and
uncalled for.

You might also like