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

PDF Beginning Java Objects: From Concepts to Code 3rd Edition Jacquie Barker download

The document provides information about the ebook 'Beginning Java Objects: From Concepts to Code 3rd Edition' by Jacquie Barker, available for download in various formats. It includes links to additional Java-related ebooks and outlines the content structure of the book, covering fundamental concepts of Java programming and object-oriented design. The document also contains copyright information and details about the publisher and contributors.

Uploaded by

douinzirwa8u
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
26 views

PDF Beginning Java Objects: From Concepts to Code 3rd Edition Jacquie Barker download

The document provides information about the ebook 'Beginning Java Objects: From Concepts to Code 3rd Edition' by Jacquie Barker, available for download in various formats. It includes links to additional Java-related ebooks and outlines the content structure of the book, covering fundamental concepts of Java programming and object-oriented design. The document also contains copyright information and details about the publisher and contributors.

Uploaded by

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

Download the Full Ebook and Access More Features - ebookmass.

com

Beginning Java Objects: From Concepts to Code 3rd


Edition Jacquie Barker

https://ebookmass.com/product/beginning-java-objects-from-
concepts-to-code-3rd-edition-jacquie-barker-2/

OR CLICK HERE

DOWLOAD NOW

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


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Beginning Java Objects: From Concepts to Code 3rd Edition


Jacquie Barker

https://ebookmass.com/product/beginning-java-objects-from-concepts-to-
code-3rd-edition-jacquie-barker-2/

ebookmass.com

Java how to program. Early objects Eleventh Edition Deitel

https://ebookmass.com/product/java-how-to-program-early-objects-
eleventh-edition-deitel/

ebookmass.com

Starting Out with Java: From Control Structures through


Objects 6th Edition, (Ebook PDF)

https://ebookmass.com/product/starting-out-with-java-from-control-
structures-through-objects-6th-edition-ebook-pdf/

ebookmass.com

Marketing: Versión para Latinoamérica 11th Edition Philip


Kotler

https://ebookmass.com/product/marketing-version-para-
latinoamerica-11th-edition-philip-kotler/

ebookmass.com
Optimising Emotions, Incubating Falsehoods: How to Protect
the Global Civic Body from Disinformation and
Misinformation Vian Bakir
https://ebookmass.com/product/optimising-emotions-incubating-
falsehoods-how-to-protect-the-global-civic-body-from-disinformation-
and-misinformation-vian-bakir/
ebookmass.com

Delicate condition 1st Edition Danielle Valentine

https://ebookmass.com/product/delicate-condition-1st-edition-danielle-
valentine/

ebookmass.com

Qualitative Data Analysis: A Methods Sourcebook Third


Edition

https://ebookmass.com/product/qualitative-data-analysis-a-methods-
sourcebook-third-edition/

ebookmass.com

Lunchtime Chronicles: Black Velvet Reana Malori &


Lunchtime Chronicles

https://ebookmass.com/product/lunchtime-chronicles-black-velvet-reana-
malori-lunchtime-chronicles/

ebookmass.com

Introductory Transport Phenomena 1st Edition, (Ebook PDF)

https://ebookmass.com/product/introductory-transport-phenomena-1st-
edition-ebook-pdf/

ebookmass.com
The 7 1/2 Deaths of Evelyn Hardcastle Stuart Turton

https://ebookmass.com/product/the-7-1-2-deaths-of-evelyn-hardcastle-
stuart-turton/

ebookmass.com
Beginning
Java Objects
From Concepts to Code

Third Edition

Jacquie Barker
Beginning Java Objects
From Concepts to Code
Third Edition

Jacquie Barker
Beginning Java Objects: From Concepts to Code
Jacquie Barker
Fairfax, VA, USA

ISBN-13 (pbk): 978-1-4842-9059-0 ISBN-13 (electronic): 978-1-4842-9060-6


https://doi.org/10.1007/978-1-4842-9060-6

Copyright © 2023 by Jacquie Barker


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: Celestin Suresh John
Development Editor: Laura Berendson
Coordinating Editor: Gryffin Winkler
Cover image designed by Pixabay (www.pixabay.com)
Distributed to the book trade worldwide by Springer Science+Business Media LLC, 1 New York Plaza, Suite
4600, New York, NY 10004. 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 https://github.com/Apress/
Beginning-Java-Objects-3e.
Printed on acid-free paper
To my husband, best friend, and love of my life, Steve,
who supports me each and every day in more ways
than he can possibly imagine.
Table of Contents
About the Author���������������������������������������������������������������������������������������������������xvii

About the Technical Reviewer��������������������������������������������������������������������������������xix

Preface�������������������������������������������������������������������������������������������������������������������xxi

Introduction����������������������������������������������������������������������������������������������������������xxiii

Student Registration System (SRS) Case Study��������������������������������������������������xxxv

Part I: The ABCs of Objects����������������������������������������������������������������������������� 1


Chapter 1: Abstraction and Modeling����������������������������������������������������������������������� 3
Simplification Through Abstraction����������������������������������������������������������������������������������������������� 3
Generalization Through Abstraction���������������������������������������������������������������������������������������������� 5
Organizing Abstractions into Classification Hierarchies���������������������������������������������������������� 5
Abstraction as the Basis for Software Development������������������������������������������������������������� 10
Reuse of Abstractions����������������������������������������������������������������������������������������������������������������� 11
Inherent Challenges�������������������������������������������������������������������������������������������������������������������� 13
What Does It Take to Be a Successful Object Modeler?�������������������������������������������������������� 14
Summary������������������������������������������������������������������������������������������������������������������������������������ 17

Chapter 2: Some Java Basics��������������������������������������������������������������������������������� 21


Java Is Architecture Neutral�������������������������������������������������������������������������������������������������������� 22
Anatomy of a Simple Java Program�������������������������������������������������������������������������������������������� 27
Comments����������������������������������������������������������������������������������������������������������������������������� 28
The Class Declaration������������������������������������������������������������������������������������������������������������ 30
The main Method������������������������������������������������������������������������������������������������������������������� 31
Setting Up a Simple Java Development Environment����������������������������������������������������������������� 32

v
Table of Contents

The Mechanics of Java��������������������������������������������������������������������������������������������������������������� 32


Compiling Java Source Code into Bytecode�������������������������������������������������������������������������� 32
Executing Bytecode��������������������������������������������������������������������������������������������������������������� 33
Primitive Types���������������������������������������������������������������������������������������������������������������������������� 34
Variables������������������������������������������������������������������������������������������������������������������������������������� 36
Variable Naming Conventions������������������������������������������������������������������������������������������������ 37
Variable Initialization������������������������������������������������������������������������������������������������������������������� 39
The String Type��������������������������������������������������������������������������������������������������������������������������� 40
Case Sensitivity��������������������������������������������������������������������������������������������������������������������������� 41
Java Expressions������������������������������������������������������������������������������������������������������������������������ 42
Arithmetic Operators������������������������������������������������������������������������������������������������������������� 43
Relational and Logical Operators������������������������������������������������������������������������������������������� 45
Evaluating Expressions and Operator Precedence���������������������������������������������������������������� 46
The Type of an Expression����������������������������������������������������������������������������������������������������� 48
Automatic Type Conversions and Explicit Casting����������������������������������������������������������������������� 48
Loops and Other Flow Control Structures����������������������������������������������������������������������������������� 51
if Statements������������������������������������������������������������������������������������������������������������������������� 52
switch Statements����������������������������������������������������������������������������������������������������������������� 55
for Statements����������������������������������������������������������������������������������������������������������������������� 58
while Statements������������������������������������������������������������������������������������������������������������������ 61
Jump Statements������������������������������������������������������������������������������������������������������������������ 63
Block-Structured Languages and the Scope of a Variable���������������������������������������������������������� 65
Printing to the Console Window�������������������������������������������������������������������������������������������������� 67
print vs. println���������������������������������������������������������������������������������������������������������������������� 69
Escape Sequences���������������������������������������������������������������������������������������������������������������� 71
Elements of Java Style���������������������������������������������������������������������������������������������������������������� 72
Proper Use of Indentation������������������������������������������������������������������������������������������������������ 72
Use Comments Wisely����������������������������������������������������������������������������������������������������������� 76
Placement of Braces������������������������������������������������������������������������������������������������������������� 77
Descriptive Variable Names��������������������������������������������������������������������������������������������������� 78
Summary������������������������������������������������������������������������������������������������������������������������������������ 78

