100% found this document useful (4 votes)
81 views84 pages

Core Java for the Impatient 3rd Edition Cay Horstmann download

The document provides links to various eBooks, including 'Core Java for the Impatient' and 'Modern JavaScript for the Impatient' by Cay S. Horstmann, along with other titles. It also includes information about the eBook format, device compatibility, and features for optimizing the reading experience. Additionally, it emphasizes Pearson's commitment to diversity, equity, and inclusion in educational content.

Uploaded by

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

Core Java for the Impatient 3rd Edition Cay Horstmann download

The document provides links to various eBooks, including 'Core Java for the Impatient' and 'Modern JavaScript for the Impatient' by Cay S. Horstmann, along with other titles. It also includes information about the eBook format, device compatibility, and features for optimizing the reading experience. Additionally, it emphasizes Pearson's commitment to diversity, equity, and inclusion in educational content.

Uploaded by

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

Core Java for the Impatient 3rd Edition Cay

Horstmann install download

https://ebookmeta.com/product/core-java-for-the-impatient-3rd-
edition-cay-horstmann/

Download more ebook from https://ebookmeta.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookmeta.com
to discover even more!

Modern JavaScript for the Impatient 1st Edition Cay S.


Horstmann

https://ebookmeta.com/product/modern-javascript-for-the-
impatient-1st-edition-cay-s-horstmann/

Core Java Volume II Advanced Features Cay S Horstmann

https://ebookmeta.com/product/core-java-volume-ii-advanced-
features-cay-s-horstmann/

Core Java, Vol. II-Advanced Feature 12th Edition Cay S.


Horstmann

https://ebookmeta.com/product/core-java-vol-ii-advanced-
feature-12th-edition-cay-s-horstmann/

Law as an Instrument: Sources of Chinese Law for


Authoritarian Legality Shucheng Wang

https://ebookmeta.com/product/law-as-an-instrument-sources-of-
chinese-law-for-authoritarian-legality-shucheng-wang/
Physics of the Apocalypse 2 A LitRPG Apocalypse Saga
1st Edition Dimitrios Gkirgkiris

https://ebookmeta.com/product/physics-of-the-
apocalypse-2-a-litrpg-apocalypse-saga-1st-edition-dimitrios-
gkirgkiris/

Phantom 1st Edition Rory Surtain

https://ebookmeta.com/product/phantom-1st-edition-rory-surtain/

Abolish the Monarchy Why we should and how we will


Graham Smith

https://ebookmeta.com/product/abolish-the-monarchy-why-we-should-
and-how-we-will-graham-smith/

RN Mental Health Nursing REVIEW MODULE EDITION 11.0 Ati


Nursing Education

https://ebookmeta.com/product/rn-mental-health-nursing-review-
module-edition-11-0-ati-nursing-education/

Programming Languages and Systems 19th Asian Symposium


APLAS 2021 Chicago IL USA October 17 18 2021
Proceedings 1st Edition Hakjoo Oh

https://ebookmeta.com/product/programming-languages-and-
systems-19th-asian-symposium-aplas-2021-chicago-il-usa-
october-17-18-2021-proceedings-1st-edition-hakjoo-oh-2/
IT Security Controls: A Guide to Corporate Standards
and Frameworks 1st Edition Virgilio Viegas

https://ebookmeta.com/product/it-security-controls-a-guide-to-
corporate-standards-and-frameworks-1st-edition-virgilio-viegas/
About This eBook
ePUB is an open, industry-standard format for eBooks.
However, support of ePUB and its many features varies
across reading devices and applications. Use your device or
app settings to customize the presentation to your liking.
Settings that you can customize often include font, font size,
single or double column, landscape or portrait mode, and
figures that you can click or tap to enlarge. For additional
information about the settings and features on your reading
device or app, visit the device manufacturer’s Web site.
Many titles include programming code or configuration
examples. To optimize the presentation of these elements,
view the eBook in single-column, landscape mode and
adjust the font size to the smallest setting. In addition to
presenting code and configurations in the reflowable text
format, we have included images of the code that mimic the
presentation found in the print book; therefore, where the
reflowable format may compromise the presentation of the
code listing, you will see a “Click here to view code image”
link. Click the link to view the print-fidelity code image. To
return to the previous page viewed, click the Back button on
your device or app.
Core Java for the
Impatient
Third Edition
Core Java for the
Impatient
Third Edition

Cay S. Horstmann

Boston • Columbus • New York • San Francisco •


Amsterdam • Cape Town
Dubai • London • Madrid • Milan • Munich • Paris •
Montreal • Toronto • Delhi • Mexico City
São Paulo • Sydney • Hong Kong • Seoul • Singapore
• Taipei • Tokyo
Cover illustration by Morphart Creation / Shutterstock
Figures 1.1 and 1.3: Microsoft
Figure 1.2: Eclipse Foundation
Figures 1.4, 1.5, 11.1: Oracle Corporation

Many of the designations used by manufacturers and sellers


to distinguish their products are claimed as trademarks.
Where those designations appear in this book, and the
publisher was aware of a trademark claim, the designations
have been printed with initial capital letters or in all capitals.

The author and publisher have taken care in the preparation


of this book, but make no expressed or implied warranty of
any kind and assume no responsibility for errors or
omissions. No liability is assumed for incidental or
consequential damages in connection with or arising out of
the use of the information or programs contained herein.

For information about buying this title in bulk quantities, or


for special sales opportunities (which may include electronic
versions; custom cover designs; and content particular to
your business, training goals, marketing focus, or branding
interests), please contact our corporate sales department at
[email protected] or (800) 382-3419.

For government sales inquiries, please contact


[email protected].

For questions about sales outside the United States, please


contact [email protected].

Visit us on the Web: informit.com/aw


Library of Congress Control Number: 2022942895

Copyright © 2023 Pearson Education, Inc.

All rights reserved. This publication is protected by


copyright, and permission must be obtained from the
publisher prior to any prohibited reproduction, storage in a
retrieval system, or transmission in any form or by any
means, electronic, mechanical, photocopying, recording, or
likewise. For information regarding permissions, request
forms and the appropriate contacts within the Pearson
Education Global Rights & Permissions Department, please
visit www.pearson.com/permissions/.

ISBN-13: 978-0-13-805210-2
ISBN-10: 0-13-805210-7

ScoutAutomatedPrintCode
Pearson’s Commitment to
Diversity, Equity, and Inclusion
Pearson is dedicated to creating bias-free content that
reflects the diversity of all learners. We embrace the many
dimensions of diversity, including but not limited to race,
ethnicity, gender, socioeconomic status, ability, age, sexual
orientation, and religious or political beliefs.
Education is a powerful force for equity and change in our
world. It has the potential to deliver opportunities that
improve lives and enable economic mobility. As we work
with authors to create content for every product and
service, we acknowledge our responsibility to demonstrate
inclusivity and incorporate diverse scholarship so that
everyone can achieve their potential through learning. As
the world’s leading learning company, we have a duty to
help drive change and live up to our purpose to help more
people create a better life for themselves and to create a
better world.
Our ambition is to purposefully contribute to a world where:
Everyone has an equitable and lifelong opportunity to
succeed through learning.
Our educational products and services are inclusive and
represent the rich diversity of learners.
Our educational content accurately reflects the histories
and experiences of the learners we serve.
Our educational content prompts deeper discussions
with learners and motivates them to expand their own
learning (and worldview).
While we work hard to present unbiased content, we want to
hear from you about any concerns or needs with this
Pearson product so that we can investigate and address
them.
Please contact us with concerns about any potential bias
at https://www.pearson.com/report-bias.xhtml.
To Chi—the most patient person in my life.
Contents
Preface
Acknowledgments
About the Author

