100% found this document useful (3 votes)
10 views

Java Programming Joyce Farrell - The complete ebook set is ready for download today

The document promotes the availability of various programming ebooks, particularly focusing on Java programming by Joyce Farrell and other related titles. It provides links to download these ebooks in multiple formats for easy access on various devices. Additionally, it includes copyright information and details about the content structure of the Java Programming textbook.

Uploaded by

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

Java Programming Joyce Farrell - The complete ebook set is ready for download today

The document promotes the availability of various programming ebooks, particularly focusing on Java programming by Joyce Farrell and other related titles. It provides links to download these ebooks in multiple formats for easy access on various devices. Additionally, it includes copyright information and details about the content structure of the Java Programming textbook.

Uploaded by

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

Explore the full ebook collection and download it now at textbookfull.

com

Java Programming Joyce Farrell

https://textbookfull.com/product/java-programming-joyce-
farrell/

OR CLICK HERE

DOWLOAD EBOOK

Browse and Get More Ebook Downloads Instantly at https://textbookfull.com


Click here to visit textbookfull.com and download textbook now
Your digital treasures (PDF, ePub, MOBI) await
Download instantly and pick your perfect format...

Read anywhere, anytime, on any device!

Java Programming Joyce Farrell

https://textbookfull.com/product/java-programming-joyce-farrell-2/

textbookfull.com

Practical Numerical C Programming 1st Edition Philip Joyce

https://textbookfull.com/product/practical-numerical-c-
programming-1st-edition-philip-joyce/

textbookfull.com

Programming in Java Sachin Malhotra

https://textbookfull.com/product/programming-in-java-sachin-malhotra/

textbookfull.com

Murach s Java Programming Joel Murach

https://textbookfull.com/product/murach-s-java-programming-joel-
murach/

textbookfull.com
Practical Numerical C Programming: Finance, Engineering,
and Physics Applications Philip Joyce

https://textbookfull.com/product/practical-numerical-c-programming-
finance-engineering-and-physics-applications-philip-joyce/

textbookfull.com

Learning Java An Introduction to Real World Programming


with Java Marc Loy

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

textbookfull.com

Learning Java Beginning programming with java for dummies


First Edition John Bach

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

textbookfull.com

Java Network Programming Fourth Edition Harold Elliotte

https://textbookfull.com/product/java-network-programming-fourth-
edition-harold-elliotte/

textbookfull.com

Computer Graphics Programming in OpenGL with Java Gordon

https://textbookfull.com/product/computer-graphics-programming-in-
opengl-with-java-gordon/

textbookfull.com
TM

JAVA PROGRAMMING

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
EIGHTH EDITION

TM

JAVA PROGRAMMING

JOYCE FARRELL

Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
This is an electronic version of the print textbook. Due to electronic rights restrictions, some third party content may be suppressed. Editorial
review has deemed that any suppressed content does not materially affect the overall learning experience. The publisher reserves the right to
remove content from this title at any time if subsequent rights restrictions require it. For valuable information on pricing, previous
editions, changes to current editions, and alternate formats, please visit www.cengage.com/highered to search by
ISBN#, author, title, or keyword for materials in your areas of interest.

Important Notice: Media content referenced within the product description or the product text may not be available in the eBook version.

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Java Programming, © 2016, 2014, 2012 Cengage Learning
Eighth Edition WCN: 02-200-203
Joyce Farrell
ALL RIGHTS RESERVED. No part of this work covered by the copyright
Product Director: herein may be reproduced, transmitted, stored, or used in any form or
Kathleen McMahon by any means graphic, electronic, or mechanical, including but not
Senior Content Developer: limited to photocopying, recording, scanning, digitizing, taping, Web
Alyssa Pratt distribution, information networks, or information storage and
retrieval systems, except as permitted under Section 107 or 108 of the
Development Editor: Dan Seiter
1976 United States Copyright Act, without the prior written
Marketing Manager: Eric LaScola permission of the publisher.
Manufacturing Planner:
Julio Esperas
For product information and technology assistance, contact us at
Art Director: Jack Pendleton Cengage Learning Customer & Sales Support, 1-800-354-9706
Production Management,
For permission to use material from this text or product,
Copyediting, Composition,
Proofreading, and Indexing: submit all requests online at www.cengage.com/permissions.
Integra Software Services Pvt. Ltd. Further permissions questions can be emailed to
Cover Photo: permissionrequest@cengage.com.
©Maram/Shutterstock.com

Library of Congress Control Number: 2014956152


ISBN: 978-1-285-85691-9
Cengage Learning
20 Channel Center Street
Boston, MA 02210
USA

Cengage Learning is a leading provider of customized learning


solutions with office locations around the globe, including Singapore,
the United Kingdom, Australia, Mexico, Brazil, and Japan. Locate your
local office at www.cengage.com/global.

Cengage Learning products are represented in Canada by Nelson


Education, Ltd.

All images © 2016 Cengage Learning®. All rights reserved.


To learn more about Cengage Learning Solutions, visit
www.cengage.com.
Purchase any of our products at your local college store
or at our preferred online store www.cengagebrain.com.

Printed in the U nited States of America


Print N umber: 01 Print Year: 2015

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Brief Contents
v

Preface . . . . . . . . . . . . . . . . . . . . . . xxi
CHAPTER 1 Creating Java Programs . . . . . . . . . . . . . . . . 1
CHAPTER 2 Using Data . . . . . . . . . . . . . . . . . . . . . 53
CHAPTER 3 Using Methods, Classes, and Objects . . . . . . . 119
CHAPTER 4 More Object Concepts . . . . . . . . . . . . . . . 183
CHAPTER 5 Making Decisions . . . . . . . . . . . . . . . . . 245
CHAPTER 6 Looping . . . . . . . . . . . . . . . . . . . . . 301
CHAPTER 7 Characters, Strings, and the StringBuilder . . . 353
CHAPTER 8 Arrays . . . . . . . . . . . . . . . . . . . . . . 393
CHAPTER 9 Advanced Array Concepts . . . . . . . . . . . . . 439
CHAPTER 10 Introduction to Inheritance . . . . . . . . . . . . . 491
CHAPTER 11 Advanced Inheritance Concepts . . . . . . . . . . 537
CHAPTER 12 Exception Handling . . . . . . . . . . . . . . . . 593
CHAPTER 13 File Input and Output . . . . . . . . . . . . . . . 665
CHAPTER 14 Introduction to Swing Components . . . . . . . . 729
CHAPTER 15 Advanced GUI Topics . . . . . . . . . . . . . . . 791
CHAPTER 16 Graphics . . . . . . . . . . . . . . . . . . . . . 861
APPENDIX A Working with the Java Platform . . . . . . . . . . . 919
APPENDIX B Data Representation . . . . . . . . . . . . . . . 925
APPENDIX C Formatting Output . . . . . . . . . . . . . . . . 931
APPENDIX D Generating Random Numbers . . . . . . . . . . . 941
APPENDIX E Javadoc . . . . . . . . . . . . . . . . . . . . . 949
Glossary . . . . . . . . . . . . . . . . . . . . 957
Index . . . . . . . . . . . . . . . . . . . . . . 979

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Contents
vi

Preface . . . . . . . . . . . . . . . . . . xxi

CHAPT ER 1 Creating Java Programs . . . . . . . . . . . 1


Learning Programming Terminology . . . . . . . . . . . . . . 2
Comparing Procedural and Object-Oriented
Programming Concepts . . . . . . . . . . . . . . . . . . 6
Procedural Programming . . . . . . . . . . . . . . . . . . 6
Object-Oriented Programming . . . . . . . . . . . . . . . . 6
Understanding Classes, Objects, and Encapsulation . . . . . . 7
Understanding Inheritance and Polymorphism . . . . . . . . . 9
Features of the Java Programming Language . . . . . . . . . . 11
Java Program Types . . . . . . . . . . . . . . . . . . . . 12
Analyzing a Java Application that Produces Console Output . . . . 13
Understanding the Statement that Produces the Output . . . . . 14
Understanding the First Class . . . . . . . . . . . . . . . 15
Indent Style . . . . . . . . . . . . . . . . . . . . . . . 18
Understanding the main() Method . . . . . . . . . . . . . 19
Saving a Java Class . . . . . . . . . . . . . . . . . . . . 21
Compiling a Java Class and Correcting Syntax Errors . . . . . . . 23
Compiling a Java Class . . . . . . . . . . . . . . . . . . . 23
Correcting Syntax Errors . . . . . . . . . . . . . . . . . . 24
Running a Java Application and Correcting Logic Errors . . . . . . 29
Running a Java Application . . . . . . . . . . . . . . . . . 29
Modifying a Compiled Java Class . . . . . . . . . . . . . . 30
Correcting Logic Errors . . . . . . . . . . . . . . . . . . 31
Adding Comments to a Java Class . . . . . . . . . . . . . . . 32
Creating a Java Application that Produces GUI Output . . . . . . 35
Finding Help . . . . . . . . . . . . . . . . . . . . . . . . 38
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . . 39
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . 41

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . 45
Review Questions . . . . . . . . . . . . . . . . . . . . . . 46
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . 48
Programming Exercises . . . . . . . . . . . . . . . . . . 48
Debugging Exercises . . . . . . . . . . . . . . . . . . . 50 vii
Game Zone . . . . . . . . . . . . . . . . . . . . . . . . 50
Case Problems . . . . . . . . . . . . . . . . . . . . . . 51

CHAPT ER 2 Using Data . . . . . . . . . . . . . . . . . 53


Declaring and Using Constants and Variables . . . . . . . . . . 54
Declaring Variables . . . . . . . . . . . . . . . . . . . . 55
Declaring Named Constants . . . . . . . . . . . . . . . . 56
The Scope of Variables and Constants . . . . . . . . . . . . 58
Concatenating Strings to Variables and Constants . . . . . . . 58
Pitfall: Forgetting that a Variable Holds
One Value at a Time . . . . . . . . . . . . . . . . . . . 60
Learning About Integer Data Types . . . . . . . . . . . . . . 64
Using the boolean Data Type . . . . . . . . . . . . . . . . . 70
Learning About Floating-Point Data Types . . . . . . . . . . . . 71
Using the char Data Type . . . . . . . . . . . . . . . . . . 72
Using the Scanner Class to Accept Keyboard Input . . . . . . . 78
Pitfall: Using nextLine() Following One of the
Other Scanner Input Methods . . . . . . . . . . . . . . 81
Using the JOptionPane Class to Accept GUI Input . . . . . . . 87
Using Input Dialog Boxes . . . . . . . . . . . . . . . . . . 87
Using Confirm Dialog Boxes . . . . . . . . . . . . . . . . 91
Performing Arithmetic . . . . . . . . . . . . . . . . . . . . 93
Associativity and Precedence . . . . . . . . . . . . . . . . 95
Writing Arithmetic Statements Efficiently . . . . . . . . . . . 96
Pitfall: Not Understanding Imprecision
in Floating-Point Numbers . . . . . . . . . . . . . . . . 96
Understanding Type Conversion . . . . . . . . . . . . . . . 101
Automatic Type Conversion . . . . . . . . . . . . . . . . 101
Explicit Type Conversions . . . . . . . . . . . . . . . . 102
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 106
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 107

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS

Chapter Summary . . . . . . . . . . . . . . . . . . . . . 111