vi
Table of Contents

Chapter 3: Objects and Classes������������������������������������������������������������������������������ 81


Software at Its Simplest�������������������������������������������������������������������������������������������������������������� 81
Functional Decomposition����������������������������������������������������������������������������������������������������� 82
The Object-Oriented Approach���������������������������������������������������������������������������������������������� 85
What Is an Object?���������������������������������������������������������������������������������������������������������������������� 85
State/Data/Attributes������������������������������������������������������������������������������������������������������������� 87
Behavior/Operations/Methods����������������������������������������������������������������������������������������������� 89
What Is a Class?�������������������������������������������������������������������������������������������������������������������������� 91
A Note Regarding Naming Conventions��������������������������������������������������������������������������������� 92
Declaring a Class, Java Style������������������������������������������������������������������������������������������������� 93
Instantiation�������������������������������������������������������������������������������������������������������������������������������� 94
Encapsulation����������������������������������������������������������������������������������������������������������������������������� 96
User-Defined Types and Reference Variables����������������������������������������������������������������������������� 97
Naming Conventions for Reference Variables����������������������������������������������������������������������� 99
Instantiating Objects: A Closer Look������������������������������������������������������������������������������������������ 100
Garbage Collection�������������������������������������������������������������������������������������������������������������� 110
Objects As Attributes����������������������������������������������������������������������������������������������������������������� 111
A Compilation “Trick”: “Stubbing Out” Classes������������������������������������������������������������������� 115
Composition������������������������������������������������������������������������������������������������������������������������� 118
The Advantages of References As Attributes����������������������������������������������������������������������� 120
Three Distinguishing Features of an Object-Oriented Programming Language������������������������ 121
Summary���������������������������������������������������������������������������������������������������������������������������������� 121

Chapter 4: Object Interactions������������������������������������������������������������������������������ 125


Events Drive Object Collaboration��������������������������������������������������������������������������������������������� 126
Declaring Methods�������������������������������������������������������������������������������������������������������������������� 128
Method Headers������������������������������������������������������������������������������������������������������������������ 129
Method Naming Conventions���������������������������������������������������������������������������������������������� 129
Passing Arguments to Methods������������������������������������������������������������������������������������������� 130
Method Return Types����������������������������������������������������������������������������������������������������������� 131
An Analogy��������������������������������������������������������������������������������������������������������������������������� 133

vii
Table of Contents

Method Bodies��������������������������������������������������������������������������������������������������������������������� 134


Features May Be Declared in Any Order������������������������������������������������������������������������������ 135
return Statements��������������������������������������������������������������������������������������������������������������� 136
Methods Implement Business Rules����������������������������������������������������������������������������������������� 141
Objects As the Context for Method Invocation�������������������������������������������������������������������������� 142
Java Expressions, Revisited������������������������������������������������������������������������������������������������ 146
Capturing the Value Returned by a Method������������������������������������������������������������������������� 147
Method Signatures�������������������������������������������������������������������������������������������������������������� 148
Choosing Descriptive Method Names���������������������������������������������������������������������������������� 150
Method Overloading������������������������������������������������������������������������������������������������������������������ 151
Message Passing Between Objects������������������������������������������������������������������������������������������ 153
Delegation��������������������������������������������������������������������������������������������������������������������������������� 156
Obtaining Handles on Objects��������������������������������������������������������������������������������������������������� 157
Objects As Clients and Suppliers���������������������������������������������������������������������������������������������� 162
Information Hiding/Accessibility����������������������������������������������������������������������������������������������� 165
Public Accessibility�������������������������������������������������������������������������������������������������������������� 166
Private Accessibility������������������������������������������������������������������������������������������������������������� 168
Publicizing Services������������������������������������������������������������������������������������������������������������ 169
Method Headers, Revisited�������������������������������������������������������������������������������������������������� 171
Accessing the Features of a Class from Within Its Own Methods��������������������������������������� 171
Accessing Private Features from Client Code��������������������������������������������������������������������������� 176
Declaring Accessor Methods����������������������������������������������������������������������������������������������� 176
Recommended “Get”/“Set” Method Headers���������������������������������������������������������������������� 178
IDE-Generated Get/Set Methods������������������������������������������������������������������������������������������ 182
The “Persistence” of Attribute Values���������������������������������������������������������������������������������� 183
Using Accessor Methods from Client Code�������������������������������������������������������������������������� 183
The Power of Encapsulation Plus Information Hiding��������������������������������������������������������������� 184
Preventing Unauthorized Access to Encapsulated Data������������������������������������������������������ 185
Helping Ensure Data Integrity���������������������������������������������������������������������������������������������� 185
Limiting “Ripple Effects” When Private Features Change��������������������������������������������������� 188
Using Accessor Methods from Within a Class’s Own Methods�������������������������������������������� 191

viii
Table of Contents

Exceptions to the Public/Private Rule��������������������������������������������������������������������������������������� 197


Constructors������������������������������������������������������������������������������������������������������������������������������ 201
Default Constructors������������������������������������������������������������������������������������������������������������ 201
Writing Our Own Explicit Constructors�������������������������������������������������������������������������������� 202
Passing Arguments to Constructors������������������������������������������������������������������������������������ 203
Replacing the Default Parameterless Constructor�������������������������������������������������������������� 205
More Elaborate Constructors����������������������������������������������������������������������������������������������� 206
Overloading Constructors���������������������������������������������������������������������������������������������������� 208
An Important Caveat Regarding the Default Constructor���������������������������������������������������� 210
Using the “this” Keyword to Facilitate Constructor Reuse�������������������������������������������������� 212
Software at Its Simplest, Revisited������������������������������������������������������������������������������������������� 216
Summary���������������������������������������������������������������������������������������������������������������������������������� 218

Chapter 5: Relationships Between Objects����������������������������������������������������������� 223