1 FUNDAMENTAL PROGRAMMING STRUCTURES


1.1 Our First Program
1.1.1 Dissecting the “Hello, World” Program
1.1.2 Compiling and Running a Java Program
1.1.3 Method Calls
1.1.4 JShell
1.2 Primitive Types
1.2.1 Signed Integer Types
1.2.2 Floating-Point Types
1.2.3 The char Type
1.2.4 The boolean Type
1.3 Variables
1.3.1 Variable Declarations
1.3.2 Identifiers
1.3.3 Initialization
1.3.4 Constants
1.4 Arithmetic Operations
1.4.1 Assignment
1.4.2 Basic Arithmetic
1.4.3 Mathematical Methods
1.4.4 Number Type Conversions
1.4.5 Relational and Logical Operators
1.4.6 Big Numbers
1.5 Strings
1.5.1 Concatenation
1.5.2 Substrings
1.5.3 String Comparison
1.5.4 Converting Between Numbers and
Strings
1.5.5 The String API
1.5.6 Code Points and Code Units
1.5.7 Text Blocks
1.6 Input and Output
1.6.1 Reading Input
1.6.2 Formatted Output
1.7 Control Flow
1.7.1 Branches
1.7.2 Switches
1.7.3 Loops
1.7.4 Breaking and Continuing
1.7.5 Local Variable Scope
1.8 Arrays and Array Lists
1.8.1 Working with Arrays
1.8.2 Array Construction
1.8.3 Array Lists
1.8.4 Wrapper Classes for Primitive Types
1.8.5 The Enhanced for Loop
1.8.6 Copying Arrays and Array Lists
1.8.7 Array Algorithms
1.8.8 Command-Line Arguments
1.8.9 Multidimensional Arrays
1.9 Functional Decomposition
1.9.1 Declaring and Calling Static Methods
1.9.2 Array Parameters and Return Values
1.9.3 Variable Arguments
Exercises

2 OBJECT-ORIENTED PROGRAMMING
2.1 Working with Objects
2.1.1 Accessor and Mutator Methods
2.1.2 Object References
2.2 Implementing Classes
2.2.1 Instance Variables
2.2.2 Method Headers
2.2.3 Method Bodies
2.2.4 Instance Method Invocations
2.2.5 The this Reference
2.2.6 Call by Value
2.3 Object Construction
2.3.1 Implementing Constructors
2.3.2 Overloading
2.3.3 Calling One Constructor from Another
2.3.4 Default Initialization
2.3.5 Instance Variable Initialization
2.3.6 Final Instance Variables
2.3.7 The Constructor with No Arguments
2.4 Records
2.4.1 The Record Concept
2.4.2 Constructors: Canonical, Custom, and
Compact
2.5 Static Variables and Methods
2.5.1 Static Variables
2.5.2 Static Constants
2.5.3 Static Initialization Blocks
2.5.4 Static Methods
2.5.5 Factory Methods
2.6 Packages
2.6.1 Package Declarations
2.6.2 The jar Command
2.6.3 The Class Path
2.6.4 Package Access
2.6.5 Importing Classes
2.6.6 Static Imports
2.7 Nested Classes
2.7.1 Static Nested Classes
2.7.2 Inner Classes
2.7.3 Special Syntax Rules for Inner Classes
2.8 Documentation Comments
2.8.1 Comment Insertion
2.8.2 Class Comments
2.8.3 Method Comments
2.8.4 Variable Comments
2.8.5 General Comments
2.8.6 Links
2.8.7 Package, Module, and Overview
Comments
2.8.8 Comment Extraction
Exercises

3 INTERFACES AND LAMBDA EXPRESSIONS


3.1 Interfaces
3.1.1 Using Interfaces
3.1.2 Declaring an Interface
3.1.3 Implementing an Interface
3.1.4 Converting to an Interface Type
3.1.5 Casts and the instanceof Operator
3.1.6 The “Pattern-Matching” Form of
instanceof
3.1.7 Extending Interfaces
3.1.8 Implementing Multiple Interfaces
3.1.9 Constants
3.2 Static, Default, and Private Methods
3.2.1 Static Methods
3.2.2 Default Methods
3.2.3 Resolving Default Method Conflicts
3.2.4 Private Methods
3.3 Examples of Interfaces
3.3.1 The Comparable Interface
3.3.2 The Comparator Interface
3.3.3 The Runnable Interface
3.3.4 User Interface Callbacks
3.4 Lambda Expressions
3.4.1 The Syntax of Lambda Expressions
3.4.2 Functional Interfaces
3.5 Method and Constructor References
3.5.1 Method References
3.5.2 Constructor References
3.6 Processing Lambda Expressions
3.6.1 Implementing Deferred Execution
3.6.2 Choosing a Functional Interface
3.6.3 Implementing Your Own Functional
Interfaces
3.7 Lambda Expressions and Variable Scope
3.7.1 Scope of a Lambda Expression
3.7.2 Accessing Variables from the Enclosing
Scope
3.8 Higher-Order Functions
3.8.1 Methods that Return Functions
3.8.2 Methods That Modify Functions
3.8.3 Comparator Methods
3.9 Local and Anonymous Classes
3.9.1 Local Classes
3.9.2 Anonymous Classes
Exercises

4 INHERITANCE AND REFLECTION


4.1 Extending a Class
4.1.1 Super- and Subclasses
4.1.2 Defining and Inheriting Subclass
Methods
4.1.3 Method Overriding
4.1.4 Subclass Construction
4.1.5 Superclass Assignments
4.1.6 Casts
4.1.7 Anonymous Subclasses
4.1.8 Method Expressions with super
4.2 Inheritance Hierarchies
4.2.1 Final Methods and Classes
4.2.2 Abstract Methods and Classes
4.2.3 Protected Access
4.2.4 Sealed Types
4.2.5 Inheritance and Default Methods
4.3 Object: The Cosmic Superclass
4.3.1 The toString Method
4.3.2 The equals Method
4.3.3 The hashCode Method
4.3.4 Cloning Objects
4.4 Enumerations
4.4.1 Methods of Enumerations
4.4.2 Constructors, Methods, and Fields
4.4.3 Bodies of Instances
4.4.4 Static Members
4.4.5 Switching on an Enumeration
4.5 Runtime Type Information and Resources
4.5.1 The Class Class
4.5.2 Loading Resources
4.5.3 Class Loaders
4.5.4 The Context Class Loader
4.5.5 Service Loaders
4.6 Reflection
4.6.1 Enumerating Class Members
4.6.2 Inspecting Objects
4.6.3 Invoking Methods
4.6.4 Constructing Objects
4.6.5 JavaBeans
4.6.6 Working with Arrays
4.6.7 Proxies
Exercises

5 EXCEPTIONS, ASSERTIONS, AND LOGGING