Review Questions . . . . . . . . . . . . . . . . . . . . . 111
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 114
Programming Exercises . . . . . . . . . . . . . . . . . 114
viii Debugging Exercises . . . . . . . . . . . . . . . . . . 116
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 117
Case Problems . . . . . . . . . . . . . . . . . . . . . 118

CHAPT ER 3 Using Methods, Classes, and Objects . . . . 119


Understanding Method Calls and Placement . . . . . . . . . . 120
Understanding Method Construction . . . . . . . . . . . . . 123
Access Specifiers . . . . . . . . . . . . . . . . . . . . 123
Return Type . . . . . . . . . . . . . . . . . . . . . . 124
Method Name . . . . . . . . . . . . . . . . . . . . . 125
Parentheses . . . . . . . . . . . . . . . . . . . . . . 125
Adding Parameters to Methods . . . . . . . . . . . . . . . 129
Creating a Method that Receives a Single Parameter . . . . . 130
Creating a Method that Requires Multiple Parameters . . . . . 133
Creating Methods that Return Values . . . . . . . . . . . . . 136
Chaining Method Calls . . . . . . . . . . . . . . . . . . 138
Learning About Classes and Objects . . . . . . . . . . . . . 142
Creating a Class . . . . . . . . . . . . . . . . . . . . . 145
Creating Instance Methods in a Class . . . . . . . . . . . . 147
Organizing Classes . . . . . . . . . . . . . . . . . . . 150
Declaring Objects and Using their Methods . . . . . . . . . . 154
Understanding Data Hiding . . . . . . . . . . . . . . . . 156
An Introduction to Using Constructors . . . . . . . . . . . . 159
Understanding that Classes Are Data Types . . . . . . . . . . 163
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 168
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 168
Chapter Summary . . . . . . . . . . . . . . . . . . . . . 170
Review Questions . . . . . . . . . . . . . . . . . . . . . 171
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 174
Programming Exercises . . . . . . . . . . . . . . . . . 174
Debugging Exercises . . . . . . . . . . . . . . . . . . 177
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 178
Case Problems . . . . . . . . . . . . . . . . . . . . . 179

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPT ER 4 More Object Concepts . . . . . . . . . . . 183
Understanding Blocks and Scope . . . . . . . . . . . . . . 184
Overloading a Method . . . . . . . . . . . . . . . . . . . 192
Automatic Type Promotion in Method Calls . . . . . . . . . 194
Learning About Ambiguity . . . . . . . . . . . . . . . . . 199 ix

Creating and Calling Constructors with Parameters . . . . . . . 200


Overloading Constructors . . . . . . . . . . . . . . . . 201
Learning About the this Reference . . . . . . . . . . . . . 205
Using the this Reference to Make Overloaded Constructors
More Efficient . . . . . . . . . . . . . . . . . . . . . 209
Using static Fields . . . . . . . . . . . . . . . . . . . 213
Using Constant Fields . . . . . . . . . . . . . . . . . . 215
Using Automatically Imported, Prewritten Constants
and Methods . . . . . . . . . . . . . . . . . . . . . . 220
The Math Class . . . . . . . . . . . . . . . . . . . . 221
Importing Classes that Are Not Imported Automatically . . . . 223
Using the LocalDate Class . . . . . . . . . . . . . . . 224
Understanding Composition and Nested Classes . . . . . . . . 230
Composition . . . . . . . . . . . . . . . . . . . . . . 230
Nested Classes . . . . . . . . . . . . . . . . . . . . . 232
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 234
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 234
Chapter Summary . . . . . . . . . . . . . . . . . . . . . 236
Review Questions . . . . . . . . . . . . . . . . . . . . . 236
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 239
Programming Exercises . . . . . . . . . . . . . . . . . 239
Debugging Exercises . . . . . . . . . . . . . . . . . . 242
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 242
Case Problems . . . . . . . . . . . . . . . . . . . . . 243

CHAPT ER 5 Making Decisions . . . . . . . . . . . . . 245


Planning Decision-Making Logic . . . . . . . . . . . . . . . 246
The if and if…else Statements . . . . . . . . . . . . . . 248
The if Statement . . . . . . . . . . . . . . . . . . . . 248
Pitfall: Misplacing a Semicolon in an if Statement . . . . . . 249
Pitfall: Using the Assignment Operator Instead
of the Equivalency Operator . . . . . . . . . . . . . . 250

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS

Pitfall: Attempting to Compare Objects


Using the Relational Operators . . . . . . . . . . . . . 251
The if…else Statement . . . . . . . . . . . . . . . . . 251
Using Multiple Statements in if and if…else Clauses . . . . 254
x Nesting if and if…else Statements . . . . . . . . . . . . 260
Using Logical AND and OR Operators . . . . . . . . . . . . 263
The AND Operator . . . . . . . . . . . . . . . . . . . . 263
The OR Operator . . . . . . . . . . . . . . . . . . . . 265
Short-Circuit Evaluation . . . . . . . . . . . . . . . . . . 266
Making Accurate and Efficient Decisions . . . . . . . . . . . 269
Making Accurate Range Checks . . . . . . . . . . . . . . 270
Making Efficient Range Checks . . . . . . . . . . . . . . 272
Using && and || Appropriately . . . . . . . . . . . . . . 273
Using the switch Statement . . . . . . . . . . . . . . . . 274
Using the Conditional and NOT Operators . . . . . . . . . . . 280
Using the NOT Operator . . . . . . . . . . . . . . . . . 281
Understanding Operator Precedence . . . . . . . . . . . . . 282
Adding Decisions and Constructors
to Instance Methods . . . . . . . . . . . . . . . . . . . 285
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 289
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 289
Chapter Summary . . . . . . . . . . . . . . . . . . . . . 291
Review Questions . . . . . . . . . . . . . . . . . . . . . 291
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 294
Programming Exercises . . . . . . . . . . . . . . . . . 294
Debugging Exercises . . . . . . . . . . . . . . . . . . 297
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 297
Case Problems . . . . . . . . . . . . . . . . . . . . . 299

CHAPT ER 6 Looping . . . . . . . . . . . . . . . . . 301


Learning About the Loop Structure . . . . . . . . . . . . . . 302
Creating while Loops . . . . . . . . . . . . . . . . . . 303
Writing a Definite while Loop . . . . . . . . . . . . . . 303
Pitfall: Failing to Alter the Loop Control Variable
Within the Loop Body . . . . . . . . . . . . . . . . . 305
Pitfall: Unintentionally Creating a Loop with
an Empty Body . . . . . . . . . . . . . . . . . . . . 306

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Altering a Definite Loop’s Control Variable . . . . . . . . . . 307
Writing an Indefinite while Loop . . . . . . . . . . . . . 308
Validating Data . . . . . . . . . . . . . . . . . . . . . 310
Using Shortcut Arithmetic Operators . . . . . . . . . . . . . 314
Creating a for Loop . . . . . . . . . . . . . . . . . . . 319 xi
Unconventional for Loops . . . . . . . . . . . . . . . . 320
Learning How and When to Use a do…while Loop . . . . . . 325
Learning About Nested Loops . . . . . . . . . . . . . . . . 328
Improving Loop Performance . . . . . . . . . . . . . . . . 333
Avoiding Unnecessary Operations . . . . . . . . . . . . . 333
Considering the Order of Evaluation of Short-Circuit
Operators . . . . . . . . . . . . . . . . . . . . . . 334
Comparing to Zero . . . . . . . . . . . . . . . . . . . 334
Employing Loop Fusion . . . . . . . . . . . . . . . . . . 336
Using Prefix Incrementing Rather than Postfix
Incrementing . . . . . . . . . . . . . . . . . . . . . 337
A Final Note on Improving Loop Performance . . . . . . . . 338
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 342
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 342
Chapter Summary . . . . . . . . . . . . . . . . . . . . . 344
Review Questions . . . . . . . . . . . . . . . . . . . . . 344
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 347
Programming Exercises . . . . . . . . . . . . . . . . . 347
Debugging Exercises . . . . . . . . . . . . . . . . . . 350
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 350
Case Problems . . . . . . . . . . . . . . . . . . . . . 352

CHAPT ER 7 Characters, Strings, and


the StringBuilder . . . . . . . . . . . . 353
Understanding String Data Problems . . . . . . . . . . . . . 354
Using Character Class Methods . . . . . . . . . . . . . . 355
Declaring and Comparing String Objects . . . . . . . . . . 359
Comparing String Values . . . . . . . . . . . . . . . . 359
Empty and null Strings . . . . . . . . . . . . . . . . . 363
Using Other String Methods . . . . . . . . . . . . . . . 365
Converting String Objects to Numbers . . . . . . . . . . 369

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS

Learning About the StringBuilder


and StringBuffer Classes . . . . . . . . . . . . . . 374
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 381
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 382
xii Chapter Summary . . . . . . . . . . . . . . . . . . . . . 382
Review Questions . . . . . . . . . . . . . . . . . . . . . 383
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 385
Programming Exercises . . . . . . . . . . . . . . . . . 385
Debugging Exercises . . . . . . . . . . . . . . . . . . 388
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 388
Case Problems . . . . . . . . . . . . . . . . . . . . . 391

CHAPT ER 8 Arrays . . . . . . . . . . . . . . . . . . 393


Declaring Arrays . . . . . . . . . . . . . . . . . . . . . 394
Initializing an Array . . . . . . . . . . . . . . . . . . . . 399
Using Variable Subscripts with an Array . . . . . . . . . . . . 402
Using the Enhanced for Loop . . . . . . . . . . . . . . 403
Using Part of an Array . . . . . . . . . . . . . . . . . . 404
Declaring and Using Arrays of Objects . . . . . . . . . . . . 406
Using the Enhanced for Loop with Objects . . . . . . . . . 408
Manipulating Arrays of Strings . . . . . . . . . . . . . 408
Searching an Array and Using Parallel Arrays . . . . . . . . . 414
Using Parallel Arrays . . . . . . . . . . . . . . . . . . . 415
Searching an Array for a Range Match . . . . . . . . . . . 418
Passing Arrays to and Returning Arrays from Methods . . . . . 422
Returning an Array from a Method . . . . . . . . . . . . . 426
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 428
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 428
Chapter Summary . . . . . . . . . . . . . . . . . . . . . 429
Review Questions . . . . . . . . . . . . . . . . . . . . . 430
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 433
Programming Exercises . . . . . . . . . . . . . . . . . 433
Debugging Exercises . . . . . . . . . . . . . . . . . . 435
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 435
Case Problems . . . . . . . . . . . . . . . . . . . . . 438

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPT ER 9 Advanced Array Concepts . . . . . . . . . 439
Sorting Array Elements Using the Bubble Sort Algorithm . . . . 440
Using the Bubble Sort Algorithm . . . . . . . . . . . . . . 440
Improving Bubble Sort Efficiency . . . . . . . . . . . . . 442
Sorting Arrays of Objects . . . . . . . . . . . . . . . . . 443 xiii

Sorting Array Elements Using the Insertion Sort Algorithm . . . . 448