Associations and Links������������������������������������������������������������������������������������������������������������� 224
Multiplicity��������������������������������������������������������������������������������������������������������������������������� 227
Multiplicity and Links���������������������������������������������������������������������������������������������������������� 229
Aggregation and Composition��������������������������������������������������������������������������������������������������� 232
Inheritance�������������������������������������������������������������������������������������������������������������������������������� 234
Responding to Shifting Requirements with a New Abstraction������������������������������������������� 234
(Inappropriate) Approach #1: Modify the Student Class������������������������������������������������������ 235
(Inappropriate) Approach #2: “Clone” the Student Class to Create a GraduateStudent
Class������������������������������������������������������������������������������������������������������������������������������������ 239
The Proper Approach (#3): Taking Advantage of Inheritance����������������������������������������������� 241
The “is a” Nature of Inheritance������������������������������������������������������������������������������������������ 242
The Benefits of Inheritance������������������������������������������������������������������������������������������������� 246
Class Hierarchies����������������������������������������������������������������������������������������������������������������� 247
The Object Class������������������������������������������������������������������������������������������������������������������ 250
Is Inheritance Really a Relationship?���������������������������������������������������������������������������������� 250
Avoiding “Ripple Effects” in a Class Hierarchy�������������������������������������������������������������������� 251
Rules for Deriving Classes: The “Do’s”�������������������������������������������������������������������������������� 252
Overriding���������������������������������������������������������������������������������������������������������������������������� 252

ix
Table of Contents

Reusing Superclass Behaviors: The “super” Keyword�������������������������������������������������������� 256


Rules for Deriving Classes: The “Don’ts”����������������������������������������������������������������������������� 260
Private Features and Inheritance���������������������������������������������������������������������������������������� 262
Inheritance and Constructors���������������������������������������������������������������������������������������������� 267
A Few Words About Multiple Inheritance����������������������������������������������������������������������������� 275
Three Distinguishing Features of an OOPL, Revisited��������������������������������������������������������������� 280
Summary���������������������������������������������������������������������������������������������������������������������������������� 280

Chapter 6: Collections of Objects������������������������������������������������������������������������� 285


What Are Collections?��������������������������������������������������������������������������������������������������������������� 286
Collections Are Defined by Classes and Must Be Instantiated�������������������������������������������� 286
Collections Organize References to Other Objects�������������������������������������������������������������� 287
Collections Are Encapsulated���������������������������������������������������������������������������������������������� 289
Three Generic Types of Collection��������������������������������������������������������������������������������������������� 290
Ordered Lists����������������������������������������������������������������������������������������������������������������������� 290
Dictionaries������������������������������������������������������������������������������������������������������������������������� 292
Sets������������������������������������������������������������������������������������������������������������������������������������� 293
Arrays As Simple Collections���������������������������������������������������������������������������������������������������� 295
Declaring and Instantiating Arrays�������������������������������������������������������������������������������������� 295
Accessing Individual Array Elements����������������������������������������������������������������������������������� 297
Initializing Array Contents���������������������������������������������������������������������������������������������������� 298
Manipulating Arrays of Objects������������������������������������������������������������������������������������������� 300
A More Sophisticated Type of Collection: The ArrayList Class��������������������������������������������������� 305
Using the ArrayList Class: An Example�������������������������������������������������������������������������������� 306
Import Directives and Packages������������������������������������������������������������������������������������������ 306
The Namespace of a Class�������������������������������������������������������������������������������������������������� 310
User-Defined Packages and the Default Package��������������������������������������������������������������� 313
Generics������������������������������������������������������������������������������������������������������������������������������ 314
ArrayList Features��������������������������������������������������������������������������������������������������������������� 315
Iterating Through ArrayLists������������������������������������������������������������������������������������������������ 318
Copying the Contents of an ArrayList into an Array������������������������������������������������������������� 319
The HashMap Collection Class�������������������������������������������������������������������������������������������������� 321

x
Table of Contents

The TreeMap Class�������������������������������������������������������������������������������������������������������������������� 329


The Same Object Can Be Simultaneously Referenced by Multiple Collections������������������������� 332
Inventing Our Own Collection Types������������������������������������������������������������������������������������������ 334
Approach #1: Designing a New Collection Class from Scratch������������������������������������������ 334
Approach #2: Extending a Predefined Collection Class (MyIntCollection)��������������������������� 335
Approach #3: Encapsulating a Standard Collection (MyIntCollection2)������������������������������� 341
Trade-Offs of Approach #2 vs. Approach #3������������������������������������������������������������������������ 346
Collections As Method Return Types����������������������������������������������������������������������������������������� 348
Collections of Derived Types����������������������������������������������������������������������������������������������������� 350
Revisiting Our Student Class Design����������������������������������������������������������������������������������������� 351
The courseLoad Attribute of Student����������������������������������������������������������������������������������� 352
The transcript Attribute of Student�������������������������������������������������������������������������������������� 352
The transcript Attribute, Take 2�������������������������������������������������������������������������������������������� 356
Our Completed Student Data Structure������������������������������������������������������������������������������� 363
Summary���������������������������������������������������������������������������������������������������������������������������������� 364

Chapter 7: Some Final Object Concepts���������������������������������������������������������������� 367


Polymorphism��������������������������������������������������������������������������������������������������������������������������� 368
Polymorphism Simplifies Code Maintenance���������������������������������������������������������������������� 375
Three Distinguishing Features of an Object-Oriented Programming Language������������������������ 378
The Benefits of User-Defined Types������������������������������������������������������������������������������������� 378
The Benefits of Inheritance������������������������������������������������������������������������������������������������� 379
The Benefits of Polymorphism��������������������������������������������������������������������������������������������� 379
Abstract Classes����������������������������������������������������������������������������������������������������������������������� 380
Implementing Abstract Methods����������������������������������������������������������������������������������������� 385
Abstract Classes and Instantiation�������������������������������������������������������������������������������������� 387
Declaring Reference Variables of Abstract Types���������������������������������������������������������������� 389
An Interesting Twist on Polymorphism�������������������������������������������������������������������������������� 390
Interfaces���������������������������������������������������������������������������������������������������������������������������������� 392
Implementing Interfaces����������������������������������������������������������������������������������������������������� 395
Another Form of the “Is A” Relationship������������������������������������������������������������������������������ 400
Interfaces and Casting��������������������������������������������������������������������������������������������������������� 401

xi
Table of Contents

Implementing Multiple Interfaces���������������������������������������������������������������������������������������� 406


Interfaces and Casting, Revisited���������������������������������������������������������������������������������������� 409
Interfaces and Instantiation������������������������������������������������������������������������������������������������� 410
Interfaces and Polymorphism���������������������������������������������������������������������������������������������� 411
The Importance of Interfaces���������������������������������������������������������������������������������������������� 412
Static Features�������������������������������������������������������������������������������������������������������������������������� 423
Static Variables�������������������������������������������������������������������������������������������������������������������� 423
A Design Improvement: Burying Implementation Details���������������������������������������������������� 428
Static Methods�������������������������������������������������������������������������������������������������������������������� 429
Restrictions on Static Methods�������������������������������������������������������������������������������������������� 430
Utility Classes���������������������������������������������������������������������������������������������������������������������� 432
The final Keyword���������������������������������������������������������������������������������������������������������������� 433
Custom Utility Classes��������������������������������������������������������������������������������������������������������� 437
Summary���������������������������������������������������������������������������������������������������������������������������������� 439

Part II: Object Modeling 101��������������������������������������������������������������������������������� 443

Chapter 8: The Object Modeling Process in a Nutshell����������������������������������������� 445


The “Big Picture” Goal of Object Modeling������������������������������������������������������������������������������� 445
Modeling Methodology = Process + Notation + Tool���������������������������������������������������������� 446
My Recommended Object Modeling Process, in a Nutshell������������������������������������������������������ 451
Thoughts Regarding Object Modeling Software Tools��������������������������������������������������������� 452
A Reminder�������������������������������������������������������������������������������������������������������������������������� 455
Summary���������������������������������������������������������������������������������������������������������������������������������� 455

Chapter 9: Formalizing Requirements Through Use Cases����������������������������������� 457


What Are Use Cases?���������������������������������������������������������������������������������������������������������������� 458
Functional vs. Technical Requirements������������������������������������������������������������������������������� 458
Involving the Users�������������������������������������������������������������������������������������������������������������� 460
Actors���������������������������������������������������������������������������������������������������������������������������������������� 460
Identifying Actors and Determining Their Roles������������������������������������������������������������������ 461
Diagramming a System and Its Actors�������������������������������������������������������������������������������� 463
Specifying Use Cases���������������������������������������������������������������������������������������������������������������� 466

xii
Table of Contents

Matching Up Use Cases with Actors����������������������������������������������������������������������������������������� 468


To Diagram or Not to Diagram?������������������������������������������������������������������������������������������������� 468
Summary���������������������������������������������������������������������������������������������������������������������������������� 470

Chapter 10: Modeling the Static/Data Aspects of the System������������������������������ 473


Identifying Appropriate Classes������������������������������������������������������������������������������������������������ 474
Noun Phrase Analysis���������������������������������������������������������������������������������������������������������� 475
Refining the Candidate Class List���������������������������������������������������������������������������������������� 483
Revisiting the Use Cases����������������������������������������������������������������������������������������������������� 488
Producing a Data Dictionary����������������������������������������������������������������������������������������������������� 491
Determining Associations Between Classes����������������������������������������������������������������������������� 492
Association Matrices����������������������������������������������������������������������������������������������������������� 495
Identifying Attributes����������������������������������������������������������������������������������������������������������������� 498
UML Notation: Modeling the Static Aspects of an Abstraction�������������������������������������������������� 498
Classes, Attributes, and Operations������������������������������������������������������������������������������������� 499
Relationships Between Classes������������������������������������������������������������������������������������������� 503
Reflecting Multiplicity���������������������������������������������������������������������������������������������������������� 511
Object/Instance Diagrams��������������������������������������������������������������������������������������������������������� 516
Associations As Attributes��������������������������������������������������������������������������������������������������������� 518
Information “Flows” Along an Association “Pipeline”��������������������������������������������������������������� 520
“Mixing and Matching” Relationship Notations������������������������������������������������������������������������ 527
Association Classes������������������������������������������������������������������������������������������������������������������ 531
Our “Completed” Student Registration System Class Diagram������������������������������������������������ 534
Metadata����������������������������������������������������������������������������������������������������������������������������������� 543
Summary���������������������������������������������������������������������������������������������������������������������������������� 545

Chapter 11: Modeling the Dynamic/Behavioral Aspects of the System��������������� 547


How Behavior Affects State������������������������������������������������������������������������������������������������������ 548
Events���������������������������������������������������������������������������������������������������������������������������������� 551
Scenarios���������������������������������������������������������������������������������������������������������������������������������� 556
Scenario #1 for the “Register for a Course” Use Case�������������������������������������������������������� 557
Scenario #2 for the “Register for a Course” Use Case�������������������������������������������������������� 559

xiii
Table of Contents

Sequence Diagrams������������������������������������������������������������������������������������������������������������������ 560


Determining Objects and External Actors for Scenario #1�������������������������������������������������� 561
Preparing the Sequence Diagram���������������������������������������������������������������������������������������� 563
Using Sequence Diagrams to Determine Methods������������������������������������������������������������������� 568
Communication Diagrams��������������������������������������������������������������������������������������������������������� 571
Revised SRS Class Diagram������������������������������������������������������������������������������������������������������ 573
Summary���������������������������������������������������������������������������������������������������������������������������������� 575

Chapter 12: Wrapping Up Our Modeling Efforts���������������������������������������������������� 579


Testing the Model���������������������������������������������������������������������������������������������������������������������� 579
Revisiting Requirements����������������������������������������������������������������������������������������������������������� 580
Reusing Models: A Word About Design Patterns����������������������������������������������������������������������� 584
Summary���������������������������������������������������������������������������������������������������������������������������������� 587

Part III: Translating an Object Blueprint into Java Code����������������������������� 589


Chapter 13: A Few More Java Details������������������������������������������������������������������� 591
Java-Specific Terminology�������������������������������������������������������������������������������������������������������� 592
Java Archive (jar) Files�������������������������������������������������������������������������������������������������������������� 593
Creating Jar Files���������������������������������������������������������������������������������������������������������������� 594
Inspecting the Contents of a Jar File����������������������������������������������������������������������������������� 595
Using the Bytecode Contained Within a Jar File������������������������������������������������������������������ 596
Extracting Contents from Jar Files�������������������������������������������������������������������������������������� 597
“Jarring” Entire Directory Hierarchies��������������������������������������������������������������������������������� 597
Javadoc Comments������������������������������������������������������������������������������������������������������������������� 599
The Object Nature of Strings����������������������������������������������������������������������������������������������������� 608
Operations on Strings���������������������������������������������������������������������������������������������������������� 608
Strings Are Immutable��������������������������������������������������������������������������������������������������������� 612
The StringBuffer Class��������������������������������������������������������������������������������������������������������� 616
The StringTokenizer Class��������������������������������������������������������������������������������������������������� 617
Instantiating Strings and the String Literal Pool������������������������������������������������������������������ 620
Testing the Equality of Strings��������������������������������������������������������������������������������������������� 624
Message Chains������������������������������������������������������������������������������������������������������������������������ 626

xiv
Table of Contents

Object Self-Referencing with “this”������������������������������������������������������������������������������������������ 628


Java Exception Handling����������������������������������������������������������������������������������������������������������� 630
The Mechanics of Exception Handling��������������������������������������������������������������������������������� 633
Catching Exceptions������������������������������������������������������������������������������������������������������������ 645
Interpreting Exception Stack Traces������������������������������������������������������������������������������������ 651
The Exception Class Hierarchy�������������������������������������������������������������������������������������������� 654
Catching the Generic Exception Type���������������������������������������������������������������������������������� 658
Compiler Enforcement of Exception Handling��������������������������������������������������������������������� 659
Taking Advantage of the Exception That We’ve Caught������������������������������������������������������� 661
Nesting of Try/Catch Blocks������������������������������������������������������������������������������������������������� 662
User-Defined Exception Types��������������������������������������������������������������������������������������������� 663
Throwing Multiple Types of Exception��������������������������������������������������������������������������������� 668
Enum(eration)s�������������������������������������������������������������������������������������������������������������������������� 668
Providing Input to Command-Line-Driven Programs���������������������������������������������������������������� 678
Accepting Command-Line Arguments: The args Array�������������������������������������������������������� 679
Introducing Custom Command-Line Flags to Control a Program’s Behavior����������������������� 681
Accepting Keyboard Input: The Scanner Class�������������������������������������������������������������������� 687
Using Wrapper Classes for Input Conversion����������������������������������������������������������������������� 689
Features of the Object Class����������������������������������������������������������������������������������������������������� 692
Determining the Class That an Object Belongs To��������������������������������������������������������������� 692
Testing the Equality of Objects�������������������������������������������������������������������������������������������� 694
Overriding the equals Method��������������������������������������������������������������������������������������������� 700
Overriding the toString Method������������������������������������������������������������������������������������������� 704
Static Initializers������������������������������������������������������������������������������������������������������������������ 707
Variable Initialization, Revisited������������������������������������������������������������������������������������������������ 709
Variable Arguments (varargs)���������������������������������������������������������������������������������������������� 712
Summary���������������������������������������������������������������������������������������������������������������������������������� 716

Chapter 14: Transforming the Model into Java Code�������������������������������������������� 719


Suggestions for Getting the Maximum Value from This Chapter���������������������������������������������� 720
The SRS Class Diagram Revisited��������������������������������������������������������������������������������������������� 720
The Person Class (Specifying Abstract Classes)������������������������������������������������������������������ 724

xv
Another Random Document on
Scribd Without Any Related Topics
Or winged winds in speed outvies.
Nay, she might fly o’er fields of grain
Nor crush in flight the tapering wheat, 10
Or skim the surface of the main,
Nor let the billows touch her feet.
Where’er she moves, from house and land
The youths and ancient matrons throng,
And fixed in greedy wonder stand 15
Beholding as she speeds along:
In kingly dye that scarf was dipped:
’Tis gold confines those tresses’ flow:
Her pastoral wand with steel is tipped,
And Lycian are her shafts and bow. 20
BOOK VIII
Soon as Turnus set high on Laurentum’s tower the
ensign of war, and the horns clanged forth their harsh
music, soon as he shook the reins in the mouth of his
fiery steeds, and clashed his armour, at once came a stirring
of men’s souls: all Latium conspires in tumultuous rising, 5
and the warrior bands are inflamed to madness. The
generals, Messapus and Ufens and Mezentius, scorner of
the gods, assume the lead, mustering succour from all
sides and unpeopling the fields of their tillers far and
wide. Venulus too is sent to the town of mighty Diomede 10
to entreat help, and set forth that the Teucrians are
planting foot in Latium: that Æneas is arrived by sea
and intruding his vanquished home-gods, and announcing
himself as the Latians’ destined king; that many tribes
are flocking to the standard of the Dardan chief, and the 15
contagion of his name is spreading over Latium’s length
and breadth. What is to be the end of such a beginning,
what, should fortune favour him, he promises to himself
as the issue of the battle, Diomede will know better than
king Turnus or king Latinus. 20

So go things in Latium. The chief of Laomedon’s line


sees it all, and is tossed on a sea of cares; now on this
point, now on that, he throws in a moment the forces of
his mind, hurrying it into all quarters and sweeping the
whole range of thought: as in water a flickering beam 25
on a brazen vat, darted back by the sun or the bright
moon’s image, flits far and wide over the whole place,
now at last mounting to the sky and striking the ceiling
of the roof. Night came, and tired life the earth over,
bird and beast alike, were lapped deep in slumber, when 30
Æneas, good king, troubled at heart by the anxious war,
stretched himself on the bank under heaven’s chilly cope,
and let repose at last steal over his frame. Before him
appeared in person the god of the place, old Tiber of the
pleasant stream, rising among the poplar foliage: a gray
mantle of transparent linen floated about him, and his 5
hair was shaded with bushy reeds: and thus he began to
address the chief and relieve his care: “O offspring of
heaven’s stock, who are bringing back to us safe from
the foe the city of Troy, and preserving Pergamus in enduring
life, yourself looked for long on the Laurentian 10
soil and in the fields of Latium, here is your abiding place
of rest, here, distrust it not, permanence for your home-gods:
let not war’s threatenings make you afraid, the
swellings of the anger of heaven have all given way.
Even now, that you may not think this the idle coinage 15
of sleep, under the oaks on the bank you shall find an
enormous swine lying with a litter of thirty head just
born, white herself throughout her lazy length, her children
round her breasts as white as she: a sign that when
thirty years have made their circuit, Ascanius shall found 20
that city known by the illustrious name of the White.
Of no doubtful issue are these words of mine. Now for
the way in which you may triumphantly unravel the
present knot, grant me your attention, and I will show
you in brief. On this my coast, Arcadians, a race sprung 25
from Pallas, who have followed king Evander and his
banner, have chosen themselves a site and built a city
on the hills, called from the name of their ancestor Pallas,
Pallanteum. These are forever engaged in war with the
Latian nation: let them join your camp as allies, and 30
make league with them. I myself will lead you between
the banks, straight along my stream, that as you journey
up your oars may surmount the adverse current. Up
then, goddess-born, and ere the stars have well set, offer
prayer in due course to Juno, and overbear with suppliant 35
vows her anger and her menace. Once triumphant,
you shall pay your worship to me. I am he whom you
see here with brimming flood grazing the banks and
threading rich cultured lands, sea-green Tiber, the river
whom gods love best. Here rises my royal palace, the
crown of lofty cities.” The river-god said, and plunged
into his deep pool, down to the bottom; night and sleep
at once fled from Æneas. He rises, and with his eyes 5
fixed on the sun’s rays just dawning on the sky, he lifts
up in due form water from the river in the hollow of
his hands, and pours forth to heaven words like these:
“Nymphs, Laurentian nymphs, whence rivers derive their
birth, and thou, father Tiber, with thy hallowed flood, 10
take Æneas to your bosom, and at last relieve him from
perils. Whatever the spring of the pool where thou
dwellest in thy pity for our troubles, whatever the soil
whence thy goodly stream arises, ever shalt thou be
honoured by me with sacrifice, ever with offerings, the 15
river with the crescent horn, the monarch of Hesperian
waters. Be but thou present, and confirm by thy deed
thy heavenly tokens.” So saying, he chooses two biremes
from the fleet and fits them with rowers, while he gives
his comrades arms to wear. 20

When lo, a sudden portent marvellous to view—stretched


in milk-white length along the sward, herself of
one hue with her white litter, conspicuous on the verdant
bank is seen a sow, whom pious Æneas to thee, even to
thee, mightiest Juno, immolates in sacrifice, and sets her 25
with all her brood before the altar. That whole night
long Tiber smoothed his brimming stream, and so stood
with hushed waves, half recoiling, as to lay down a watery
floor as of some gentle lake or peaceful pool, that the oar
might have nought to struggle with. So they begin their 30
voyage and speed with auspicious cheers. Smooth along
the surface floats the anointed pine: marvelling stand
the waters, marvelling the unwonted wood, to see the
warriors’ shields gleaming far along the stream, and the
painted vessels gliding between the banks. The rowers 35
give no rest to night or day, as they surmount the long
meanders, sweep under the fringe of diverse trees, and
cut through the woods that look green in the still expanse.
The sun had climbed in full blaze the central cope of
heaven, when from afar they see walls, and a citadel,
and the roofs of straggling habitations—the place which
the power of Rome has now made to mate the skies:
then it was but Evander’s poor domain. At once they 5
turn their prows to land and approach the town.

It happened that on that day the Arcadian monarch


was performing a yearly sacrifice to Amphitryon’s mighty
child[250] and the heavenly brotherhood in a grove before the
city. With him his son Pallas, with him all the prime of 10
his warriors and his unambitious senate were offering incense,
and the new-shed blood was steaming warm on the
altar. Soon as they saw tall ships gliding toward them
through the shadowy trees, and plying the oar in silence,
alarmed by the sudden apparition, each and all start up 15
from the sacrificial board. Pallas, bolder than the rest,
bids them not break the sacred observance, and snatching
up a weapon flies himself to meet the strangers, and
from a height at distance, “Warriors,” he cries, “what
cause has led you to venture on a path you know not? 20
whither are you bound? what is your nation, your family?
is it peace you bring us or war?” Then father Æneas
bespeaks him thus from the lofty stern, stretching forth
in his hand a branch of peaceful olive: “These are Trojans
you see. These weapons mean hostility to the 25
Latins, who have driven us from their land by a tyrannous
war. Our errand is to Evander. Take back our message,
and say that chosen chiefs of Dardany are at his gate,
praying for an armed alliance.” That mighty name
struck awe into Pallas. “Disembark,” he cries, “whoever 30
you be, and speak to my sire in person, and come
beneath our home-gods’ hospitable shelter,” and gave his
hand in welcome, and clung to the hand he clasped.
They advance under the shade of the grove, and leave
the river behind. 35

Then Æneas addresses the king with friendly courtesy:


“Best of the sons of Greece, to whom it has pleased Fortune
that I should make my prayer and stretch out boughs
wreathed with fillets, I felt no fear for that you were a
Danaan leader, an Arcadian, allied by lineage with the
two sons of Atreus: I felt that my own worth, and the
gods’ hallowed oracles, and the old connection of our
ancestry, and your world-wide fame, had linked me to 5
you, and brought me before you at once by destiny and
of my own will. Dardanus, first father and founder of the
town of Ilion, born, as Greeks tell, of Electra, daughter of
Atlas, came among Teucer’s people: Electra’s father was
mighty Atlas, he that bears up on his shoulders the 10
spheres of heaven. Your progenitor is Mercury, whom
beauteous Maia[251] conceived and brought forth on Cyllene’s
chill summit; but Maia, if tradition be credited, is the
child of Atlas, the same Atlas who lifts up the stars of
the firmament. Thus our two races part off from one 15
and the same stock. Trusting to this, I sent no embassy,
nor contrived the first approaches to you by rule
and method: in myself, in my own person, I have made
the experiment, and come to your gate as a suppliant.
The same tribe which persecutes you, the Daunians, is 20
now persecuting us with cruel war: should they drive us
away, they foresee nought to hinder their subduing all
Hesperia utterly to their yoke, and mastering either sea,
that washes it above or below. Take our friendship and
give us yours. On our side are hearts valiant in war, 25
and a gallant youth approved by adventure.”

Æneas ended. Long ere this the other’s eye was scanning
the speaker’s countenance and eyes, and surveying
his whole frame. Then he returns in brief: “With what
joy, bravest of the Teucrians, do I welcome and acknowledge 30
ye! how well I call to mind the words, the voice,
the look of your sire, the great Anchises! For I remember
how Priam, son of Laomedon, journeying to Salamis,
to see the kingdom of his sister Hesione, went on to visit
the chill frontier of Arcadia. In those days the first 35
bloom of youth was clothing my cheeks. I admired the
Teucrian leaders, I admired Laomedon’s royal son; but
Anchises’ port was nobler than all. My mind kindled
with a youth’s ardour to accost one so great, and exchange
the grasp of the hand. I made my approach, and eagerly
conducted him to the walls of Pheneus.[252] On leaving he
gave me a beauteous quiver with Lycian arrows, and a
scarf embroidered with gold, and two bridles which my 5
Pallas has now, all golden. So now I both plight you
here with the hand you ask, and soon as to-morrow’s light
shall restore to the earth its blessing, I will send you back
rejoicing in an armed succour, and reënforced with stores.
Meanwhile, since you are arrived here as my friends, join 10
in gladly solemnizing with us this our yearly celebration,
which it were sin to postpone, and accustom yourselves
thus early to the hospitalities of your new allies.”

This said, he bids set on again the viands and the cups,
erewhile removed, and himself places the warriors on a 15
seat of turf, welcoming Æneas in especial grace with the
heaped cushion of a shaggy lion’s hide, and bidding him
occupy a throne of maple wood. Then chosen youths
and the priest of the altar with emulous zeal bring in the
roasted carcases of bulls, pile up in baskets the gifts of 20
the corn-goddess prepared by art, and serve the wine-god
round. Æneas and the warriors of Troy with him
regale themselves on a bull’s long chine[o] and on sacrificial
entrails.

When hunger had been quenched and appetite allayed, 25


king Evander begins: “Think not that these solemnities
of ours, these ritual feastings, this altar so blest in divine
presence, have been riveted on us by idle superstition,
unknowing of the gods of old; no, guest of Troy, it is
deliverance from cruel dangers that makes us sacrifice 30
and pay again and again worship where worship is due.
First of all cast your eyes on this rock-hung crag: observe
how the masses of stone are flung here and there, how
desolate and exposed stands the mountain’s recess, and
how the rocks have left the trail of a giant downfall. 35
Here once was a cave, retiring in enormous depth, tenanted
by a terrible shape, Cacus, half man, half brute: the sun’s
rays could never pierce it; the ground was always steaming
with fresh carnage; fixed to its imperious portals
were hanging human countenances ghastly with hideous
gore. This monster’s father was Vulcan: Vulcan’s were
the murky fires that he disgorged from his mouth as he
towered along in enormous bulk. To us also at length 5
in our yearning need time brought the arrival of a divine
helper. For the mightiest of avengers, Alcides, triumphing
in the slaughter and the spoils of the triple Geryon,[253]
was in our land, and was driving by this road as a conqueror
those giant oxen, and the cattle were filling valley 10
and river-side. But Cacus, infatuated by fiendish frenzy,
not to leave aught of crime or craft undared or unessayed,
carries off from the stalls four bulls of goodly form, and
heifers no fewer of surpassing beauty. And these, that
they might leave no traces by their forward motion, he 15
dragged by the tail to his cave, haled them with reversed
footprints to tell the story, and so concealed them in the
dark rocky den. Thus the seeker found no traces to lead
him to the cavern. Meantime, when Amphitryon’s son
was at last removing from their stalls his feasted herds 20
and preparing to quit the country, the oxen gave a farewell
low, filling the whole woodland with their plainings,
and taking clamorous leave of the hills. One of the
heifers returned the sound, lowing from the depth of the
vast cavern, and thus baffled the hopes of her jealous 25
guardian. Now, if ever, Alcides’ wrath blazed up from
the black choler of his heart: he snatches up his weapons
and his club with all its weight of knots, and makes at
full speed for the skyey mountain’s height. Then first the
men of our country saw Cacus’ limbs tremble and his 30
eyes quail: away he flies swifter than the wind, and seeks
his den; fear has winged his feet. Scarce had he shut
himself in, and let down from its burst fastenings the
huge stone, suspended there by his father’s workmanship
in iron, and with that barrier fortified his straining doorway, 35
when lo! the hero of Tiryns[254] was there in the fury
of his soul: scanning every inlet he turns his face hither
and thither, gnashing with his teeth. Thrice in white
heat of wrath he surveys the whole mass of Aventine;
thrice he attempts in vain the stony portal; thrice,
staggering from the effort, he sits down in the hollow.
Before him stood a pointed crag with abrupt rocky sides
rising over the cave behind, high as the eye can reach, a 5
fitting home for the nests of unclean and hateful birds.
This, as sloping down it inclined towards the river on the
left, pushing it full on the right he upheaved and tore it
loose from its seat, then suddenly sent it down, with a
shock at which high heaven thunders, the banks start 10
apart, and the river runs back in terror. Then the cave
and the vast halls of Cacus were seen unroofed, and the
dark recesses lay open to their depths—even as if earth,
by some mighty force laid open to her depths, should
burst the doors of the mansions below, and expose the 15
realms of ghastly gloom which the gods hate, and from
above the vast abyss were to be seen, and the spectres
dazzled by the influx of day. So as Cacus stares surprised
by the sudden burst of light, pent by the walls of
his cave, and roars in strange and hideous sort, Alcides 20
from above showers down his darts, and calls every
weapon to his aid, and rains a tempest of boughs and
huge millstones. But he, seeing that no hope of flight
remains, vomits from his throat huge volumes of smoke,
marvellous to tell, and wraps the whole place in pitchy 25
darkness, blotting out all prospect from the eyes, and in
the depth of the cave masses a smothering night of blended
blackness and fire. The rage of Alcides brooked not this:
headlong he dashed through the flame, where the smoke
surges thickest and the vast cavern seethes with billows 30
of black vapour. Here while Cacus in the heart of the
gloom is vomiting his helpless fires he seizes him, twines
his limbs with his own, and in fierce embrace compresses
his strangled eyeballs and his throat now bloodless and
dry. At once the doors are burst and the black den laid 35
bare, and the plundered oxen, the spoil that his oath had
disclaimed, are exposed to light, and the hideous carcase
is dragged out by the heels. The gazers look unsatisfied
on those dreadful eyes, those grim features, the shaggy
breast of the half bestial monster, and the extinguished
furnace of his throat. Since then grateful acknowledgments
have been paid, and the men of younger time have
joyfully observed the day: foremost among them Potitius, 5
founder of the ceremony, and the Pinarian house, custodian
of the worship of Hercules. He himself set up in
the grove this altar, which shall ever be named by us
the greatest, and shall ever be the greatest in truth.
Come then, warriors, and in honour of worth so glorious 10
wreathe your locks with leaves, and present in your hands
brimming cups, and invoke our common deity, and pour
libations with gladness of heart.” As he ended, the white-green
poplar cast its Herculean shade over his locks and
hung down with a festoon of leaves, and the sacred goblet 15
charged his hand. At once all with glad hearts pour
libations on the board and make prayers to heaven.

Meantime evening is approaching nearer the slope of


heaven, and already the priests and their chief Potitius
were in procession, clad in skins in ritual sort, and bearing 20
fire in their hands. They renew the solemn feast,
and bring delicious offerings for a fresh repast, and pile
the altars with loaded chargers. Then come the Salii to
sing round about the blazing altars, their temples wreathed
with boughs of poplar, a company of youths and another 25
of old men; and these extol in song the glories and deeds
of Hercules: how in his cradle, by the pressure of his
young hand he strangled his stepmother’s monstrous
messengers, the two serpents; how in war that same
hand dashed to pieces mighty cities, Troy and Œchalia; 30
how he endured those thousand heavy labours, a slave to
king Eurystheus, by ungentle Juno’s fateful will. “Yes,
thou, unconquered hero, thou slayest the two-formed
children of the cloud, Hylæus and Pholus, thou slayest
the portent of Crete, and the enormous lion that dwelt 35
’neath Nemea’s rock. Thou never quailedst at aught in
bodily shape, no, nor at Typhœus himself, towering high,
weapons in hand; thy reason failed thee not when Lerna’s
serpent stood round thee with all her throng of heads.
Hail to thee, authentic offspring of Jove, fresh ornament
of the sky! come to us, come to these thine own rites
with favouring smile and auspicious gait.” Such things
their songs commemorate; and they crown all with Cacus’ 5
cave and the fiend himself, the fire panting from his lungs.
The entire grove echoes with their voices, and the hills
rebound.

The sacrifice over, the whole concourse returns to the


city. There walked the king, mossed over with years, 10
keeping at his side Æneas and his son as he moved along,
and lightening the way with various speech. Æneas admires,
and turns his quick glance from sight to sight:
each scene enthralls him; and with eager zest he inquires
and learns one by one the records of men of old. Then 15
spoke king Evander, the builder of Rome’s tower-crowned
hill: “These woodlands were first inhabited by native
Fauns and Nymphs, and by a race of men that sprung
from trunks of trees and hard oaken core; no rule of life,
no culture had they: they never learnt to yoke the ox, 20
nor to hive their stores, nor to husband what they got;
the boughs and the chase supplied their savage sustenance.
The first change came from Saturn, who arrived from
skyey Olympus, flying from the arms of Jove, a realmless
exile. He brought together the race, untamed as they 25
were and scattered over mountain heights, and gave them
laws, and chose for the country the name of Latium,
because he had found it a safe hiding-place. The golden
age of story was when he was king, so calm and peaceful
his rule over his people; till gradually there crept in a 30
race of worse grain and duller hue, and the frenzy of war,
and the greed of having. Then came the host of Ausonia
and the Sicanian tribes, and again and again Saturn’s
land changed its name; then came king after king, savage
Thybris with his giant bulk, from whom in after days we 35
Italians called the river Tiber: the authentic name of
ancient Albula was lost. Myself, an exile from my country,
while voyaging to the ends of the sea, all-powerful
Fortune and inevitable Destiny planted here; at my back
were the awful hests[255] of my mother, the nymph Carmentis,
and the divine sanction of Apollo.” Scarce had he
finished, when moving on he points out the altar and
the Carmental gate, as the Romans call it, their ancient 5
tribute to the nymph Carmentis, the soothsaying seer, who
first told of the future greatness of Æneas’ sons and of
the glories of Pallanteum. Next he points out a mighty
grove, which fiery Romulus made the Asylum of a later
day, and embowered by the chill dank rock, the Lupercal, 10
bearing after Arcadian wont the name of Lycæan Pan.
He shows, moreover, the forest of hallowed Argiletum,
and appeals to the spot, and recounts the death of Argus,
once his guest. Thence he leads the way to the Tarpeian
temple, even the Capitol, now gay with gold, then rough 15
with untrimmed brushwood. Even in that day the sacred
terrors of the spot awed the trembling rustics; even then
they shuddered at the forest and the rock. “This wood,”
he says, “this hill with the shaggy brow, is the home of
a god of whom we know not; my Arcadians believe that 20
they have seen there great Jove himself, oft and oft,
shaking with his right hand the shadowy Ægis[256] and calling
up the storm. Here, too, in these two towns, with
their ramparts overthrown, you see the relics and the
chronicles of bygone ages. This tower was built by father 25
Janus, that by Saturn; the one’s name Janiculum, the
other’s Saturnia.” So talking together they came nigh
the palace where Evander dwells in poverty, and saw
cattle all about lowing in the Roman forum and Carinæ’s
luxurious precinct. When they reached the gate, “This 30
door,” said the host, “Alcides in his triumph stooped to
enter; this mansion contained his presence. Nerve yourself,
my guest, to look down on riches, and make your
own soul, like his, such as a god would not disdain, and
take in no churlish sort the welcome of poverty.” He 35
said, and beneath the slope of his narrow roof ushered in
the great Æneas, and laid him to rest on a couch of leaves
and the skin of a Libyan bear.

Down comes the night, and flaps her sable wings over
the earth. But Venus, distracted, and not idly, with a
mother’s cares, disturbed by the menaces of the Laurentines
and the violence of the gathering storm, addresses
Vulcan, and in the nuptial privacy of their golden chamber 5
begins her speech, breathing in every tone the love
that gods feel: “In old days of war, while the Argive
kings were desolating Pergamus, their destined prey, and
ravaging the towers which were doomed to hostile fire,
no help for the sufferers, no arms of thy resourceful workmanship 10
did I ask; no, my dearest lord, I chose not to
task thee and thy efforts to no end, large as was my debt
to the sons of Priam, and many the tears that I shed for
Æneas’ cruel agony. Now, by Jove’s commands, he has
set his foot on Rutulian soil; so, with the past in my 15
mind, I appear as a suppliant, to ask of his power whom
I honour most, as a mother may, armour for my son.
Thee the daughter of Nereus, thee the spouse of Tithonus,
found accessible to tears. See but what nations are
mustering, what cities are closing the gate and pointing 20
the steel against me and the lives I love.” The speech
was ended, and the goddess is fondling her undecided
lord on all sides in the soft embrace of her snowy arms.
Suddenly he caught the wonted fire, the well-known heat
shot to his vitals and threaded his melting frame, even as 25
on a day when the fiery rent burst by the thunderclaps
runs with gleaming flash along the veil of cloud. His
spouse saw the triumph of her art and felt what beauty
can do. Then spoke the stern old god, subdued by everlasting
love: “Why fetch your excuses from so far? 30
whither, my queen, has fled your old affiance in me? had
you then been as anxious, even in those old days it had
been allowed to give arms to the Trojans; nor was the
almighty sire nor the destinies unwilling that Troy should
stand and Priam remain in life for ten years more. And 35
now, if war is your object and so your purpose holds, all
the care that it lies within my art to promise, what can
be wrought out of iron and molten electrum, as far as
fire can burn and wind blow—cease to show by entreaty
that you mistrust your power.” This said, he gave the
embrace she longed for, and falling on the bosom of his
spouse wooed the calm of slumber in every limb.

Then, soon as rest, first indulged, had driven sleep 5


away, when flying night had run half her course; just
when a woman, compelled to support life by spinning,
even by Pallas’ slender craft, wakes to light the fire that
slumbered in the embers, adding night to her day’s work,
and keeps her handmaids labouring long by the blaze, all 10
that she may preserve her husband’s bed unsullied, and
bring up his infant sons; even so the lord of fire, at an
hour not less slothful, rises from his couch of down to
the toils of the artisan. There rises an island hard by
the Sicanian coast and Æolian Lipari, towering with fiery 15
mountains; beneath it thunders a cavern, the den of
Ætna, blasted out by Cyclop forges; the sound of mighty
blows echoes on anvils: the smeltings of the Chalybes
hiss through its depths, and the fire pants from the jaws
of the furnace; it is the abode of Vulcan, and the land 20
bears Vulcan’s name. Hither, then, the lord of fire
descends from heaven’s height. There, in the enormous
den, the Cyclops were forging the iron, Brontes, and
Steropes, and Pyracmon, the naked giant. In their hands
was the rough cast of the thunder-bolt, one of those many 25
which the great Father showers down on earth from all
quarters of heaven—part was polished for use, part still
incomplete. Three spokes of frozen rain, three of watery
cloud had they put together, three of ruddy flame and
winged southern wind; and now they were blending with 30
what they had done the fearful flash, and the noise, and
the terror, and the fury of untiring fire. In another part
they were hurrying on for Mars the car and the flying
wheels, with which he rouses warriors to madness, aye,
and whole cities; and with emulous zeal were making 35
bright with golden serpent scales the terrible Ægis, the
armour of angry Pallas, snakes wreathed together, and
full on the breast of the goddess the Gorgon herself, her
neck severed and her eyes rolling. “Away with all this,”
cries the god; “take your unfinished tasks elsewhere, you
Cyclops of Ætna, and give your attention here. Arms
are wanted for a fiery warrior. Now is the call for power,
now for swiftness of hand, now for all that art can teach. 5
Turn delay into despatch.” No more he said; but they
with speed put their shoulder to the work, sharing it in
equal parts. Copper flows in streams and golden ore, and
steel, that knows how to wound, is molten in the huge
furnace. They set up in outline a mighty shield, itself 10
singly matched against all the Latian weapons, and tangle
together seven plates, circle and circle. Some with their
gasping bellows are taking in and giving out the wind;
others are dipping the hissing copper in the lake. The
cave groans under the anvil’s weight. They, one with 15
another, with all a giant’s strength, are lifting their arms
in measured cadence, and turning with their griping
tongs the ore on this side and on that.

While the father of Lemnos[257] makes this despatch on


the Æolian shores, Evander is roused from his lowly 20
dwelling by the genial light and the morning songs of
birds under the eaves. Up rises the old man, and draws
a tunic over his frame, and puts Tyrrhenian sandals
round his feet; next he fastens from below to side and
shoulder a sword from Tegea, flinging back over him a 25
panther’s hide that drooped from the left. Moreover, two
guardian dogs go before him from his palace door, and
attend their master’s steps. So he made his way to the
lodging of his guest, and sought Æneas’ privacy, their
discourse of yesterday and the gift then promised fresh 30
in his heroic soul. Æneas likewise was astir not less early.
This had his son Pallas, that had Achates walking by his
side. They meet, and join hand in hand, and sit them
down in the midst of the mansion, and at last enjoy the
privilege of mutual talk. The king begins as follows:— 35

“Mightiest leader of the Teucrians, whom while heaven


preserves I shall never own that Troy’s powers are vanquished
or her realm overturned, we ourselves have but
small means of martial aid to back our great name; on
this side we are bounded by the Tuscan river: on that
our Rutulian foe beleaguers us, and thunders in arms
around our walls. But I have a mighty nation, a host
with an imperial heritage, which I am ready to unite with 5
you—a gleam of safety revealed by unexpected chance.
It is at the summons of destiny that you bend your steps
thither. Not far hence, built of ancient stone, is the inhabited
city of Agylla, where of old the Lydian nation,
renowned in war, took its seat on Etruscan mountains. 10
This city, after long and prosperous years, was held by
king Mezentius, by stress of tyrant rule and the terror of
the sword. Why should I recount the despot’s dreadful
murders and all his savage crimes? may the gods preserve 15
them in mind, and bring them on his own head and
his family’s! Nay, he would even link together the dead
and the living, coupling hand with hand and face with
face—so inventive is the lust of torture—and in the
slime and poison of that sickening embrace would destroy
them thus by a lingering dissolution. At last, wearied 20
by oppression, his subjects in arms besiege the frantic
monster himself and his palace, slay his retainers, shower
firebrands on his roof. He, mid the carnage, escapes to
Rutulian territory, and shelters himself under Turnus’
friendly power. So all Etruria has risen in righteous 25
wrath; at once, at the sword’s point, they demand that
the king be surrendered to their vengeance. Of these
thousands, Æneas, I will make you general. For along
the seaboard’s length their ships are swarming and panting
for the fray, and calling on the trumpet to sound, 30
while an aged soothsayer is holding them back by his
fateful utterance: ‘Chosen warriors of Mæonian land, the
power and soul of an ancient nation, whom just resentment
launches against the foe and Mezentius inflames with
righteous fury, no Italian may take the reins of a race so 35
proud: choose foreigners to lead you.’ At this the Etruscan
army settled down on yonder plain, awed by the
heavenly warning. Tarchon[o] himself has sent me ambassadors
with the royal crown and sceptre, and given to
my hands the ensigns of power, bidding me join the camp,
and assume the Tyrrhene throne. But age, with its enfeebling
chill and the exhaustion of its long term of years,
grudges me the honour of command; my day of martial 5
prowess is past. Fain would I encourage my son to the
task, but that the blood of a Sabine mother blending with
mine makes his race half Italian. You, in years and in
race alike the object of Fate’s indulgence—you, the
chosen one of Heaven—assume the place that waits 10
you, gallant general of Teucrians and Italians both. Nay,
I will give you, too, Pallas here, the hope and solace of
my age; under your tutelage let him learn to endure
military service and the war-god’s strenuous labours; let
your actions be his pattern, and his young admiration be 15
centred on you. To him I will give two hundred Arcadian
horsemen, the flower of my chivalry, and Pallas in his
own name shall give you as many more.”

Scarce had his words been uttered—and the twain


were holding their eyes in downcast thought, Æneas 20
Anchises’ son and true Achates, brooding each with his
own sad heart on many a peril, had not Cythera’s goddess
sent a sign from the clear sky. For unforeseen, flashed
from the heaven, comes a glare and a peal, and all around
seemed crashing down at once, and the clang of the 25
Tyrrhene trumpet appeared to blare through ether. They
look up: a second and a third time cracks the enormous
sound. Armour enveloped in a cloud in a clear quarter
of the firmament is seen to flash redly in the sunlight and
to ring as clashed together. The rest were all amazement; 30
but the Trojan hero recognized the sound, and in
it the promise of his goddess mother. Then he cries:
“Nay, my host, nay, ask not in sooth what chance these
wonders portend; it is I that have a call from on high.
This was the sign that the goddess who gave me birth 35
foreshowed me that she would send, should the attack of
war come, while she would bring through the air armour
from Vulcan for my help. Alas! how vast the carnage
ready to burst on Laurentum’s wretched sons! what
vengeance, Turnus, shall be mine from thee! how many
a warrior’s shield and helm and stalwart frame shalt thou
toss beneath thy waters, father Tiber! Aye, clamour for
battle, and break your plighted word!” 5

Thus having said, he rises from his lofty seat, and first
of all quickens the altars where the Herculean fires were
smouldering, and with glad heart approaches the hearth-god
of yesterday, and the small household powers; duly
they sacrifice chosen sheep, Evander for his part and the 10
Trojan youth for theirs. Next he moves on to the ships
and revisits his crew: from whose number he chooses men
to follow him to the war, eminent in valour: the rest are
wafted down the stream and float lazily along with the
current at their back, to bring Ascanius news of his father 15
and his fortunes. Horses are given to the Teucrians who
are seeking the Tyrrhene territory, and one is led along,
reserved for Æneas; a tawny lion’s hide covers it wholly,
gleaming forth with talons of gold.

At once flies rumour, blazed through the little city, 20


that the horsemen are marching with speed to the gates
of the Tyrrhene king. In alarm the matrons redouble
their vows; fear treads on the heels of danger, and the
features of the war-god loom larger on the view. Then
Evander, clasping the hand of his departing son, hangs 25
about him with tears that never have their fill, and speaks
like this: “Ah! would but Jupiter bring back my bygone
years, and make me what I was when under Præneste’s
very walls I struck down the first rank and set a
conqueror’s torch to piles of shields, and with this my 30
hand sent down to Tartarus king Erulus, whom at his
birth his mother Feronia endowed with three lives—fearful
to tell—and a frame that could thrice bear arms:
thrice had he to be struck down in death: yet from him
on that day this hand took all those three lives, and 35
thrice stripped that armour—never should I, as now, be
torn, my son, from your loved embrace. Never would
Mezentius have laid dishonour on a neighbour’s crest,
dealt with his sword that repeated havoc, and bereaved
my city of so many of her sons. But you, great powers
above, and thou, Jupiter, mightiest ruler of the gods,
have pity, I implore you, on an Arcadian monarch, and
give ear to a father’s prayer; if your august will, if destiny 5
has in store for me the safe return of my Pallas, if life
will make me see him and meet him once more, then I
pray that I may live; there is no trial I cannot bear to
outlast. But if thou, dark Fortune, threatenest any unnamed
calamity, now, oh, now, be it granted me to snap 10
life’s ruthless thread, while care wears a double face,
while hope cannot spell the future, while you, darling boy,
my love and late delight, are still in my arms: nor let
my ears be pierced by tidings more terrible.” So was the
father heard to speak at their last parting; his servants 15
were seen carrying within doors their fallen lord.

And now the cavalry had passed the city’s open gates,
Æneas among the first and true Achates, and after them
the other Trojan nobles; Pallas himself the centre of the
column, conspicuous with gay scarf and figured armour; 20
even as the morning-star just bathed in the waves of the
ocean, Venus’ favourite above all the stellar fires, sets in
a moment on the sky his heavenly countenance, and
melts the darkness. There are the trembling matrons
standing on the walls, following with their eyes the cloud 25
of dust and the gleam of the brass-clad companies. They
in their armour are moving through the underwood, their
eye on the nearest path: hark! a shout mounts up, a
column is formed, and the four-foot beat of the hoof shakes
the crumbling plain. Near the cool stream of Cære stands 30
a vast grove, clothed by hereditary reverence with wide-spread
sanctity; on all sides it is shut in by the hollows
of hills, which encompass its dark pine-wood shades.
Rumour says that the old Pelasgians dedicated it to Silvanus,
god of the country and the cattle, a grove with a 35
holiday—the people who once in early times dwelt on
the Latian frontier. Not far from this Tarchon and the
Tyrrhenians were encamped in a sheltered place, and from
the height of the hill their whole army spread already to
the view, as they pitched at large over the plain. Hither
come father Æneas and the chosen company of warriors,
and refresh the weariness of themselves and their steeds.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookmass.com

You might also like