5.1 Exception Handling
5.1.1 Throwing Exceptions
5.1.2 The Exception Hierarchy
5.1.3 Declaring Checked Exceptions
5.1.4 Catching Exceptions
5.1.5 The Try-with-Resources Statement
5.1.6 The finally Clause
5.1.7 Rethrowing and Chaining Exceptions
5.1.8 Uncaught Exceptions and the Stack
Trace
5.1.9 API Methods for Throwing Exceptions
5.2 Assertions
5.2.1 Using Assertions
5.2.2 Enabling and Disabling Assertions
5.3 Logging
5.3.1 Should You Use the Java Logging
Framework?
5.3.2 Logging 101
5.3.3 The Platform Logging API
5.3.4 Logging Configuration
5.3.5 Log Handlers
5.3.6 Filters and Formatters
Exercises

6 GENERIC PROGRAMMING
6.1 Generic Classes
6.2 Generic Methods
6.3 Type Bounds
6.4 Type Variance and Wildcards
6.4.1 Subtype Wildcards
6.4.2 Supertype Wildcards
6.4.3 Wildcards with Type Variables
6.4.4 Unbounded Wildcards
6.4.5 Wildcard Capture
6.5 Generics in the Java Virtual Machine
6.5.1 Type Erasure
6.5.2 Cast Insertion
6.5.3 Bridge Methods
6.6 Restrictions on Generics
6.6.1 No Primitive Type Arguments
6.6.2 At Runtime, All Types Are Raw
6.6.3 You Cannot Instantiate Type Variables
6.6.4 You Cannot Construct Arrays of
Parameterized Types
6.6.5 Class Type Variables Are Not Valid in
Static Contexts
6.6.6 Methods May Not Clash after Erasure
6.6.7 Exceptions and Generics
6.7 Reflection and Generics
6.7.1 The Class<T> Class
6.7.2 Generic Type Information in the Virtual
Machine
Exercises

7 COLLECTIONS
7.1 An Overview of the Collections Framework
7.2 Iterators
7.3 Sets
7.4 Maps
7.5 Other Collections
7.5.1 Properties
7.5.2 Bit Sets
7.5.3 Enumeration Sets and Maps
7.5.4 Stacks, Queues, Deques, and Priority
Queues
7.5.5 Weak Hash Maps
7.6 Views
7.6.1 Small Collections
7.6.2 Ranges
7.6.3 Unmodifiable Views
Exercises

8 STREAMS
8.1 From Iterating to Stream Operations
8.2 Stream Creation
8.3 The filter, map, and flatMap Methods
8.4 Extracting Substreams and Combining
Streams
8.5 Other Stream Transformations
8.6 Simple Reductions
8.7 The Optional Type
8.7.1 Producing an Alternative
8.7.2 Consuming the Value If Present
8.7.3 Pipelining Optional Values
8.7.4 How Not to Work with Optional Values
8.7.5 Creating Optional Values
8.7.6 Composing Optional Value Functions
with flatMap
8.7.7 Turning an Optional into a Stream
8.8 Collecting Results
8.9 Collecting into Maps
8.10 Grouping and Partitioning
8.11 Downstream Collectors
8.12 Reduction Operations
8.13 Primitive Type Streams
8.14 Parallel Streams
Exercises

9 PROCESSING INPUT AND OUTPUT


9.1 Input/Output Streams, Readers, and Writers
9.1.1 Obtaining Streams
9.1.2 Reading Bytes
9.1.3 Writing Bytes
9.1.4 Character Encodings
9.1.5 Text Input
9.1.6 Text Output
9.1.7 Reading and Writing Binary Data
9.1.8 Random-Access Files
9.1.9 Memory-Mapped Files
9.1.10 File Locking
9.2 Paths, Files, and Directories
9.2.1 Paths
9.2.2 Creating Files and Directories
9.2.3 Copying, Moving, and Deleting Files
9.2.4 Visiting Directory Entries
9.2.5 ZIP File Systems
9.3 HTTP Connections
9.3.1 The URLConnection and HttpURLConnection
Classes
9.3.2 The HTTP Client API
9.4 Regular Expressions
9.4.1 The Regular Expression Syntax
9.4.2 Testing a Match
9.4.3 Finding All Matches
9.4.4 Groups
9.4.5 Splitting along Delimiters
9.4.6 Replacing Matches
9.4.7 Flags
9.5 Serialization
9.5.1 The Serializable Interface
9.5.2 Transient Instance Variables
9.5.3 The readObject and writeObject Methods
9.5.4 The readExternal and writeExternal
Methods
9.5.5 The readResolve and writeReplace
Methods
9.5.6 Versioning
9.5.7 Deserialization and Security
Exercises
10 CONCURRENT PROGRAMMING
10.1 Concurrent Tasks
10.1.1 Running Tasks
10.1.2 Futures
10.2 Asynchronous Computations
10.2.1 Completable Futures
10.2.2 Composing Completable Futures
10.2.3 Long-Running Tasks in User-Interface
Callbacks
10.3 Thread Safety
10.3.1 Visibility
10.3.2 Race Conditions
10.3.3 Strategies for Safe Concurrency
10.3.4 Immutable Classes
10.4 Parallel Algorithms
10.4.1 Parallel Streams
10.4.2 Parallel Array Operations
10.5 Threadsafe Data Structures
10.5.1 Concurrent Hash Maps
10.5.2 Blocking Queues
10.5.3 Other Threadsafe Data Structures
10.6 Atomic Counters and Accumulators
10.7 Locks and Conditions
10.7.1 Locks
10.7.2 The synchronized Keyword
10.7.3 Waiting on Conditions
10.8 Threads
10.8.1 Starting a Thread
10.8.2 Thread Interruption
10.8.3 Thread-Local Variables
10.8.4 Miscellaneous Thread Properties
10.9 Processes
10.9.1 Building a Process
10.9.2 Running a Process
10.9.3 Process Handles
Exercises
11 ANNOTATIONS
11.1 Using Annotations
11.1.1 Annotation Elements
11.1.2 Multiple and Repeated Annotations
11.1.3 Annotating Declarations
11.1.4 Annotating Type Uses
11.1.5 Making Receivers Explicit
11.2 Defining Annotations
11.3 Standard Annotations
11.3.1 Annotations for Compilation
11.3.2 Meta-Annotations
11.4 Processing Annotations at Runtime
11.5 Source-Level Annotation Processing
11.5.1 Annotation Processors
11.5.2 The Language Model API
11.5.3 Using Annotations to Generate
Source Code
Exercises
12 THE DATE AND TIME API
12.1 The Time Line
12.2 Local Dates
12.3 Date Adjusters
12.4 Local Time
12.5 Zoned Time
12.6 Formatting and Parsing
12.7 Interoperating with Legacy Code
Exercises
13 INTERNATIONALIZATION
13.1 Locales
13.1.1 Specifying a Locale
13.1.2 The Default Locale
13.1.3 Display Names
13.2 Number Formats
13.3 Currencies
13.4 Date and Time Formatting
13.5 Collation and Normalization
13.6 Message Formatting
13.7 Resource Bundles
13.7.1 Organizing Resource Bundles
13.7.2 Bundle Classes
13.8 Character Encodings
13.9 Preferences
Exercises
14 COMPILING AND SCRIPTING
14.1 The Compiler API
14.1.1 Invoking the Compiler
14.1.2 Launching a Compilation Task
14.1.3 Capturing Diagnostics
14.1.4 Reading Source Files from Memory
14.1.5 Writing Byte Codes to Memory
14.2 The Scripting API
14.2.1 Getting a Scripting Engine
14.2.2 Evaluating Scripts
14.2.3 Bindings
14.2.4 Redirecting Input and Output
14.2.5 Calling Scripting Functions and
Methods
14.2.6 Compiling a Script
Exercises
15 THE JAVA PLATFORM MODULE SYSTEM
15.1 The Module Concept
15.2 Naming Modules
15.3 The Modular “Hello, World!” Program
15.4 Requiring Modules
15.5 Exporting Packages
15.6 Modules and Reflective Access
15.7 Modular JARs
15.8 Automatic Modules
15.9 The Unnamed Module
15.10 Command-Line Flags for Migration
15.11 Transitive and Static Requirements
15.12 Qualified Exporting and Opening
15.13 Service Loading
15.14 Tools for Working with Modules
Exercises