Using Two-Dimensional and Other Multidimensional Arrays . . . . 452
Passing a Two-Dimensional Array to a Method . . . . . . . . 454
Using the length Field with a Two-Dimensional Array . . . . 455
Understanding Ragged Arrays . . . . . . . . . . . . . . . 456
Using Other Multidimensional Arrays . . . . . . . . . . . . 456
Using the Arrays Class . . . . . . . . . . . . . . . . . . 459
Using the ArrayList Class . . . . . . . . . . . . . . . . 467
Creating Enumerations . . . . . . . . . . . . . . . . . . . 472
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 479
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 479
Chapter Summary . . . . . . . . . . . . . . . . . . . . . 480
Review Questions . . . . . . . . . . . . . . . . . . . . . 481
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 484
Programming Exercises . . . . . . . . . . . . . . . . . 484
Debugging Exercises . . . . . . . . . . . . . . . . . . 486
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 487
Case Problems . . . . . . . . . . . . . . . . . . . . . 490

CHAPT ER 10 Introduction to Inheritance . . . . . . . . . 491


Learning About the Concept of Inheritance . . . . . . . . . . 492
Diagramming Inheritance Using the UML . . . . . . . . . . 492
Inheritance Terminology . . . . . . . . . . . . . . . . . 495
Extending Classes . . . . . . . . . . . . . . . . . . . . . 496
Overriding Superclass Methods . . . . . . . . . . . . . . . 502
Using the @Override Tag . . . . . . . . . . . . . . . . 504
Calling Constructors During Inheritance . . . . . . . . . . . . 507
Using Superclass Constructors that
Require Arguments . . . . . . . . . . . . . . . . . . 508
Accessing Superclass Methods . . . . . . . . . . . . . . . 513
Comparing this and super . . . . . . . . . . . . . . . 515
Employing Information Hiding . . . . . . . . . . . . . . . . 516

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS

Methods You Cannot Override . . . . . . . . . . . . . . . . 518


A Subclass Cannot Override static Methods in
Its Superclass . . . . . . . . . . . . . . . . . . . . 518
A Subclass Cannot Override final Methods in
Its Superclass . . . . . . . . . . . . . . . . . . . . 522
xiv
A Subclass Cannot Override Methods
in a final Superclass . . . . . . . . . . . . . . . . 523
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 525
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 525
Chapter Summary . . . . . . . . . . . . . . . . . . . . . 526
Review Questions . . . . . . . . . . . . . . . . . . . . . 527
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 530
Programming Exercises . . . . . . . . . . . . . . . . . 530
Debugging Exercises . . . . . . . . . . . . . . . . . . 533
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 534
Case Problems . . . . . . . . . . . . . . . . . . . . . 535

CHAPT ER 11 Advanced Inheritance Concepts . . . . . . . 537


Creating and Using Abstract Classes . . . . . . . . . . . . . 538
Using Dynamic Method Binding . . . . . . . . . . . . . . . 547
Using a Superclass as a Method Parameter Type . . . . . . 549
Creating Arrays of Subclass Objects . . . . . . . . . . . . . 551
Using the Object Class and Its Methods . . . . . . . . . . . 554
Using the toString() Method . . . . . . . . . . . . . 556
Using the equals() Method . . . . . . . . . . . . . . . 559
Using Inheritance to Achieve Good Software Design . . . . . . 564
Creating and Using Interfaces . . . . . . . . . . . . . . . . 565
Creating Interfaces to Store Related Constants . . . . . . . 570
Creating and Using Packages . . . . . . . . . . . . . . . . 574
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 580
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 580
Chapter Summary . . . . . . . . . . . . . . . . . . . . . 581
Review Questions . . . . . . . . . . . . . . . . . . . . . 582
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 585
Programming Exercises . . . . . . . . . . . . . . . . . 585
Debugging Exercises . . . . . . . . . . . . . . . . . . 589
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 590
Case Problems . . . . . . . . . . . . . . . . . . . . . 590
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPT ER 12 Exception Handling . . . . . . . . . . . . 593
Learning About Exceptions . . . . . . . . . . . . . . . . . 594
Trying Code and Catching Exceptions . . . . . . . . . . . . 599
Using a try Block to Make Programs “Foolproof” . . . . . . 604
Declaring and Initializing Variables in try…catch Blocks . . . 606 xv

Throwing and Catching Multiple Exceptions . . . . . . . . . . 609


Using the finally Block . . . . . . . . . . . . . . . . . 615
Understanding the Advantages of Exception Handling . . . . . . 618
Specifying the Exceptions that a Method Can Throw . . . . . . 621
Tracing Exceptions Through the Call Stack . . . . . . . . . . 626
Creating Your Own Exception Classes . . . . . . . . . . . 630
Using Assertions . . . . . . . . . . . . . . . . . . . . . 634
Displaying the Virtual Keyboard . . . . . . . . . . . . . . . 650
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 653
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 654
Chapter Summary . . . . . . . . . . . . . . . . . . . . . 655
Review Questions . . . . . . . . . . . . . . . . . . . . . 656
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 659
Programming Exercises . . . . . . . . . . . . . . . . . 659
Debugging Exercises . . . . . . . . . . . . . . . . . . 662
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 662
Case Problems . . . . . . . . . . . . . . . . . . . . . 663

CHAPT ER 13 File Input and Output . . . . . . . . . . . . 665


Understanding Computer Files . . . . . . . . . . . . . . . 666
Using the Path and Files Classes . . . . . . . . . . . . . 667
Creating a Path . . . . . . . . . . . . . . . . . . . . . 668
Retrieving Information About a Path . . . . . . . . . . . . 669
Converting a Relative Path to an Absolute One . . . . . . . . 670
Checking File Accessibility . . . . . . . . . . . . . . . . 671
Deleting a Path . . . . . . . . . . . . . . . . . . . . . 673
Determining File Attributes . . . . . . . . . . . . . . . . 674
File Organization, Streams, and Buffers . . . . . . . . . . . . 678
Using Java’s IO Classes . . . . . . . . . . . . . . . . . . 680
Writing to a File . . . . . . . . . . . . . . . . . . . . . 683
Reading from a File . . . . . . . . . . . . . . . . . . . 685

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS

Creating and Using Sequential Data Files . . . . . . . . . . . 687


Learning About Random Access Files . . . . . . . . . . . . 693
Writing Records to a Random Access Data File . . . . . . . . 697
Reading Records from a Random Access Data File . . . . . . . 704
xvi Accessing a Random Access File Sequentially . . . . . . . . 704
Accessing a Random Access File Randomly . . . . . . . . . 705
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 719
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 719
Chapter Summary . . . . . . . . . . . . . . . . . . . . . 720
Review Questions . . . . . . . . . . . . . . . . . . . . . 721
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 724
Programming Exercises . . . . . . . . . . . . . . . . . 724
Debugging Exercises . . . . . . . . . . . . . . . . . . 726
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 727
Case Problems . . . . . . . . . . . . . . . . . . . . . 727

CHAPT ER 14 Introduction to Swing Components . . . . . 729


Understanding Swing Components . . . . . . . . . . . . . 730
Using the JFrame Class . . . . . . . . . . . . . . . . . . 731
Customizing a JFrame’s Appearance . . . . . . . . . . . 734
Using the JLabel Class . . . . . . . . . . . . . . . . . . 738
Changing a JLabel’s Font . . . . . . . . . . . . . . . . 740
Using a Layout Manager . . . . . . . . . . . . . . . . . . 743
Extending the JFrame Class . . . . . . . . . . . . . . . . 746
Adding JTextFields, JButtons, and Tool Tips to a
JFrame . . . . . . . . . . . . . . . . . . . . . . . . 748
Adding JTextFields . . . . . . . . . . . . . . . . . . 748
Adding JButtons . . . . . . . . . . . . . . . . . . . 750
Using Tool Tips . . . . . . . . . . . . . . . . . . . . . 752
Learning About Event-Driven Programming . . . . . . . . . . 755
Preparing Your Class to Accept Event Messages . . . . . . . 756
Telling Your Class to Expect Events to Happen . . . . . . . 757
Telling Your Class How to Respond to Events . . . . . . . . 757
An Event-Driven Program . . . . . . . . . . . . . . . . . 757
Using Multiple Event Sources . . . . . . . . . . . . . . . 759
Using the setEnabled() Method . . . . . . . . . . . . 761
Understanding Swing Event Listeners . . . . . . . . . . . . 764

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Using the JCheckBox, ButtonGroup, and JComboBox
Classes . . . . . . . . . . . . . . . . . . . . . . . . 767
The JCheckBox Class . . . . . . . . . . . . . . . . . 767
The ButtonGroup Class . . . . . . . . . . . . . . . . 771
The JComboBox Class . . . . . . . . . . . . . . . . . 772 xvii
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 780
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 780
Chapter Summary . . . . . . . . . . . . . . . . . . . . . 781
Review Questions . . . . . . . . . . . . . . . . . . . . . 783
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 785
Programming Exercises . . . . . . . . . . . . . . . . . 785
Debugging Exercises . . . . . . . . . . . . . . . . . . 787
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 787
Case Problems . . . . . . . . . . . . . . . . . . . . . 788

CHAPT ER 15 Advanced GUI Topics . . . . . . . . . . . 791


Understanding the Content Pane . . . . . . . . . . . . . . 792
Using Color . . . . . . . . . . . . . . . . . . . . . . . 795
Learning More About Layout Managers . . . . . . . . . . . . 797
Using BorderLayout . . . . . . . . . . . . . . . . . 798
Using FlowLayout . . . . . . . . . . . . . . . . . . . 800
Using GridLayout . . . . . . . . . . . . . . . . . . . 802
Using CardLayout . . . . . . . . . . . . . . . . . . . 803
Using Advanced Layout Managers . . . . . . . . . . . . . 805
Using the JPanel Class . . . . . . . . . . . . . . . . . . 813
Creating JScrollPanes . . . . . . . . . . . . . . . . . 821
A Closer Look at Events and Event Handling . . . . . . . . . . 824
An Event-Handling Example: KeyListener . . . . . . . . 827
Using AWTEvent Class Methods . . . . . . . . . . . . . . 830
Understanding x- and y-Coordinates . . . . . . . . . . . . 832
Handling Mouse Events . . . . . . . . . . . . . . . . . . 832
Using Menus . . . . . . . . . . . . . . . . . . . . . . . 837
Using Specialized Menu Items . . . . . . . . . . . . . . . 841
Using addSeparator() . . . . . . . . . . . . . . . . 843
Using setMnemonic() . . . . . . . . . . . . . . . . . 843
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 848
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 849

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS

Chapter Summary . . . . . . . . . . . . . . . . . . . . . 850


Review Questions . . . . . . . . . . . . . . . . . . . . . 851
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 853
Programming Exercises . . . . . . . . . . . . . . . . . 853
xviii Debugging Exercises . . . . . . . . . . . . . . . . . . 855
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 855
Case Problems . . . . . . . . . . . . . . . . . . . . . 859

CHAPT ER 16 Graphics . . . . . . . . . . . . . . . . . 861