Index
Preface
Java has seen many changes since its initial release in 1996.
The classic book, Core Java, covers, in meticulous detail, not
just the language but all core libraries and a multitude of
changes between versions, spanning two volumes and over
2,000 pages. However, if you just want to be productive
with modern Java, there is a much faster, easier pathway for
learning the language and core libraries. In this book, I don’t
retrace history and don’t dwell on features of past versions.
I show you the good parts of Java as it exists today, so you
can put your knowledge to work quickly.
As with my previous “Impatient” books, I quickly cut to the
chase, showing you what you need to know to solve a
programming problem without lecturing about the
superiority of one paradigm over another. I also present the
information in small chunks, organized so that you can
quickly retrieve it when needed.
Assuming you are proficient in some other programming
language, such as C++, JavaScript, Swift, PHP, or Ruby, with
this book you will learn how to become a competent Java
programmer. I cover all aspects of Java that a developer
needs to know today, including the powerful concepts of
lambda expressions and streams, as well as modern
constructs such as records and sealed classes.
A key reason to use Java is to tackle concurrent
programming. With parallel algorithms and threadsafe data
structures readily available in the Java library, the way
application programmers should handle concurrent
programming has completely changed. I provide fresh
coverage, showing you how to use the powerful library
features instead of error-prone low-level constructs.
Traditionally, books on Java have focused on user interface
programming, but nowadays, few developers produce user
interfaces on desktop computers. If you intend to use Java
for server-side programming or Android programming, you
will be able to use this book effectively without being
distracted by desktop GUI code.
Finally, this book is written for application programmers, not
for a college course and not for systems wizards. The book
covers issues that application programmers need to wrestle
with, such as logging and working with files, but you won’t
learn how to implement a linked list by hand or how to write
a web server.
I hope you enjoy this rapid-fire introduction into modern
Java, and I hope it will make your work with Java productive
and enjoyable.
If you find errors or have suggestions for improvement,
please visit http://horstmann.com/javaimpatient, head for the
errata page, and leave a comment. Be sure to visit that site
to download the runnable code examples that complement
this book.

Register your copy of Core Java for the Impatient, Third


Edition, on the InformIT site for convenient access to
updates and/or corrections as they become available. To
start the registration process, go to
informit.com/register and log in or create an account.
Enter the product ISBN (9780138052102) and click
Submit. Look on the Registered Products tab for an
Access Bonus Content link next to this product, and
follow that link to access any available bonus materials.
If you would like to be notified of exclusive offers on
new editions and updates, please check the box to
receive email from us.
Acknowledgments
My thanks go, as always, to my editor Greg Doench, who
enthusiastically supported the vision of a short book that
gives a fresh introduction to Java. Dmitry Kirsanov and Alina
Kirsanova once again turned an XHTML manuscript into an
attractive book with amazing speed and attention to detail.
My special gratitude goes to the excellent team of reviewers
for all editions who spotted many errors and gave thoughtful
suggestions for improvement. They are: Andres Almiray,
Gail Anderson, Paul Anderson, Marcus Biel, Brian Goetz,
Mark Lawrence, Doug Lea, Simon Ritter, Yoshiki Shibata, and
Christian Ullenboom.

Cay Horstmann
Berlin
August 2022
About the Author
Cay S. Horstmann is the author of JavaScript for the
Impatient and Scala for the Impatient (both from Addison-
Wesley), is principal author of Core Java, Volumes I and II,
Twelfth Edition (Pearson, 2022), and has written a dozen
other books for professional programmers and computer
science students. He is professor emeritus of computer
science at San Jose State University and is a Java Champion.
Chapter 1

Fundamental
Programming Structures

Topics in This Chapter

1.1 Our First Program


1.2 Primitive Types
1.3 Variables
1.4 Arithmetic Operations
1.5 Strings
1.6 Input and Output
1.7 Control Flow
1.8 Arrays and Array Lists
1.9 Functional Decomposition
Exercises

In this chapter, you will learn about the basic data types and
control structures of the Java language. I assume that you
are an experienced programmer in some other language
and that you are familiar with concepts such as variables,
loops, function calls, and arrays, but perhaps with a different
syntax. This chapter will get you up to speed on the Java
way. I will also give you some tips on the most useful parts
of the Java API for manipulating common data types.
The key points of this chapter are:

1. In Java, all methods are declared in a class. You invoke a


non-static method on an object of the class to which the
method belongs.
2. Static methods are not invoked on objects. Program
execution starts with the static main method.
3. Java has eight primitive types: four signed integral types,
two floating-point types, char, and boolean.
4. The Java operators and control structures are very similar
to those of C or JavaScript.
5. There are four forms of switch: expressions and
statements with and without fall-through.
6. The Math class provides common mathematical functions.
7. String objects are sequences of characters or, more
precisely, Unicode code points in the UTF-16 encoding.
8. Use the “text box” syntax to declare multiline string
literals.
9. With the System.out object, you can display output in a
terminal window. A Scanner tied to System.in lets you read
terminal input.
10. Arrays and collections can be used to collect elements of
the same type.

1.1 Our First Program


When learning any new programming language, it is
traditional to start with a program that displays the
message “Hello, World!”. That is what we will do in the
following sections.

1.1.1 Dissecting the “Hello, World”


Program
Without further ado, here is the “Hello, World” program in
Java:
Click here to view code image
package ch01.sec01;

// Our first Java program