Learning About Rendering Methods . . . . . . . . . . . . . 862
Drawing Strings . . . . . . . . . . . . . . . . . . . . . . 865
Repainting . . . . . . . . . . . . . . . . . . . . . . . 867
Setting a Font . . . . . . . . . . . . . . . . . . . . . 869
Using Color . . . . . . . . . . . . . . . . . . . . . . 870
Drawing Lines and Shapes . . . . . . . . . . . . . . . . . 874
Drawing Lines . . . . . . . . . . . . . . . . . . . . . 874
Drawing Unfilled and Filled Rectangles . . . . . . . . . . . 875
Drawing Clear Rectangles . . . . . . . . . . . . . . . . 875
Drawing Rounded Rectangles . . . . . . . . . . . . . . . 876
Drawing Shadowed Rectangles . . . . . . . . . . . . . . 878
Drawing Ovals . . . . . . . . . . . . . . . . . . . . . 879
Drawing Arcs . . . . . . . . . . . . . . . . . . . . . . 880
Creating Polygons . . . . . . . . . . . . . . . . . . . . 881
Copying an Area . . . . . . . . . . . . . . . . . . . . 883
Using the paint() Method with JFrames . . . . . . . . . 883
Learning More About Fonts . . . . . . . . . . . . . . . . . 891
Discovering Screen Statistics . . . . . . . . . . . . . . . 893
Discovering Font Statistics . . . . . . . . . . . . . . . . 894
Drawing with Java 2D Graphics . . . . . . . . . . . . . . . 898
Specifying the Rendering Attributes . . . . . . . . . . . . 899
Setting a Drawing Stroke . . . . . . . . . . . . . . . . . 901
Creating Objects to Draw . . . . . . . . . . . . . . . . . 902
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 910
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 911
Chapter Summary . . . . . . . . . . . . . . . . . . . . . 911
Review Questions . . . . . . . . . . . . . . . . . . . . . 912
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 915

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Programming Exercises . . . . . . . . . . . . . . . . . 915
Debugging Exercises . . . . . . . . . . . . . . . . . . 916
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 916
Case Problems . . . . . . . . . . . . . . . . . . . . . 918
xix
APPENDIX A Working with the Java Platform . . . . . . . 919
Learning about the Java SE Development Kit . . . . . . . . . 920
Configuring Windows to Use the JDK . . . . . . . . . . . . . 920
Finding the Command Prompt . . . . . . . . . . . . . . . 921
Command Prompt Anatomy . . . . . . . . . . . . . . . . 921
Changing Directories . . . . . . . . . . . . . . . . . . 921
Setting the class and classpath Variables . . . . . . . 922
Changing a File’s Name . . . . . . . . . . . . . . . . . 922
Compiling and Executing a Java Program . . . . . . . . . . . 923
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 923

APPENDIX B Data Representation . . . . . . . . . . . . 925


Understanding Numbering Systems . . . . . . . . . . . . . 926
Representing Numeric Values . . . . . . . . . . . . . . . . 927
Representing Character Values . . . . . . . . . . . . . . . 929
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 930

APPENDIX C Formatting Output . . . . . . . . . . . . . 931


Rounding Numbers . . . . . . . . . . . . . . . . . . . . 932
Using the printf() Method . . . . . . . . . . . . . . . . 933
Specifying a Number of Decimal Places to
Display with printf() . . . . . . . . . . . . . . . . 936
Specifying a Field Size with printf() . . . . . . . . . . . 937
Using the Optional Argument Index with printf() . . . . . 938
Using the DecimalFormat Class . . . . . . . . . . . . . 939
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 940

APPENDIX D Generating Random Numbers . . . . . . . . 941


Understanding Computer-Generated Random Numbers . . . . . 942
Using the Math.random() Method . . . . . . . . . . . . . 943
Using the Random Class . . . . . . . . . . . . . . . . . . 944
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 947

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS

APPENDIX E Javadoc . . . . . . . . . . . . . . . . . 949


The Javadoc Documentation Generator . . . . . . . . . . . . 950
Javadoc Comment Types . . . . . . . . . . . . . . . . . . 950
Generating Javadoc Documentation . . . . . . . . . . . . . 952
xx Specifying Visibility of Javadoc Documentation . . . . . . . . 955
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 956

Glossary . . . . . . . . . . . . . . . . . 957
Index . . . . . . . . . . . . . . . . . . . 979

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Preface
xxi

Java Programming, Eighth Edition, provides the beginning programmer with a guide to
developing applications using the Java programming language. Java is popular among
professional programmers because it can be used to build visually interesting graphical user
interface (GUI) and Web-based applications. Java also provides an excellent environment for
the beginning programmer—a student can quickly build useful programs while learning the
basics of structured and object-oriented programming techniques.
This textbook assumes that you have little or no programming experience. It provides a solid
background in good object-oriented programming techniques and introduces terminology
using clear, familiar language. The programming examples are business examples; they do not
assume a mathematical background beyond high-school business math. In addition, the
examples illustrate only one or two major points; they do not contain so many features that
you become lost following irrelevant and extraneous details. Complete, working programs
appear frequently in each chapter; these examples help students make the transition from the
theoretical to the practical. The code presented in each chapter can also be downloaded from
the publisher’s Web site, so students can easily run the programs and experiment with
changes to them.
The student using Java Programming, Eighth Edition, builds applications from the bottom up
rather than starting with existing objects. This facilitates a deeper understanding of the
concepts used in object-oriented programming and engenders appreciation for the existing
objects students use as their knowledge of the language advances. When students complete
this book, they will know how to modify and create simple Java programs, and they will have
the tools to create more complex examples. They also will have a fundamental knowledge of
object-oriented programming, which will serve them well in advanced Java courses or in
studying other object-oriented languages such as C++, C#, and Visual Basic.

Organization and Coverage


Java Programming, Eighth Edition, presents Java programming concepts, enforcing good
style, logical thinking, and the object-oriented paradigm. Objects are covered right from the
beginning, earlier than in many other textbooks. You create your first Java program in
Chapter 1. Chapters 2, 3, and 4 increase your understanding of how data, classes, objects,
and methods interact in an object-oriented environment.
Chapters 5 and 6 explore input and repetition structures, which are the backbone of
programming logic and essential to creating useful programs in any language. You learn the
special considerations of string and array manipulation in Chapters 7, 8, and 9.

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
PREFACE Features

Chapters 10, 11, and 12 thoroughly cover inheritance and exception handling. Inheritance is
the object-oriented concept that allows you to develop new objects quickly by adapting the
features of existing objects; exception handling is the object-oriented approach to handling
errors. Both are important concepts in object-oriented design. Chapter 13 provides
information on handling files so you can permanently store and retrieve program output.
xxii
Chapters 14, 15, and 16 introduce GUI Swing components (Java’s visually pleasing,
user-friendly widgets), their layout managers, and graphics.

Features
The following features are new for the Eighth Edition:
JAVA 8E: All programs have been tested using Java 8e, the newest edition of Java.
WINDOWS 8.1: All programs have been tested in Windows 8.1, and all screen shots have
been taken in this new environment.
DATE AND TIME CLASSES: This edition provides thorough coverage of the java.time
package, which is new in Java 8e.
ON-SCREEN KEYBOARD: This edition provides instructions for displaying and using an
on-screen keyboard with either a touch screen or a standard screen.
MODERNIZED GRAPHICS OUTPUT: The chapter on graphics (Chapter 16) has been
completely rewritten to focus on Swing component graphics production using the
paintComponent() method.

MODERNIZED OVERRIDING: The @Override tag is introduced.


EXPANDED COVERAGE OF THE EQUALS() METHOD: The book provides a thorough
explanation of the difference between overloading and overriding the equals() method.
PROGRAMMING EXERCISES: Each chapter contains several new programming exercises
not seen in previous editions. All exercises and their solutions from the previous edition
that were replaced in this edition are still available in the Instructor’s Resource Kit.
Additionally, Java Programming, Eighth Edition, includes the following features:
OBJECTIVES: Each chapter begins with a list of objectives so you know the topics that will
be presented in the chapter. In addition to providing a quick reference to topics covered,
this feature provides a useful study aid.
YOU DO IT: In each chapter, step-by-step exercises help students create multiple working
programs that emphasize the logic a programmer uses in choosing statements to include.
These sections provide a means for students to achieve success on their own—even those
in online or distance learning classes.
NOTES: These highlighted tips provide additional information—for example, an
alternative method of performing a procedure, another term for a concept, background
information on a technique, or a common error to avoid.

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Features

EMPHASIS ON STUDENT RESEARCH: The student frequently is directed to the Java Web
site to investigate classes and methods. Computer languages evolve, and programming
professionals must understand how to find the latest language improvements. This book
encourages independent research.
FIGURES: Each chapter contains many figures. Code figures are most frequently 25 lines
xxiii
or fewer, illustrating one concept at a time. Frequent screen shots show exactly how
program output appears. Callouts appear where needed to emphasize a point.
COLOR: The code figures in each chapter contain all Java keywords in blue. This helps
students identify keywords more easily, distinguishing them from programmer-selected
names.
FILES: More than 200 student files can be downloaded from the publisher’s Web site. Most
files contain the code presented in the figures in each chapter; students can run the code for
themselves, view the output, and make changes to the code to observe the effects. Other
files include debugging exercises that help students improve their programming skills.
TWO TRUTHS & A LIE: A short quiz reviews each chapter section, with answers provided.
This quiz contains three statements based on the preceding section of text—two
statements are true and one is false. Over the years, students have requested answers to
problems, but we have hesitated to distribute them in case instructors want to use
problems as assignments or test questions. These true–false quizzes provide students with
immediate feedback as they read, without “giving away” answers to the multiple-choice
questions and programming exercises.
DON’T DO IT: This section at the end of each chapter summarizes common mistakes and
pitfalls that plague new programmers while learning the current topic.
KEY TERMS: Each chapter includes a list of newly introduced vocabulary, shown in the
order of appearance in the text. The list of key terms provides a short review of the major
concepts in the chapter.
SUMMARIES: Following each chapter is a summary that recaps the programming
concepts and techniques covered in the chapter. This feature provides a concise means for
students to check their understanding of the main points in each chapter.
REVIEW QUESTIONS: Each chapter includes 20 multiple-choice questions that serve as a
review of chapter topics.
GAME ZONE: Each chapter provides one or more exercises in which students can create
interactive games using the programming techniques learned up to that point; 70 game
programs are suggested in the book. The games are fun to create and play; writing them
motivates students to master the necessary programming techniques. Students might
exchange completed game programs with each other, suggesting improvements and
discovering alternate ways to accomplish tasks.
CASES: Each chapter contains two running case problems. These cases represent projects
that continue to grow throughout a semester using concepts learned in each new chapter.
Two cases allow instructors to assign different cases in alternate semesters or to divide
students in a class into two case teams.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
PREFACE Instructor Resources

GLOSSARY: This edition contains an alphabetized list of all key terms identified in the
book, along with their definitions.
APPENDICES: This edition includes useful appendices on working with the Java platform,
data representation, formatting output, generating random numbers, and creating Javadoc
comments.
xxiv
QUALITY: Every program example, exercise, and game solution was tested by the author
and then tested again by a quality assurance team using Java Standard Edition (SE) 8, the
most recent version available.

CourseMate
The more you study, the better the results. Make the most of your study time by accessing
everything you need to succeed in one place. Read your textbook, take notes, review
flashcards, watch videos, and take practice quizzes online. CourseMate goes beyond the book
to deliver what you need! Learn more at www.cengage.com/coursemate.
The Java Programming CourseMate includes:
Debugging Exercises: Four error-filled programs accompany each chapter. By
debugging these programs, students can gain expertise in program logic in general and
the Java programming language in particular.
Video Lessons: Each chapter is accompanied by at least three video lessons that help to
explain important chapter concepts. These videos were created and narrated by the
author.
Interactive Study Aids: An interactive eBook, quizzes, flashcards, and more!
Instructors may add CourseMate to the textbook package, or students may purchase
CourseMate directly at www.CengageBrain.com.

Instructor Resources
The following teaching tools are available for download at our Instructor Companion Site.
Simply search for this text at sso.cengage.com. An instructor login is required.
Electronic Instructor’s Manual: The Instructor’s Manual that accompanies this
textbook contains additional instructional material to assist in class preparation,
including items such as Overviews, Chapter Objectives, Teaching Tips, Quick
Quizzes, Class Discussion Topics, Additional Projects, Additional Resources, and Key
Terms. A sample syllabus is also available. Additional exercises in the Instructor’s
Manual include:
Tough Questions: Two or more fairly difficult questions that an applicant
might encounter in a technical job interview accompany each chapter. These
questions are often open-ended; some involve coding and others might involve
research.

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Acknowledgments

Up for Discussion: A few thought-provoking questions concerning programming in


general or Java in particular supplement each chapter. The questions can be used to
start classroom or online discussions, or to develop and encourage research, writing,
and language skills.
Programming Exercises and Solutions: Each chapter is accompanied by several
xxv
programming exercises to supplement those offered in the text. Instructors can use
these exercises as additional or alternate assignments, or as the basis for lectures.
Test Bank: Cengage Learning Testing Powered by Cognero is a flexible, online system
that allows you to:
Author, edit, and manage test bank content from multiple Cengage Learning
solutions.
Create multiple test versions in an instant.
Deliver tests from your LMS, your classroom, or anywhere you want.
PowerPoint Presentations: This text provides PowerPoint slides to accompany each
chapter. Slides may be used to guide classroom presentations, to make available to
students for chapter review, or to print as classroom handouts. Files are provided for every
figure in the text. Instructors may use the files to customize PowerPoint slides, illustrate
quizzes, or create handouts.
Solutions: Solutions to “You Do It” exercises and all end-of-chapter exercises are
available. Annotated solutions are provided for some of the multiple-choice Review
Questions. For example, if students are likely to debate answer choices or not understand
the choice deemed to be the correct one, a rationale is provided.

Acknowledgments
I would like to thank all of the people who helped to make this book a reality, including Dan
Seiter, Development Editor; Alyssa Pratt, Senior Content Developer; Carmel Isaac, Content
Project Manager; and Chris Scriver and Danielle Shaw, quality assurance testers. I am lucky to
work with these professionals who are dedicated to producing high-quality instructional
materials.
I am also grateful to the reviewers who provided comments and encouragement during this
book’s development, including Bernice Cunningham, Wayne County Community College
District; Bev Eckel, Iowa Western Community College; John Russo, Wentworth Institute of
Technology; Leslie Spivey, Edison Community College; and Angeline Surber, Mesa
Community College.
Thanks, too, to my husband, Geoff, for his constant support and encouragement. Finally, this
book is dedicated to the newest Farrell, coming March 2015. As this book goes to production,
I don’t know your name or even your gender, but I do know that I love you.
Joyce Farrell

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Read This Before
xxvi
You Begin
The following information will help you as you prepare to use this textbook.

To the User of the Data Files


To complete the steps and projects in this book, you need data files that have been created
specifically for this book. Your instructor will provide the data files to you. You also can
obtain the files electronically from www.CengageBrain.com. Find the ISBN of your title on the
back cover of your book, then enter the ISBN in the search box at the top of the Cengage
Brain home page. You can find the data files on the product page that opens. Note that
you can use a computer in your school lab or your own computer to complete the exercises
in this book.

Using Your Own Computer


To use your own computer to complete the steps and exercises, you need the following:
Software: Java SE 8, available from www.oracle.com/technetwork/java/index.html. Although
almost all of the examples in this book will work with earlier versions of Java, this book was
created using Java 8. The book clearly points out the few cases when an example is based on
Java 7 and will not work with earlier versions of Java. You also need a text editor, such as
Notepad. A few exercises ask you to use a browser for research.
Hardware: If you are using Windows 8, the Java Web site suggests at least 128 MB of
memory and at least 181 MB of disk space. For other operating system requirements, see
http://java.com/en/download/help.

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Features
This text focuses on helping students become better programmers and understand
Java program development through a variety of key features. In addition to Chapter
Objectives, Summaries, and Key Terms, these useful features will help students
regardless of their learning styles. xxvii

YOU DO IT sections walk


students through program
development step by step.

NOTES provide
additional information—
for example, another
location in the book that
expands on a topic, or a
common error to watch
out for.

The author does an awesome


job: the examples, problems,
VIDEO LESSONS help
and material are very easy to
explain important chapter
understand!
concepts. Videos are part
—Bernice Cunningham, of the text’s enhanced
Wayne County Community
CourseMate site.
College District
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Exploring the Variety of Random
Documents with Different Content
altrettanto angusto, è, come in ogni altro ordine d'idee e di fatti fra
noi, così anche in questo, il dominio della leggenda. È già stato
osservato da parecchi, che la fioritura leggendaria, nelle età che
l'avrebber portata, scarseggiò in Italia; e ciò perchè, lo dirò con le
parole d'un critico tedesco, [97] «gl'Italiani avevano dietro a sè
un'epoca di grande cultura nell'antichità, le cui traccie non si erano
mai interamente perdute, essi non uscirono da un tempo di barbarie:
e quindi mancavano loro appunto.... tradizioni, la origine delle quali
risalisse a tempi oscuri e mitici». Siffatta condizione storica rivolse
verso fonti oltramontane il naturale appetito delle plebi al
maraviglioso, originando quella poesia romanzesca, la quale
solamente fra noi doveva inalzarsi a creazioni d'arte grandiose e
squisite; siffatta condizione storica, anche per altri o cicli tradizionali,
o temi individui di leggenda, fu causa che il remoto e l'esotico
apparissero quasi essenzial condizione perchè un soggetto
addivenisse leggendario. Ciò premesso, sembrerà piuttosto troppo
che poco, trovare circonfusa del nimbo della leggenda qualche figura
di donna fiorentina, e non dai due primi secoli del Comune, sibbene
da quelli della sua piena maturità.
Al secolo XIV sembra invero appartenere, se si considerano le
circostanze dei fatti, il soggetto della novella, fin dal XV popolare, e
tale conservatasi, specialmente nella sua forma metrica, fino a' di
nostri, di Ippolito e Lionora; [98] una delle tante versioni sotto le quali
si è perpetuata la leggenda dell'amor contrastato, da Piramo e Tisbe
agli amanti veronesi che Guglielmo Shakspeare e Vincenzio Bellini
hanno resi immortali. Ma nella leggenda fiorentina mancano e la
catastrofe tragica, conchiudendosi l'amore con lieta fine, e quasi la
forma stessa di leggenda, alla cui scarna semplicità subentrano le
forme tornite e conversevoli della novella. Ippolito de' Buondelmonti
ama la Lionora, o Dianora, de' Bardi, e n'è riamato, nonostante la
nimicizia che, sebben guelfe ambedue, divide le loro famiglie.
Disperato del proprio amore, il giovane si consuma e ne inferma; e
alla madre, che piangendo lo interroga, rivela la segreta cagione del
suo languire. L'amore materno spinge le donne, non avvisando altro
mezzo, a pregare una zia di Lionora, abbadessa nel convento di
Monticelli, che procuri di far trovare insieme i due amanti. Il che
avuto effetto e giuratasi fede di sposi, e stabilito come rivedersi con
maggior agio nella casa di Lionora, nel recarvisi Ippolito nottetempo,
è fermato dalla famiglia del Potestà. Egli, per salvare l'onore della
donna amata, si dà per ladro, e tale persiste a dichiararsi,
nonostante l'onta e la desolazione de' suoi; tacendo, a quel che
sembra, le donne, per ispavento che, risapendosi il vero, le due
famiglie e respettive consorterie non s'arrovescino l'una contro
l'altra, e prima vittima sia lo stesso Ippolito. Il giovine generoso,
condannato a ignominiosa morte, prega, per la salvezza almeno
dell'anima, «che vi piaccia, nel mandarmi alla giustizia, che io faccia
la via alla casa de' Bardi, acciò che gli possa domandare perdono
dell'odio che io come inimico ho portato loro»; ma in realtà,
«solamente per vedere una volta Lionora, prima che morisse». Gli è
concesso; e il lugubre corteggio, a suon di trombe e con lo
stendardo della giustizia alla testa, s'incammina: Lionora si fa alla
finestra, e gli sguardi de' due sposi s'incontrano: allora ella «come
furiosa discende la scala, a malgrado di tutte le donne di casa...., si
gitta fuori della porta, afferra per la briglia il cavallo del cavaliere del
Potestà, e grida: Finchè la vita mi starà nel corpo, tu non menerai
Ippolito alla morte, la quale lui non ha meritata.» E si gitta nelle
braccia del condannato. Il cavaliere non sa che si fare, la gente
romoreggia; la Signoria chiama a sè i due giovani: «Ippolito, legato
con la corda intorno al collo, e Lionora scapigliata e piangente,
seguendoli gran copia di popolo». La giovine si fa innanzi e domanda
ragione: «cioè, che voi mi rendiate il mio marito e sposo; altrimente
io appello a Dio ed al mondo, chiamando vendetta di tanta
ingiustizia, pregando Dio che con i suoi giusti occhi riguardi le vostre
inique sentenze e malvagi giudizi.» La Signoria, verificati i fatti,
chiama i padri de' due sposi: «li quali intendono la cosa per dritto
modo, e quivi in presenza de' Signori e del popolo, fermano il
parentado. E dove già duecento anni i Buondelmonti e i Bardi erano
stati inimici a morte, divennero amicissimi per il parentado che tutti
parevano d'uno sangue.» Vedete, o Signore gentili, che la leggenda
ha pur voluto dare la sua eroina a Firenze, e l'ha chiesta all'amore.
Amorosa pure è la leggenda della sepolta viva; che il suo rozzo
cantastorie quattrocentista riferisce al 1393. Ginevra degli Amieri
(Almieri, per corruzione popolare) è amata da Antonio dei Rondinelli,
ma dal padre sposata invece a Francesco degli Agolanti. Infermatasi
e tramortita è, in que' sospetti di morìa, creduta estinta, e la
seppelliscono da Santa Reparata. Ritorna ai sensi dentro la tomba, si
accorge dell'atroce suo caso, si raccomanda alla Vergine, e guidata
da un debole raggio di luna che trapela da uno spiraglio del sepolcro,
sale una scaletta, riesce a smuovere la pietra testè murata; ed ecco
la sua bianca figura, che rasente al Campanile, pel chiasso che poi
da lei si vorrebbe essere stato chiamato della Morte, incamminasi
alla casa del marito. Batte, ed è il marito stesso che si affaccia alla
finestra;

Chi è la? chi batte? — Io son la tua Ginevra.


Non m'odi tu?...

Il marito spaventato si fa il segno della croce, promette a quella


pover'anima errante orazioni e messe, e si ritira. Ginevra prosegue
alla casa paterna, in Mercato Vecchio. Bussa; e si affaccia la madre.