public class HelloWorld {


public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

Let’s examine this program:


Java is an object-oriented language. In your program,
you manipulate (mostly) objects by having them do
work. Each object that you manipulate belongs to a
specific class, and we say that the object is an instance
of that class. A class defines what an object’s state can
be and what it can do. In Java, all code is defined inside
classes. We will look at objects and classes in detail in
Chapter 2. This program is made up of a single class
HelloWorld.

main is a method, that is, a function declared inside a


class. The main method is the first method that is called
when the program runs. It is declared as static to
indicate that the method does not operate on any
objects. (When main gets called, there are only a handful
of predefined objects, and none of them are instances of
the HelloWorld class.) The method is declared as void to
indicate that it does not return any value. See Section
1.8.8, “Command-Line Arguments” (page 52) for the
meaning of the parameter declaration String[] args.
In Java, you can declare many features as public or
private, and there are a couple of other visibility levels
as well. Here, we declare the HelloWorld class and the
main method as public, which is the most common
arrangement for classes and methods.
A package is a set of related classes. It is a good idea to
place each class in a package so you can group related
classes together and avoid conflicts when multiple
classes have the same name. In this book, we’ll use
chapter and section numbers as package names. The full
name of our class is ch01.sec01.HelloWorld. Chapter 2 has
more to say about packages and package naming
conventions.
The line starting with // is a comment. All characters
between // and the end of the line are ignored by the
compiler and are meant for human readers only.
Finally, we come to the body of the main method. In our
example, it consists of a single line with a command to
print a message to System.out, an object representing
the “standard output” of the Java program.
As you can see, Java is not a scripting language that can be
used to quickly dash off a few commands. It is squarely
intended as a language for larger programs that benefit
from being organized into classes, packages, and modules.
(Modules are introduced in Chapter 15.)
Java is also quite simple and uniform. Some languages have
global variables and functions as well as variables and
methods inside classes. In Java, everything is declared
inside a class. This uniformity can lead to somewhat
verbose code, but it makes it easy to understand the
meaning of a program.

Note
You have just seen a // comment that extends to the
end of the line. You can also have multiline comments
between /* and */ delimiters, such as
Click here to view code image
/*
This is the first sample program in Core Java
for the Impatient.
The program displays the traditional greeting
"Hello, World!".
*/

There is a third comment style, called documentation


comment, with /** and */ as delimiters, that you will
see in the next chapter.

1.1.2 Compiling and Running a Java


Program
To compile and run this program, you need to install the
Java Development Kit (JDK) and, optionally, an integrated
development environment (IDE). You should also download
the sample code, which you will find at the companion
website for this book, http://horstmann.com/javaimpatient.
Since instructions for installing software don’t make for
interesting reading, I put them on the companion website as
well.
Once you have installed the JDK, open a terminal window,
change to the directory containing the ch01 directory, and
run the commands
Click here to view code image
javac ch01/sec01/HelloWorld.java
java ch01.sec01.HelloWorld

The familiar greeting will appear in the terminal window


(see Figure 1-1).
Note that two steps were involved to execute the program.
The javac command compiles the Java source code into an
intermediate machine-independent representation, called
byte codes, and saves them in class files. The java
command launches a virtual machine that loads the class
files and executes the byte codes.
Once compiled, byte codes can run on any Java virtual
machine, whether on your desktop computer or on a device
in a galaxy far, far away. The promise of “write once, run
anywhere” was an important design criterion for Java.
Figure 1-1 Running a Java program in a terminal window

Note
The javac compiler is invoked with the name of a file,
with slashes separating the path segments, and an
extension .java. The java virtual machine launcher is
invoked with the name of a class, with dots separating
the package segments, and no extension.
Note
If your program consists of a single source file, then
you can skip the compilation step and run the program
with the command
Click here to view code image
java ch01/sec01/HelloWorld.java

Behind the scenes, the program is compiled before it


runs, but no class files are produced.

Note
On Unix-like operating systems, you can turn a Java
file into an executable program by following these
steps:

1. Rename the file so that it doesn’t have extension


.java:
mv HelloWorld.java hello

2. Make the file executable:


chmod +x hello

3. Add a “shebang” line at the top of the file:


Click here to view code image
#!/path/to/jdk/bin/java --source 17

Now you can run the program as


./hello
To run the program in an IDE, you need to first make a
project, as described in the installation instructions. Then,
select the HelloWorld class and tell the IDE to run it. Figure 1-
2 shows how this looks in Eclipse. Eclipse is a popular IDE,
but there are many other excellent choices. As you get more
comfortable with Java programming, you should try out a
few and pick one that you like.
Figure 1-2 Running a Java program inside the Eclipse
IDE

Congratulations! You have just followed the time-honored


ritual of running the “Hello, World!” program in Java. Now
we are ready to examine the basics of the Java language.

Tip
At http://horstmann.com/javaimpatient, you can
download the sample code for all chapters of this book
that presents the book’s code snippets in context. The
code is organized so that you can make a single
project that holds all the example programs. I
encourage you to download, run, and study the code
as you follow along with the book content.

1.1.3 Method Calls


Let us have a closer look at the single statement of the main
method:
Click here to view code image
System.out.println("Hello, World!");

System.out is an object. It is an instance of a class called


PrintStream. The PrintStream class has methods println,
print, and so on. These methods are called instance
methods because they operate on objects, or instances, of
the class.
To invoke an instance method on an object, you use the dot
notation
object.methodName(arguments)
In this case, there is just one argument, the string "Hello,
World!".

Let’s try it with another example. Strings such as "Hello,


World!" are instances of the String class. The String class
has a method length that returns the length of a String
object. To call the method, you again use the dot notation:
"Hello, World!".length()

The length method is invoked on the object "Hello, World!",


and it has no arguments. Unlike the println method, the
length method returns a result. One way of using that result
is to print it:
Click here to view code image
System.out.println("Hello, World!".length());

Give it a try. Make a Java program with this statement and


run it to see how long the string is.
In Java, you need to construct most objects (unlike the
System.out and "Hello, World!" objects, which are already
there, ready for you to use). Here is a simple example.
An object of the Random class can generate random numbers.
You construct a Random object with the new operator:
new Random()

After the class name is the list of construction arguments,


which is empty in this example.
You can call a method on the constructed object. The call
new Random().nextInt()

yields the next integer that the newly constructed random


number generator has to offer.
If you want to invoke more than one method on an object,
store it in a variable (see Section 1.3, “Variables,” page 14).
Here we print two random numbers:
Click here to view code image
Random generator = new Random();
System.out.println(generator.nextInt());
System.out.println(generator.nextInt());

Note
The Random class is declared in the java.util package.
To use it in your program, add an import statement,
like this:
package ch01.sec01;

import java.util.Random;

public class MethodDemo {


...
}

We will look at packages and the import statement in


more detail in Chapter 2.

1.1.4 JShell
In Section 1.1.2, “Compiling and Running a Java Program”
(page 4), you saw how to compile and run a Java program.
The JShell program provides a “read-evaluate-print loop”
(REPL) that allows you to experiment with Java code without
compiling and running a program. When you type a Java
expression, JShell evaluates your input, prints the result,
and waits for your next input. To start JShell, simply type
jshell in a terminal window (Figure 1-3).
Figure 1-3 Running JShell
JShell starts with a greeting, followed by a prompt:
Click here to view code image
| Welcome to JShell -- Version 17
| For an introduction type: /help intro

jshell>
Another Random Scribd Document
with Unrelated Content
Herodes, 438
Hierosolymarius, 136
Hilarus, freedman of Cicero, 30
Hipparchus, 124
Hirrus, see Lucilius Hirrus
Hispania, 296, 362
Hortalus, cognomen of Hortensius, 194, 306;
cf. Hortensius
Hortensiana, 288
Hortensius (Q.), orator, 34, 44, 48, 50, 52, 114, 210, 340, 356, 366,
380, 428, 470
Hortensius (Q.), son of the orator, 462
Hypsaeus, see Plautius Hypsaeus

Ialysus, 176
Iconium, 388, 400
Idaeus pastor, 78
Ilium, 206
Interamna, 104
Interamnates, 308
Iphicrates, 114
Isauricum forum, 404
Isocrates, 100, 426
Issus, 390
Italia, 42, 86, 152, 174, 196, 202, 222, 230, 260, 280
Iulia lex, 162, 358, 402, 474
Iulius Caesar (C.), dictator, 4, 30, 34, 74, 106, 110, 116, 13O, 142, 154,
162, 166, 178, 188, 190, 236, 304, 308, 310, 312, 316, 318, 320,
330, 332, 342, 348, 350, 360, 362, 368, 370, 394, 396, 400, 438,
440, 472, 482
Iulius Caesar (L.), consul 64 B.C., 2, 8, 324
Iulius Caesar Strabo Vopiscus (C.), 412
Iunia lex, 136, 316
Iunius Brutus (M.), 190, 380, 384, 403, 408, 410, 412, 414, 416, 418,
420, 422, 442, 448, 450, 452, 456, 458, 460
Iunius Silanus (D.), 2
Iuventas, 78
Iuventius Laterensis (M.), 162, 190
Iuventius Talna, 56

Κικέρων (ὁ μικρός), (i.e. Tullius Cicero (Q.), son of the orator, q.v.),
138, 150
Κικέρων ὁ φιλόσοφος, (i.e. Tullius Cicero (Q.), the orator, q.v.), 144
Κόνων, 466
Κορινθίων (πολιτεία), 112
Κροτωνιάτης, (i.e. T. Annius Milo, q.v.), 464, 466
Κροτωνιατικά, 466
Κύρου παιδεία, 114

Laconicum, 298
Laelius, 170, 172
Laelius Sapiens (C.), 314
Laenius Flaccus (M.), 396, 400, 406, 422, 458
Λαιστρυγονίη, 146
Lamia (L. Aelius), 354
Laodicea, 372, 374, 376, 380, 388, 392, 396, 400, 404, 414, 424,
438, 442, 446, 462, 474
Larinum, 300
Laterensis, see Iuventius Laterensis
Laterium, 290
Latinus ἀττικισμός, 332;
-ae (tribus), 8;
-ni (libri), 96, 98, 112;
-num (commentarium), 90
Lentulus, ship-owner, 20, 22
Lentulus, see also Cornelius Lentulus
Lepreon, 444
Lepta (Q.), 378, 426, 476
Leucata, 356
Leuctrica pugna, 442
Liberalia, 428
Libertas, 266, 324
Licinia lex, 136, 316
Licinius Crassus (M.), 12, 40, 42, 72, 80, 116, 120, 122, 146, 176, 182,
190, 222, 224, 250, 298, 302, 314
Licinius Lucullus Ponticus (L.), 4, 44, 90, 190
Licinius Lucullus (M.), brother of the last, 78, 268
Licinius Macer (C.), 12
Ligur or Ligus (L.), 346
Ligurinus μῶμος, 392
Livineius Regulus (L.), 234
Livineius Trypho (L.), 234
Livius Drusus, 310, 316, 324
Locri, 434
Lollius Palicanus (L.), 2, 80
Lucceius (L. M. f.), 396, 412, 438
Lucceius (L. Q. f.), 10, 14, 26, 46, 74, 110, 288, 296, 300
Lucilius (Sex.), 392
Lucilius Hirrus (C.), 316
Lucretius (Q.), 316
Lucrinenses res, 296
Luculli, 64
Lucullus, see Licinius Lucullus
Lurco, see Aufidius Lurco
Lutatius Catulus (Q.), consul 78 B.C., 34, 54, 94, 148, 190, 192, 284
Lutatius Catulus (Q.), consul 102 B.C., 268, 270, 272
Lycaonia, 374
Lycaonium forum, 404
Lycii, 468
Lycurgei, 36

Macedonia, 188, 196, 206, 388


Macer, see Licinius Macer
Macro, 300
Maecia tribus, 310
Magnus, see Pompeius Magnus
Mallius, 64
Manilius (M’), 314
Manlius Torquatus (A.), 340, 346, 406, 422
Manlius Torquatus (L.), 330
Marcellinus, see Cornelius Lentulus Marcellinus
Marcellus, see Claudius Marcellus
Marcius Figulus (C.), 8
Marcius Philippus (L.), 368, 370, 408
Martius campus, 78, 326
Maso, see Papirius Maso
Matinius (P.), 406, 420, 458
Megabocchus, 130
Megarica signa, 20, 22
Melita, 198, 386
Memmiana epistula, 426
Memmius (C.), 78, 142, 144, 308, 316, 320, 364, 438
Menelaus, 78
Menniana praedia, 336
Menophilus, 292
Menturnae, 340
Menturnenses (litterae), 344
Mescinius Rufus (L.), 464, 474
Messalla (or Messala), see Valerius Messalla
Messius (C.), 262, 264, 310
Metellina oratio, 36
Metellus, see Caecilius Metellus
Metrodorus, of Scepsus, 118
Milo, see Annius Milo
Minerva, 12
Minucius Thermus (Q.), 2, 4, 370, 396, 412, 428
Misenum, 36
Mitilenae, 364
Moeragenes, 374, 428
Molo, 110
Mucia, wife of Pompey, 30
Mucius Scaevola (P.), consul 133 B.C., 84
Mucius Scaevola (Q.), augur, 314
Mucius Scaevola (Q.), pontifex maximus, 380, 418, 430
Mucius Scaevola (Q.), tribune 54 B.C., 322, 330
Mulviana controversia, 150
Munatius Plancus Bursa (T.), 426
Musae (Μοῦσαι,) 52, 118, 124
Mytilenaei, 362

Nanneiani, 54
Nar, 308
Nares Luc(aniae), 196
Nasica, 110. Cf. Caecilius Metellus Pius Scipio
Natta, 294
Neapolis, 16, 296
Nemus, 440
Nepos, see Caecilius Metellus Nepos (Q.)
Nero, see Claudius Nero
Nicanor, 344, 396
Nigidius Figulus (P.), 112
Ninnius Quadratus (L.), 248
Nonius Sufenas (M.), 306, 428
Numestius (Numerius), 170, 184, 186, 192
Octavius (C.), father of Augustus, 112
Octavius (M.), 402, 436
Ὁμηρικῶς, 48
Opimius, 320
Oppius (C.), 336, 348
Oppius Cornicinus (Cn.), 268
Ὀπούντιοι, 444
Ὀποῦς, 444
Ops, 434
Orodes, 382, 398, 430
Osaces, 390
Otho, see Roscius Otho

Pacciana epistula, 318


Paccius (M.), 312
Paciliana domus, 46
Pacorus, 382
Paetus, see Papirius Paetus
Palatina palaestra, 120
Palicanus, see Lollius Palicanus
Pammenes, 398
Pammenia illa, 452
Pamphylium forum, 404
Panhormus, 90
Papia lex, 330
Papirius Maso (M.), 346
Papirius Paetus (L.), 96, 98, 110, 296
Parilia, 134, 298
Paris, 78
Parthicum bellum, 398, 418, 428;
-otium, 372
Parthus, 356, 378;
-i, 362, 380, 388, 390, 398, 404, 430, 448, 472
Patrae, 356
Patro, 364, 386
Paulus, see Aemilius Paulus (L.)
Peducaeus (Sex.), 12, 14
Pella, 206
Πελληναίων (πολιτεία), 112
Peloponnesiae civitates, 444
Peloponnesus, 444
Pentelici Hermae, 20
Phaetho, 206
Phemius, 396, 404, 428
Philadelphus, 28
Philippicae orationes, 102
Philippus, king, 60
Philippus, see Marcius Philippus
Philogenes, 370, 394, 442, 452, 454
Philomelium, 388
Philotimus, 120, 298, 344, 348, 354, 378, 386, 424, 434, 454
Philoxenus, 286
Philus, see Furius Philus
Phliasii, 444
Φλιοῦς, 444
Φωκυλίδης, 296
Pilia, 282, 300, 316, 364, 436, 452, 462, 464, 468, 476, 478
Pilius Celer (Q.), 330
Pinarius (T.), 438
Pindenissitae, 388
Pindenissus, 392, 424
Piraeus, 314, 366, 478
Pisaurensis Drusus, 130
Pisidae, 468
Piso, see Calpurnius Piso and Pupius Piso
Pituanius, 306
Placentia, 482
Plaetorianum incendium, 396
Plancius (Cn.), 30, 222, 244
Plancus, see Munatius Plancus
Plato, 108, 314
Plautius Hypsaeus, 206
Plautus, 56
Plotia lex, 80
Plotius (A.), 374
Πολυκλῆς, 434
Polycharmus, 364
Pompeianus cistophorus, 126;
-na laus, 42;
-ni prodromi, 28;
-num (praedium), 92, 110, 120, 296, 340
Pompeius Magnus (Cn.), 4, 28, 30, 38, 40, 42, 60, 74, 80, 84, 86, 88,
106, 116, 146, 166, 170, 178, 180, 182, 184, 188, 190, 192, 206, 208,
210, 212, 218, 220, 222, 226, 236, 244, 246, 250, 262, 264, 270,
284, 296, 298, 308, 310, 316, 318, 326, 334, 342, 348, 350, 352,
362, 368, 382, 386, 400, 406, 412, 418, 426, 430, 438, 440, 452,
456, 458, 472, 476.
See also Cicero (Cn.) and Sampsiceramus
Pompeius Rufus (Q.), 324
Pompeius Vindullus, 440
Pomponia, 14, 18, 110, 116, 118, 120, 338
Pomponius (M.), 304 (i.e., Dionysius q.v.)
Pomponius Atticus (T.), 28, 132, 138, 144, 154, 172, 198, 210, 230,
238, 244, 246, 270, 326, 436, 450, 452, 474
Pomptina tribus, 310
Pomptinus (C.), 330, 338–40, 346, 348, 350, 352, 358, 362, 390,
406, 454
Pontidia, 412, 426
Pontius Aquila (L.), 6, 340, 342, 344
Porcius Cato (C.), 306, 316, 318
Porcius Cato (M.), 36, 42, 62, 74, 80, 108, 122, 136, 138, 174, 224,
310, 324, 330, 420, 424, 428, 450
Posidonius, 100
Postumia, 406, 412
Postumius, 406
Postumus, see Curtius Postumus (M.)
Πουλυδάμας, 122
Preciana hereditas, 480
Procilius, historian, 112
Procilius, 306, 316
Prognostica, name of a book, 110
Protogenes, 176
Ptolemaeus, 296
Publius, see Clodius Pulcher (P.)
Pulchellus (i.e., Clodius Pulcher (P.), q.v.), 104, 162, 180
Pulcher, see Clodius Pulcher (P.)
Pupius Piso Frugi Calpurnianus (M.), consul 61 B.C., 32, 38, 42, 44,
48, 56
Puteolanus, 374;
-na res, 296;
-ni, 340;
-num raudusculum, 478
Puteoli, 36, 296

Quintus, see Tullius Cicero (Q.)

Rabiriana domus, 16
Rabirius (C.), 102
Rantius, 322
Reatini, 308
Regulus, see Livineius Regulus
Rex, 58
Rhinton, 94
Rhodii, 362, 366, 368, 476
Rhodos, 100, 110, 384, 474
Rhosica vasa, 428
Roma, 4, 8, 10, 14, 22, 68, 92, 104, 112, 124, 126, 132, 134, 140, 142,
144, 148, 150, 156, 158, 180, 186, 208, 212, 256, 258, 266, 290,
298, 302, 306, 308, 340, 350, 352, 354, 356, 360, 368, 370, 374,
378, 380, 382, 384, 386, 394, 396, 406, 408, 412, 426, 454, 456,
460, 464, 466, 470, 478
Romanus homo, 90;
populus, 54–6;
-na mysteria, 440;
-nae res, 42, 44, 76, 306, 326, 478;
-ni cives, 384, 402, 404;
-ni equites, 78, 290
Romulus, 108
Roscia lex, 168
Roscius Otho (L.), 102
Rosia (rura), 308
Rufio Vestorianus, 340.
See also Sempronius Rufus
Rutilius Rufus (P.), 314

Sacra via, 274


Salaminius senatus, 450;
-nii, 406, 408, 420, 422, 448, 450, 452
Salamis, 420
Saliarem in modum, 356
Sallustius (Cn.), 10, 26
Salus, 260
Samius, 434
Sampsiceramus (i.e. Pompeius Magnus), 146, 154, 158, 184
Samus, 368
Saturnalia, 388, 392
Saturninus, see Annius Saturninus
Satyrus, see Caninius Satyrus
Saufeius (L.), 10, 134, 286, 426, 482
Scaevola, see Mucius Scaevola
Scaptius (M.), 406, 408, 410, 420, 422, 424, 448, 450, 452, 458
Scaptius (M.), in Cappadocia, 418, 458
Scaurus, see Aemilius Scaurus
Scepsius, see Metrodorus of Scepsus
Scipio, see Caecilius Metellus Pius Scipio (P.) and Cornelius Scipio
Scribonii Curiones, 190
Scribonius Curius (C.), consul 76 B.C., 42, 48, 62
Scribonius Curio (C.), son of the last, 130, 132, 142, 160, 166, 168,
188, 190, 224, 240, 438, 448, 456
Scrofa, see Tremellius Scrofa
Sebosus, 148, 150
Seius (M.), 370, 396
Seleuciana provincia, 332
Selicius (Q.), 28
Sempronius Rufus (C.), 452.
See also Rufio Vestorianus
Septem Aquae, 308
Septimius (C.), 188
Serapion, geographer, 118, 124
Serapion, see Cornelius Scipio Nasica Serapion
Sergius Catilina (L.), 2, 8, 42, 58, 102, 274
Serranus, see Atilius Serranus
Servilia, 346, 426
Servilius (M.), 462
Servilius Ahala (C.), 190
Servilius Caepio Brutus (i.e. M. Junius Brutus q.v.), 188, 190
Servilius Vatta (P.), 432
Servilius Vatta Isauricus (P.), praetor 54 B.C., 90, 110, 310, 330
Servius, see Sulpicius Rufus
Sestius (P.), 234, 238, 242, 250, 276, 380, 438
Sicca, 196, 198
Sicilia, 104, 434
Sicinius, 346
Siculus Epicharmus, 88;
-i, 104, 364
Sicyon, 32
Sicyonii, 90, 96, 110, 146, 178
Sidicinus, see Egnatius Sidicinus
Silanus, see Iunius Silanus
Silius Nerva (P.), 428
Σιπούντιοι, 444
Σιποῦς, 444
Socrates, 314
Σωκρατικῶς, 116
Solonium, 116, 134
Sophocles, 130
Sopolis, 330
Sositheus, 30
Σπάρτα, 94, 286
Spartacus, 450
Spongia, 56
Statius, 162, 164, 338, 442
Statius (Sex.), 422
Sufenas, see Nonius Sufenas
Sulla, see Cornelius Sulla
Sullani homines, 84
Sulpicius Galba (P.), 2
Sulpicius Rufus (Ser.), 122, 346, 404
Sybota, 354
Synnadense forum, 404
Synnas (Synneda), 376, 388
Syria, 56, 296, 382, 390, 454, 462, 468, 478
Syros, 366

Tadiana res, 16;


-num negotium, 20
Tadius, 16, 20
Talna, see Juventius Talna
Tarentinus (ager), 200
Tarentum, 200, 350
Tarquitius (L.), 476
Tarsenses, 402
Tarsus, 378, 380, 390, 402, 406, 462
Tauri pylae, 390
Taurus, 374, 382, 390, 402, 412
Τέμπη, 308
Tenea, 444
Terentia, 8, 16, 28, 116, 120, 132, 138, 144, 150, 200, 208, 210, 236,
250, 426, 404
Terentius, 290,, 428
Terentius, tribune 54 B.C., 322
Terentius Culleo (Q.), 228
Terentius Varro (M.), 170, 178, 182, 192, 206, 222, 224, 238, 270,
304, 312, 362
Terminalia, 414
Tettius Damio, 274
Teucris (Τεῦκρις), 28, 38, 46
Thallumetus, 366
Thalna, see Iuventius Thalna
Theophanes (Θεοφάνης), 122, 144, 158, 362
Theophrastus (Θεόφραστος), 118, 136, 154, 434
Theopompium genus, 126
Theopompus, 426
Thermus, see Minucius Thermus
Thesprotia, 456
Thessalia, 244
Thessalonica, 68, 206, 208, 212, 214, 218, 222, 230, 236, 242, 244
Thurium, 200
Thyillus, 22, 30, 64
Tiberius, 402
Tigranes, 118, 128
Tigranes filius, 206
Timaeus, 434
Tiro, see Tullius Tiro
Titinius (Q.), 118, 402
Titus (Τίτος Ἀθηναῖος), see Pomponius Atticus
Torquatus, see Manlius Torquatus
Tralles, 372
Transpadanus, 362;
-ni 342
Trebonius (C.), 292
Trebulanum (praedium), 340, 342, 344
Tremellius Scrofa (Cn.), 346, 428
Tres Tabernae, 32, 140, 142, 144
Triarius, see Valerius Triarius
Tritia, 444
Tritones piscinarum, 136
Τρῳάδες, 122
Τρῶες, 122
Trophoniana narratio, 444
Trypho, see Caecilius Trypho
Tubero, see Aelius Tubero
Tullia (or Tulliola), 10, 16, 20, 26, 134, 238, 260, 282, 426, 464, 476,
482
Tullii Cicerones, 378, 396, 426
Tullius, scribe, 344, 346
Tullius (L.), legate of Cicero, 346, 362, 372, 402
Tullius Cicero (L.), cousin of Cicero, 12
Tullius Cicero (M.), the orator, 378.
See also Κικέρων ὁ φιλόσοφος
Tullius Cicero (M.), his son, 76, 132, 138, 312, 332, 356, 452, 478;
see also Κικέρων (ὁ μικρός).
Tullius Cicero (Q.), brother of the orator, 6, 10, 14, 16, 18, 20, 46, 64,
66, 90, 118, 126, 132, 156, 208, 216, 220, 230, 234, 236, 238, 244,
250, 256, 260, 264, 274, 288, 290, 296, 304, 310, 314, 330, 334,
338, 360, 392, 396, 402, 406, 412, 456
Tullius Cicero (Q.), son of the last, 112, 250, 288, 290, 296, 426, 444,
460, 474, 480
Tullius Tiro (M.), 474
Turpio, 432
Turranius (D.), 18, 480
Tusculana villa, 270;
-num aedificium, 46;
-um (praedium), 12, 16, 18, 22, 110, 134, 138, 272, 302, 314, 336,
438
Tyrannio, 124, 280, 282, 292

Valerius, 114
Valerius, interpreter, 30
Valerius (P.), 412
Valerius Flaccus (L.), 82, 194
Valerius Messalla (M.), 296, 310, 316, 320, 366, 386
Valerius Messalla Niger (M.), consul 61 B.C., 32, 36, 38, 40, 44, 262
Valerius Triarius (P.), 316, 324
Varius (P.), 4
Varro, see Terentius Varro
Vatinius (P.), 126, 130, 138, 190
Vedianae res, 440
Vedius (P.), 440
Veiento, 322
Velinus lacus 308;
-na tribus, 310
Vennonius (C.), 440, 458
Venus, 176
Venusia, 348
Vestorius (C.), 288, 304, 316, 332, 340, 444, 452
Vettius, 284
Vettius, a broker, 432
Vettius (L.), 188, 190
Vettius Chrysippus, 120
Vibius, 174
Vibo, 198
Visellius, 250
Volaterrani, 84
Volusius (Cn.), 362
Volusius (Q.), 402

Xeno, of Apollonis, 370


Xeno, of Athens, 360, 364
Xenocrates, 52

Zaleucus, 434
Zoster, 360
W. H. Smith & Son, The Arden Press, Stamford Street, S.E.
TRANSCRIBER’S NOTES
1. P. 52, corrected “ὃππως” to “ὅππως”.
2. P. 88, corrected “ταυτα” to “ταῦτα”.
3. P. 156, corrected “δε” to “δὲ”.
4. P. 359, corrected “ἒρδοι τις ἥν ἕκαστος εἰδείη
τέχνην” to “ἔρδοι τις ἣν ἕκαστος εἰδείη
τέχνην”.
5. Silently corrected typographical errors in
punctuation and spelling in the index which
didn't agree with the text.
6. Retained anachronistic, non-standard, and
uncertain spellings as printed.
*** END OF THE PROJECT GUTENBERG EBOOK CICERO: LETTERS
TO ATTICUS, VOL. 1 OF 3 ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States
copyright in these works, so the Foundation (and you!) can copy
and distribute it in the United States without permission and
without paying copyright royalties. Special rules, set forth in the
General Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree
to abide by all the terms of this agreement, you must cease
using and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project Gutenberg™
works in compliance with the terms of this agreement for
keeping the Project Gutenberg™ name associated with the
work. You can easily comply with the terms of this agreement
by keeping this work in the same format with its attached full
Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


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

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of
the copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute


this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite these
efforts, Project Gutenberg™ electronic works, and the medium
on which they may be stored, may contain “Defects,” such as,
but not limited to, incomplete, inaccurate or corrupt data,
transcription errors, a copyright or other intellectual property
infringement, a defective or damaged disk or other medium, a
computer virus, or computer codes that damage or cannot be
read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except


for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU AGREE
THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT
LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT
EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE
THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person
or entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you
do or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status
by the Internal Revenue Service. The Foundation’s EIN or
federal tax identification number is 64-6221541. Contributions
to the Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or determine
the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.

You might also like