Aprite.... io son la vostra figlia. —


Va' in pace, anima benedetta.... —
E riserrò la finestra con fretta.

La sventurata

fece del cor ròcca, e tirò via


sempre piangendo, misera dolente:

e incontra la stessa accoglienza sotto la casa d'un suo zio. Allora si


ricorda del virtuoso amante; va alla sua casa: egli, pur credendola
spirito,

vuol veder se tal spirito gli nuoce:


scende, la raccoglie, chiama la madre e le altre donne di casa; la
confortano, l'assistono, la salvano. Ella vuol esser come morta al
marito che l'ha seppellita, e passare a seconde nozze con l'uomo pel
quale è rivissuta. Sostiene la sua causa dinanzi alla curia vescovile, e
la vince. L'Amore questa volta (bene è stato detto da chi illustrò
criticamente la leggenda) [99] l'Amore trionfa della Morte.
Ma, non che antica, antichissima sarebbe, e non di amore ma civile e
patriottica, una tradizione che risale nientemeno che a' tempi di
Totila; se però non si avesse piuttosto a tenere come una postuma
trovata del popolo. Il re barbaro, entrato per inganno in Firenze, si è
insediato nel centro della piccola città romana, nel palazzo del
Campidoglio. E volendo toglier di mezzo «li maggiori e più possenti
caporali della terra, li fa uno giorno richiedere a suo consiglio in
grande quantità. E come giugnevano in Campidoglio, passando ad
uno ad uno per uno valico di camera, gli faceva uccidere e
ammazzare, non sentendo l'uno dell'altro, e poi i corpi gittare negli
acquidocci». [100] Una trecca di mercato, che ha la sua botteguccia
accanto alla chiesa di San Pietro lì presso, entrata in sospetto,
avverte i cittadini «guardino bene, chè, come ha quella favola
d'Esopo, di quanti vi sono entrati, niuno se n'è veduto uscire». Il che
salva la vita a molti, e guadagna alla chiesa il nome di San Pier
Bonconsiglio; [101] ma non impedisce la distruzione della città per
mano del barbaro. La trecca e Totila poi si sono convertiti, e ciò a' dì
nostri, egli nel più aborrito fantasma di tirannide che sia rimasto
nella memoria del popolo fiorentino, il Duca d'Atene, ed essa nella
Cavolaia di Firenze; il Consiglio de' maggiorenti al Palazzo del
Campidoglio è addivenuto una veglia in maschera, con annessi
trabocchetti, nella residenza ducale; e la maggior campana del
Duomo, che d'inverno suona per l'ultima volta a sera inoltrata, e che
al buon tempo dei nostri nonni, quando si andava a letto presto per
alzarsi all'alba, faceva segno della cessazione delle veglie, è per la
plebe la campana della Cavolaia, e rammenta come per opera di
questa brava fiorentina la veglia micidiale del Duca finisse (nessun
istorico lo sapeva) con la sua ignominiosa cacciata. La Cavolaia di
Firenze, eroica moglie di Stenterello, divide oggi gli onori del teatro
popolare fiorentino con la Ginevra degli Almieri, della quale il
suddetto Stenterello è pur diventato non so se dissotterratore o che
altro. I suoi personaggi la plebe, una volta attiratili a sè, li avvolge
nelle spire di simpatie secolari, che si modificano, si trasformano, ma
morire del tutto, non muoiono mai.
E un altro amore tradizionale del popolo fiorentino è, pure in questa
età del Comune democratico, monna Tessa, la virtuosa fantesca di
Folco Portinari, che per consiglio e cominciamento principalmente di
lei si vorrebbe avesse fondato lo spedale di Santa Maria Nuova. [102]
Al popolo, che vede scolpita in marmo la imagine della caritatevole
donna sul limitare della grande casa, ospitale alle sue infermità e alle
sue miserie, vano sarebbe, se già non fosse una pedanteria crudele,
ammonirlo che la tradizione di monna Tessa, attestata sotto quel
marmo da una iscrizione del secolo XVII, è tanto dubitabile quanto
è, a ogni modo, evidente che cotesto mezzo rilievo, posteriore
almeno di un secolo ai tempi ne' quali ella sarebbe vissuta, e che
anticamente era collocato in una delle cappelle della chiesa, non è se
non la effigie o d'una benefattrice del luogo pio, o d'una delle oblate
addette ad esso. La tradizione poi, è molto probabile che avesse
occasione od appiglio da una iscrizion del Trecento, che scolpita in
rozzi caratteri gotici era sulla mensa dell'altare di quella medesima
cappella, e vi rimase almeno fino al 1647, e dove si raccomandava
l'anima d'una monna Tessa, moglie di Tura bastaio, la quale aveva
fatto costruire cotesto altare. [103] Oltre a ciò, riescirebbe malagevole
attribuire tanta potenza di effetti all'opera d'una femminella di
condizione servile, in tempi ne' quali tale condizione rimaneva
tuttavia molto prossima alla schiavitù; e schiave infatti le
chiamavano, e dall'Oriente ne condussero e tennero effettivamente
di tali. [104] Ma non è egli bello che il popolo lasci tutto questo, ed
altro ancora, alla nostra saccenteria, e si tenga per sè la imagine
cara della sua monna Tessa, fantesca poveretta; e di questa umile
donna che sarebbe uscita da lui, esperta del suo patire, passata nel
mondo fra i medesimi dolori, faccia egli a sè come l'angelo
consolatore di questi dolori, la confortatrice di quei patimenti? Certo,
io credo, non sarebbe mai una donna, per dottissima ch'ella fosse,
che aspirerebbe alla gloria di combattere l'autenticità di monna
Tessa. Più facile invece, che qualche rappresentatrice ingegnosa di
quel vero, il quale, fuor d'ogni contingenza di persone e di tempi, è
suggello perpetuo dell'essere umano, la ritragga nelle case dei
Portinari, tutta intesa alle faccende domestiche, abbellire di carità la
vita rassegnata e paziente, e disporre al soccorso dei poveri l'animo
del ricchissimo messer Folco e della moglie sua madonna Cilia de'
Caponsacchi: e pargoletta sulle ginocchia della povera serva, la loro
figliuola, la predestinata Beatrice.
Nel nome di Beatrice, le realtà della storia e le fantasie della
leggenda si congiungono con le idealità superbe a cui l'arte del bello
solleva la manifestazione del bello più eletta fra le create, la donna.
Ed io tocco i limiti che ho assegnati alla mia lettura. Non potrei
lasciarvi con nome di donna fiorentina che suoni più alto e più soave.
Da nessun'altra delle tombe della vecchia Firenze, alle quali abbiamo
richiesta la donna del nostro antico glorioso Comune, da nessuna la
donna fiorentina si solleva irraggiata di tanto splendore. E se, come
di Folco, [105] fosse a noi rimasta la tomba di Beatrice Portinari,
c'inchineremmo su quella forse con non minor reverenza che sul
sepolcro dell'esule amante in Ravenna.

VII.

Il più solenne monumento della democrazia fiorentina, Santa Maria


del Fiore, ha distese le braccia immense su molte di quelle tombe de'
secoli XIII e XIV, con altre insieme più antiche, fin da quando le basi
poste alle navate di Arnolfo e del Talenti, alla mole aerea di Giotto,
alle tribune su cui poi voltò la cupola il Brunelleschi, coprirono
l'antichissimo cimitero di Santa Reparata; esultanti, è da credere, le
anime de' sepolti, che le loro lapide sparissero e le ossa si
confondessero nelle fondamenta del tempio che a Dio inalzavano i
forti loro figliuoli. Un prezioso Obituario [106] ci ha conservato i nomi
dei sepolti e nell'antico cimitero e poi presso alla nuova chiesa: e su
quelle pergamene, ingiallite dai secoli, leggendo i nomi, nella pace
della morte congiunti, di Uberti e Buondelmonti, Lamberti e Adimari,
Cavalcanti (e vi è Guido il poeta) e Donati, Abati e Brunelleschi; dei
combattenti a Montaperti (e vi è Farinata magnanimo), e dei
giustiziati dai Guelfi Neri, e degli uccisi nelle zuffe cittadine; e poi
nomi di artisti, specialmente di addetti ai lavori della chiesa, e nomi
di loro donne, primo Arnolfo e madonna Perfetta la madre sua,
invidiabile madre per tale figliuolo e per tal sepoltura; [107] e poi
anche i nomi di tanti ignoti che pur fanno, anzi fanno perchè ignoti,
fantasticare la mente; siam tratti a ripensare e meditare tutta la
storia d'un'età che ci è sopravvissuta ne' mirabili monumenti del suo
pensiero e del cuor suo. E i nomi tanti di donne, molti de' quali al
nostro orecchio novissimi, per esempio (e taluni hanno del
longobardico) Bellantese, Bellamprato, Bellatedesca, Berricevuta,
Ringraziata, Dolcedonna, Altadonna, Donnetta, Buona, Moltobuona,
Dibene, Piubbella, Rimbellita, Belcolore, Macchiettina, Vezzosa,
Ruvinosa, Leggiera; altri di storica ricordanza, sia pe' loro casati, sia
per sè medesimi come le molte Tesse e Contesse, tributo onomastico
alla Matelda famosa; tutti cotesti nomi, quanta ignorata storia di
affetti non racchiudono, addormentati per sempre sotto quel sacro
terreno!

Mai non t'appresentò natura ed arte


piacer, quanto le belle membra, in ch'io
rinchiusa fui, ed or son terra sparte:

sono i versi [108] ne' quali Beatrice, pure in grembo al divino, si


ricorda di quando fu donna; e perciò da potersi inscrivere anche
sulla tomba di ignote.

Signore e Signori,
Fra pochi giorni, su quel terreno che la religione e l'arte hanno fatto
sacro all'Italia e al mondo civile, converrà da tutte le nazioni, alle
solenni fratellanze del pensiero, un devoto unanime pellegrinaggio.
Santa Maria del Fiore avrà avuto, dopo quasi seicent'anni dalla prima
pietra, il suo compimento. [109] Ma i nostri vecchi, lasciando questa
gloria al secolo che ora tramonta, non potettero prevedere, nè
avrebbero osato augurarsi, che la pietra ultima sarebbe stata
consegnata alle fondamenta dalla mano invitta di Colui che la patria
italiana doveva salutare suo unificatore, suo padre, suo re; [110] che
le feste dell'opera degnamente compiuta avrebbero inauguratori i
figli di lui, il Re la Regina i Principi d'Italia; dell'Italia finalmente
pacificata e concorde in tutte le sue terre, di nazione storica
rivendicatasi a nazione vivente, e del l'avvenire affidata dalla
coscienza del proprio diritto, e dal valore de' suoi soldati che
combattono e muoiono, senza contare i nemici, nel nome di lei e del
dovere. [111] Santa Maria del Fiore si apparecchia a dischiudere le
sue porte ai sovrani benedetti da Dio e dal popolo; e di sotto ai
novelli marmi del suo limitare fremeranno in quel giorno le ossa, e
per gli spazi delle arcate severe si affolleranno invisibili, intorno agli
Eletti della nazione, i magnanimi spiriti dell'antica Firenze. Il
difensore a viso aperto e tutelatore della patria, l'Uberti, «si ergerà
col petto e con la fronte» dalla tomba sua vera, [112] drappellando
nel cospetto del Re prode e leale la vecchia insegna del popolo
fiorentino, la Croce, oggi per virtù di Casa Savoia insegna di popolo e
di re. Ma a Guido Cavalcanti, nel suo riaffacciarsi dal sepolcro al
«dolce lume» del sole, «ferirà gli occhi» una visione gentile, come
quelle da lui già idoleggiate nella sdegnosa fantasia, e gli farà
ripetere li amorosi suoi versi, [113] per entro a' quali trepida,
interrogando, l'affetto:

Chi è questa che vien, ch'ogni uom la mira,


e fa di chiarità l'aer tremare?

E mille voci concordi risponderanno a quella sospirosa melodia


d'oltretomba, acclamando il nome dell'Augusta Donna, alle cui
speranze materne è raccomandata tanta e sì cara parte delle
speranze d'Italia.
NOTE

1. Matteo Villani, Cronica, VII, lxiv.

2. Giovanni Villani, Cronica, VII, lxviii.

3. Commentaires de messire Blaise de Montluc, mareschal de


France; Lyon, 1593; pag. 176.

4. La donna; Milano, Agnelli, 1868; a pag. 41.

5. Lettere di una Gentildonna fiorentina del secolo XV ai


figliuoli esuli pubblicate da Cesare Guasti; Firenze, Sansoni,
1877; a pag. xliv: «Che le lettere familiari sono la prima
fonte storica, è cosa nota; ma che nelle lettere delle donne
sia riposta la storia più intima di un popolo, vorrei averlo
mostrato io con questo volume». Lo stesso Guasti altrove
(Opere; Prato, Succ. Vestri; I, 596) osserva che «gli storici
fiorentini non sono molto larghi nel darci tipi di donna; ma
quelle che ci mettono dinanzi agli occhi, son proprio
degnissime di poema non che di storia.»

6. Giosuè Carducci, Alla regina d'Italia, XX novembre


MDCCCLXXVIII. A pag. 858-860 delle Poesie, Bologna,
Zanichelli, 1902. E in Confessioni e Battaglie, vol. IV delle
Opere (Bologna, Zanichelli, 1890), a pag. 333-357, eterno
Femminino regale. — Su l'uso e l'abuso, e la
interpretazione critica, della frase goethiana «das
Ewigweibliche» è da vedersi un bellissimo saggio di Michele
Kerbaker, L'eterno Femminino e l'epilogo celeste nel Fausto
di W. Goethe; Napoli, Pierro, 1903. «Per l'eterno
Femminino, cioè l'eterna femminilità, nel senso più ovvio,
chi non abbia riguardo al passo del Fausto, potrebbe
intendersi la potente ed arcana attrattiva che la donna
esercita sui sentimenti dell'uomo, mediante le speciali
prerogative congenite alla sua complessione fisica e
morale.» Ma dall'esame critico dell'epilogo celeste nel
Fausto il Kerbaker conchiude, che quella «femminilità
eterna» è «l'essenza stessa dell'indole femminile
riguardata come una legge costante e provvidenziale della
natura, in contrapposizione alla Mascolinità, e di cui la
Beata Vergine, Madre di Dio e Regina dei cieli, è un
simbolo». In quanto però la frase si presti, come s'è anche
troppo compiacentemente prestata, a interpretazione
astrattamente umana, non credo aver da pentirmi di
quella che, in relazione col mio tema, a me venne fatto di
darle: «idealità della donna, immanente nella storia».

7. Il canto XV, primo della trilogia fiorentina che il poeta


svolge intorno alla figura luminosa del suo trisavolo
Cacciaguida degli Elisei.

8.

Io mi volsi a Beatrice; e quella udio


pria ch'io parlassi, ed arrisemi un cenno
che fece crescer l'ali al voler mio.
Poi cominciai così....
XV, 70-73

Vincendo me col lume d'un sorriso


ella mi disse: Volgiti ed ascolta,
non pur ne' miei occhi è paradiso.
XVIII, 19-21

9. XV, 97-99 e segg.

10. Al geniale argomento appartengono: La donna genovese


del secolo XV, di Carlo Braggio; Genova, dal Giornale
ligustico, an. XII, 1885: — La donna nel Medio Evo a
Venezia, di B. Cecchetti, Venezia, dall'Archivio veneto, an.
XVI, 1886; e La storia di Venezia nella vita privata, di P. G.
Molmenti, Torino, Roux, 1885: — gli studî di Lodovico Frati
su La vita privata di Bologna dal secolo XIII al XVII;
Bologna, Zanichelli, mdcccc (dello stesso autore, anche La
donna italiana secondo i più recenti studi; Torino, Bocca,
1899): — una Conferenza di Guido Biagi, La vita privata dei
Fiorentini, fra quelle su La vita italiana nel Rinascimento;
Milano, Treves, 1893 — una di Lodovico Zdekauer, La vita
privata dei Senesi nel Dugento, e una di Eugenio Casanova,
La donna senese del Quattrocento nella vita privata, fra
quelle tenute dalla Commissione senese di Storia patria;
Siena, Lazzeri, 1895-98; — La storia di Pescia nella vita
privata, di Carlo Stiavelli; Firenze, Lumachi, 1903 — e nel
libro La donna italiana descritta da scrittrici italiane in una
serie di Conferenze tenute all'Esposizione Beatrice in
Firenze (Firenze, Civelli, 1890), quelle specialmente di
Maria Savi Lopez, La donna italiana nel Trecento; di Filippina
Rossi Gasti, Le donne nella Divina Commedia; di Alinda
Bonacci Brunamonti, Beatrice Portinari e l'idealità della
donna nei canti d'amore in Italia.

11. Parad. XV, 130-135; XVI, 34-39.

12. G. Villani, IV, x,

13. G. Villani, IV, ix.

14. G. Villani, V, xxxvii. «Ma se nel 1209 accadde la venuta di


Ottone in Firenze, il racconto è favola; chè.... diciannove
anni avanti, Gualdrada e Guido eran congiunti, e fin dal
1196 avevano figliolanza»: nota il Guasti, Opere, I, 71. Ciò
nonostante, il valor morale della gentile tradizione rimane
intatto.
15. Parad. XXXI, 38-39.

16. Parad. XVI, 145-147.

17. Parad. XVI, 25.

18. Parad. XV, 97-99.

19. Dino Compagni, I, ii.

20. Inf. XIII, 143-145.

21. «Allora lo romore fue grande; e fue messo in una bara, e


la moglie istava nella bara, e tenea il capo in grembo
fortemente piangendo; e per tutta Firenze in questo modo
il portarono». Cronica fiorentina compilata nel secolo XIII;
a pag. 234 del vol. II, P. Villari, I primi due secoli della
storia di Firenze; Firenze, Sansoni, 1894.

22. Manzoni, Adelchi, IV, i.

23. G. Villani, VI, lxix; Cronica malispiniana, clxiv.

24. Dino Compagni, II, xxix.

25. G. Villani, l. c.

26. Una di quelle «doti isfolgorate» di lire dugento, sappiamo


oggi essere stata la dote che la Gemma di messer Manetto
Donati portò a Dante Alighieri. L'illustratore di questo
Nuovo Documento concernente Gemma Donati (U. Dorini,
nel Bullettino della Società Dantesca italiana, N. S., IX
(1902), fasc. 7-8, pag. 181-184) ha potuto sopra altri
documenti fiorentini consimili rilevare che fra il 1276 e il
1316, sopra sessantasei doti, dieci vanno dalle 50 alle 200
lire o poco più, quattordici dalle 250 alle 500, quindici dalle
500 alle 700, tredici dalle 700 alle 1218, sei da fiorini 100
a 300, otto da fiorini 300 a 560. E si seguitò per questa
via. Guido Biagi ha pubblicato (per nozze Corazzini-
Brenzini; Firenze, 1899) Due corredi nuziali fiorentini
(1320-1493), da un libro di Ricordanze dei Minerbetti,
istituendo confronti su «ciò che fosse la vita fiorentina e
nei primi del Trecento, quando non era ancor fatta la roba,
e sul declinare di quel secolo decimoquinto, in cui la
squisitezza del gusto raffinava e ammolliva il costume».
Nel matrimonio del 1320 la dote è di 325 fiorini d'oro, e 35
fiorini d'oro le «dónora» ossia il corredo. Nel 1493, fiorini
800 la dote, fiorini 240 le «dónora stimate» con altre assai
non stimate, e poi per fiorini 340 di «cose consegnate e
date» agli sposi dai genitori dello sposo. Un altro
matrimonio, d'una Valori a uno Strozzi nel 1485, porta
(Scritta di parentado ec. pubblicata da G. O. Corazzini per
nozze Ciampolini-Magagnini; Firenze, 1894) fiorini duemila
di suggello fra dote e dónora, delle quali segue la lista.
Vorrei poter riferire quelle liste, preziosa testimonianza
anche alla storia del costume. Consimili documenti di
tempi ulteriori ha pubblicato Carlo Carnesecchi nel suo
opuscolo Donne e lusso a Firenze nel secolo XVI. Cosimo I
e la sua legge suntuaria del 1562; Firenze, Pellas, 1902.

27. Parad. XV, 112-120.

28. Vedi appresso, nel mio Studio su Beatrice.

29. Ottimo, III, 355 (Parad. XV, 103-105).

30. Vedi il mio libro Dino Compagni e la sua Cronica; Firenze,


Succ. Le Monnier, 1880-87; I, 1113.

31. Vedi il citato mio studio su Beatrice; ed ivi anche ciò che
concerne il matrimonio stesso dell'Alighieri con la Donati.

32. Le antiche rime volgari secondo la lezione del codice


vaticano 3793, pubblicate per cura di A. D'Ancona e D.
Comparetti; Bologna, 1875-1888; n.i dx, dxi, cmx.
L'autenticità e realtà della «compiuta donzella di Firenze»,
che io, fin da quando (1887) scrivevo queste pagine,
propendevo a sostenere contro gli assalti della critica
dubitatrice, mi paiono ora validamente confermate nel
bello Studio di Liborio Azzolina, La Compiuta Donzella di
Firenze; Palermo, 1902; dove e quelle e altre
(d'argomento amoroso) rime del Codice Vaticano ad essa
comecchessia attinenti, sono esaminate con finezza di
osservazione critica e con appropriata dottrina di storia e
d'arte.

33. Cronica fiorentina cit. in nota 21 a pag. 235-236.

34. Parad. III, 108.

35. Commento alla D. C. d'Anonimo fiorentino III, 51.

36. Dino Compagni, III, x.

37. Parad. XVI, 112-114.

38. Pro coena maledictarum dominarum de Tosingis, riferisce il


canonico P. N. Cianfogni (Memorie istoriche della basilica di
S. Lorenzo; Firenze, 1804) essere intitolata, nel libro di
Entrata e Uscita del Capitolo di San Lorenzo, sotto l'1
Maggio 1306, la spesa di quella imbandigione,
«consistente in due capretti, due ventri di vitella, cinque
paia di pollastri e altrettante di piccioni, un ventre di
castrato, tre caci, otto dozzine e mezzo di pani, vino,
frutte, pomaranci, treggea, spezie e lardo, colla spesa, in
tutto, di otto lire, quattro soldi e sei danari» (vedi, qui
subito appresso, il conteggio, di poco superiore, del
Borghini). E poi lo stesso canonico Cianfogni soggiunge:
«Chi fossero queste donne maledette, le quali dalla
quantità delle vivande si vede che erano di un numero non
indifferente, io non ho potuto rinvenirlo; siccome neppure
si sa se questo fosse un obbligo del Capitolo, perocchè
non vi sono libri anteriori, e dal 1307 fino al 1343
mancano tutti; e in quelli che seguono, di questa cena non
se ne vede più fatta menzione». Io non sarei d'avviso che
la cena fosse imbandita a donne, cioè non crederei che le
«maledette» fossero le commensali e consumatrici:
parecchia gente, osserva pure il Cianfogni, se si guarda la
lista delle pietanze. Direi piuttosto che le «maledette»
dessero, come di certo l'occasione e l'origine, così anche il
nome alla cena; ma che questa poi fosse ammannita a
tutt'altre persone che donne e Tosinghi, ma o a poveri o a
religiosi, o altro che di simile: e ciò per un lascito nel cui
titolo le «maledette donne dei Tosinghi» rimangono per
noi un mistero. Mi capacita poco, che una casa come i
Tosinghi, così fiera e burbanzosa e potente, volesse
mandar le sue donne a quella periodica impinzatura di
calendimaggio, accompagnata poi da quella amorevole
denominazione. Peccato non usino più i romanzi storici,
per ricamarvi un po' sopra! Il gran maestro di antichità
fiorentine, Vincenzio Borghini (Autografi magliabechiani, X,
98, c. 57), pare vegga nella denominazione di
«maledette» non altro che una imprecazione de' canonici
all'indirizzo delle Tosinghe, seccati di dover tutti gli anni
per cagion d'esse metter mano alla borsa e registrar quella
spesa; imprecazione raccolta dal camarlingo, e
sopravvissutaci in cotesta come motteggevole intestatura
della partita: «Pro coena maledictarum dominarum de
Tosinghis. Erano parenti del Vescovo, e dovevano farsi fare
questa cena per piacevolezza: ma questi buon preti non ci
avevano pazienza, chè spesono in tutto lire 8. 9. 10, che
erano più di 3 lire delle nostre». Ma questa volta io non
consentirei al maestro. In quel «maledette» della cena
laurenziana commemorativa, mi par di sentire alcun che di
consono al grido misterioso che aleggia fra gli alberi del
sesto girone del Purgatorio dantesco: «Ricòrdivi, dicea, de'
maledetti....»
È
È stato popolare in Firenze, fino ai dì nostri il «lunedì
dell'unte», cioè delle tessitore, che era il penultimo, o
l'antepenultimo, lunedì del carnevale, giorno di scialo per
coteste donne dei nostri camaldoli, con tavole
apparecchiate anche su la strada: e doveva essere
antichissimo, quanto forse la cena (tutt'altra cosa) delle
«maledette».

39. Parad. XV, 127-129.

40. Protocollo di ser Uguccione di messer Ranieri Bondoni, B.


2126 dell'Archivio antecosimiano dei Contratti, nell'Archivio
fiorentino di Stato. A c. 130 t., 11 aprile 1304.

41. G. M. Brocchi, Le vite de' Santi e Beati fiorentini; Firenze,


1742-61; II, 339 seg. Vedi anche L. Santoni, Diario sacro
ecc. con l'Elenco di tutti i Santi, Beati e Venerabili che sono
nati domiciliati e morti in Toscana; Firenze, 1853; pag.
105. Piccarda, o col suo nome francescano suor Costanza,
Donati è sotto il 17 ottobre. (La data de' «17 ottobre, a
pag. 105» dell'Elenco di L. Santoni, è erronea. La vera è
«17 dicembre, a pag. 128» del medesimo Elenco; dove
anche altre cose, oltre quel doppione, sarebbero da
raddirizzare.)

42. Questo concetto fermai in una iscrizione pel Centenario di


Santa Margherita da Cortona (1897), che qui ripubblico
siccome non aliena dal carattere del presente mio libro:
Coronazione di virtù miti in secolo feroce
fu l'aureola della santità
sulla fronte della donna medievale.
Ma di eroica redenzione dalle abiezioni del peccato
voluta e combattuta e vinta,
ma di rivendicazione dello spirito immortale alla sua
libertà,
è confortevole simbolo anche nei mutati tempi
la santità tua, o Margherita,
o bella penitente,
o consigliatrice di pace ai potenti del mondo,
o iniziatrice di carità dagli abbienti ai poveretti;
Maddalena dell'età fosca e luminosa,
a cui Francesco ebbe
nelle stigmate dell'amore universale
rinnovato il dolce crocifisso Gesù.

43. Leggenda della beata Umiliana de' Cerchi; Firenze 1827; a


pag. 23, 34, 94, 50.

44. N. Tommaseo, Lo spirito, il cuore, la parola di Caterina da


Siena; premesso alle Lettere di lei (Firenze, Barbèra,
1860), a pag. clxxxvi.

45. G. Villani, VI, xxxiii: Gino Capponi, Storia della Repubblica di


Firenze; Firenze, Barbèra, 1875; I, 29-30.

46. G. Villani, VI, lxxix.

47. G. Villani, VI, lxii.

48. Il sepolcro in chiesa nella cappella di San Matteo. La pietra


(con lo stemma, e figurazioni guelfe, e la scritta
Sepulchrum filiorum de Marignolle. A. D. MCCLVIIII.
Restauratum A. D. MCCCCCV), che serviva di dossale
all'altare (Richa, Chiese fiorentine, V, 73, 33-34), fu
trasferita nel chiostro della Canonica, a man destra appena
entrati, nel 1739 per cura degli Ubaldini novelli patroni
della cappella. E così deve correggersi un accenno del
Capponi, l. c.

49. Inf. X, 92.

50. Dramma ritratto con veracità d'arte possente, in una lirica


del Tommaseo: a pag. 374-377 delle Poesie, Firenze, Succ.
Le Monnier, 1872 e 1902.

51. Vedi nel mio libro Dino Compagni e la sua Cronica, II, 519.

52. Vedi nel citato mio libro, II, 457-58.

53. Statuti fiorentini, III, clxxix: «Di non contraere parentado


co' conti Guidi e altri (conti Alberti, Ubertini, Pazzi di
Valdarno, Ubaldini), e di pagare la gabella pe' contraenti
matrimonio con alcuno Signore confinante col territorio
fiorentino.... E coloro e' quali di tale matrimonio
nascesseno, come bastardi a successione d'alcuno venire
non possano, ma da la successione s'intendano per essa
ragione schiusi, in quel modo ch'e' bastardi sono
eschiusi.» Disposizioni che dai più antichi Statuti si
veggono perdurare fino in quelli del 1415: ed erano spada
sempre tagliente, sospesa sul capo delle famiglie ribelli;
come ne danno pietoso esempio due gentildonne del
primo Quattrocento: una Bardi negli Alberti, e una Alberti
nei Corsini (vedi C. Carnesecchi, Madonna Caterina degli
Alberti Corsini, Notizie inedite; nell'Archivio Storico
Italiano, 1892, X, 116-122).

54. Dino Compagni, II, xxi; G. Villani, VIII, xxxv.

55. Dino Compagni, III, vii.

56. Dino Compagni, I, xxii: «In tal sera, che è il rinnovamento


della primavera, le donne usano molto per le vicinanze i
balli.» G. Villani, VII, cxxxii; VIII, xxxix: «Ogni anno per
calen di maggio, si faceano le brigate e compagnie di
gentili giovani....; e simile di donne e pulcelle, ec.» G.
Boccaccio, Vita di Dante, iii: «Nel tempo nel quale la
dolcezza del cielo riveste de' suoi ornamenti la terra, e
tutta per la varietà de' fiori mescolati tra le verdi frondi la
fa ridente, era usanza nella nostra città e degli uomini e
delle donne, nelle loro contrade ciascuno, e in distinte
compagnie, festeggiare.»

57. «Nell'anno 1283, del mese di giugno per la festa di San


Giovanni, essendo la città di Firenze in felice e buono stato
di riposo, e tranquillo e pacifico stato, e utile per li
mercatanti e artefici, e massimamente per gli Guelfi che
signoreggiavano la terra, si fece nella contrada di Santa
Felicita oltrarno, onde furono capo e cominciatori quegli
della casa de' Rossi con loro vicinanze, una compagnia e
brigata di mille uomini o più, tutti vestiti di robe bianche,
con uno Signore detto dell'Amore. Per la qual brigata non
s'intendea se non in giuochi e in sollazzi, e in balli di
donne e di cavalieri e d'altri, popolani, andando per la
terra con trombe e diversi stormenti in gioia e allegrezza,
e stando in conviti insieme in desinari e in cene. La quale
corte durò presso a due mesi, e fu la più nobile e
nominata che mai fosse nella città di Firenze o in Toscana;
alla quale vennero, di diverse parti e paesi, molti gentili
uomini di corte e giocolari, e tutti furono ricevuti e
provveduti onorevolmente.» G. Villani, VII, lxxxix.

58. Purg. XXIV, 50, 57.

59. Rime, ediz. Fraticelli, pag. 74.

60. Purg, XX, 70-75.

61. Dino Compagni, II, xix segg.

62. Neri Strinati, Cronichetta; Firenze, 1753, pag. 115-116.

63. Istorie pistoiesi, pag. 1.

64. Franco Sacchetti, Nov. clxxix.


65. A pag. 49-51 di Dante ne' tempi di Dante, Ritratti e Studi;
Bologna, Zanichelli, 1888. I particolari dalla Cronica di
Marchionne Stefani, ccxvii.

66. Vedi qui appresso, La donna fiorentina nel rinascimento


ecc.

67. Curioso inedito episodio di storia fiorentina, che io ebbi


occasione di raccontare nel cit. mio libro Dino Compagni e
la sua Cronica; I, 1086-88.

68. Purg. XIX, 85-90.

69. Monna Giovanna di Buonaccorso del Velluto, donna della


Penitenza delle Vestite di Santa Croce, manda (14 maggio
1298) Michele del fu Orlando, servigiale delle monache di
Monticelli, a stare per sei mesi nell'esercito del venerabile
padre messer Bonifazio sommo Pontefice e di Santa
Chiesa contro i perfidi (intendi, miscredenti) Colonnesi e
qualsisiano altri inimici e rubelli di detta Chiesa e
Pontefice; con riportare a suo tempo pubblico instrumento,
o lettere sigillate papali, del servizio fatto e relativa
indulgenza, lucrata per tal mezzo da essa monna
Giovanna. Vedi il mio Commento alla Cronica di Dino, II, ii,
6.

70. L'episodio monastico di suor Margherita, dico quello della


sfuriata profetica contro papa Bonifazio, è consegnato a
un atto dei 23 maggio 1299, pubblicato da D. Moreni
(Contorni di Firenze, VI, 77 seg.) che è fra le pergamene
dell'Archivio fiorentino di Stato, insieme con altri (del 25
maggio e 23 luglio successivi) pur concernenti il bizzarro
episodio. Dei contrasti poi, diciam pure politici, per la sua
elezione a badessa nel 1291, ci dà i particolari un altro
atto dei 5 gennaio di cotesto medesimo anno, e che è
altresì, col corredo di altri, fra le pergamene dell'Archivio
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like