Contents
About the Author
About the Technical Reviewer
Acknowledgments
Introduction
Chapter 1: Getting Started with Java
What Is Java?
Java Is a Language
Java Is a Platform
Java SE, Java EE, and Java ME
Installing the JDK and Exploring Example Applications
Hello, World!
DumpArgs
EchoText
Installing and Exploring the Eclipse IDE
Java Meets Android
What Is Android?
History of Android
Android Architecture
Android Says Hello
Summary
Chapter 2: Learning Language Fundamentals
Learning Application Structure
Learning Comments
Single-Line Comments
Multiline Comments
Javadoc Comments
Learning Identifiers
Learning Types
Primitive Types
User-Defined Types
Array Types
Learning Variables
Learning Expressions
Simple Expressions
Compound Expressions
Learning Statements
Assignment Statements
Decision Statements
Loop Statements
Break and Labeled Break Statements
Continue and Labeled Continue Statements
Summary
Chapter 3: Discovering Classes and Objects
Declaring Classes
Classes and Applications
Constructing Objects
Default Constructor
Explicit Constructors
Objects and Applications
Encapsulating State and Behaviors
Representing State via Fields
Representing Behaviors via Methods
Hiding Information
Initializing Classes and Objects
Class Initializers
Instance Initializers
Initialization Order
Collecting Garbage
Revisiting Arrays
Summary
Chapter 4: Discovering Inheritance, Polymorphism, and Interfaces
Building Class Hierarchies
Extending Classes
The Ultimate Superclass
Composition
The Trouble with Implementation Inheritance
Changing Form
Upcasting and Late Binding
Abstract Classes and Abstract Methods
Downcasting and Runtime Type Identification
Covariant Return Types
Formalizing Class Interfaces
Declaring Interfaces
Implementing Interfaces
Extending Interfaces
Why Use Interfaces?
Summary
Chapter 5: Mastering Advanced Language Features, Part 1
Mastering Nested Types
Static Member Classes
Nonstatic Member Classes
Anonymous Classes
Local Classes
Inner Classes and Memory Leaks
Interfaces within Classes and Classes within Interfaces
Mastering Packages
What Are Packages?
The Package Statement
The Import Statement
Searching for Packages and Types
Playing with Packages
Packages and JAR Files
Mastering Static Imports
Mastering Exceptions
What Are Exceptions?
Representing Exceptions in Source Code
Throwing Exceptions
Handling Exceptions
Performing Cleanup
Summary
Chapter 6: Mastering Advanced Language Features, Part 2
Mastering Assertions
Declaring Assertions
Using Assertions
Avoiding Assertions
Enabling and Disabling Assertions
Mastering Annotations
Discovering Annotations
Declaring Annotation Types and Annotating Source Code
Processing Annotations
Mastering Generics
Collections and the Need for Type Safety
Generic Types
Generic Methods
Arrays and Generics
Mastering Enums
The Trouble with Traditional Enumerated Types
The Enum Alternative
The Enum Class
Summary
Chapter 7: Exploring the Basic APIs, Part 1
Exploring Math
StrictMath and strictfp
Exploring Number and Its Children
BigDecimal
BigInteger
Primitive Type Wrapper Classes
Exploring String, StringBuffer, and StringBuilder
String
StringBuffer and StringBuilder
Exploring System
Exploring Threads
Runnable and Thread
Synchronization
Thread-Local Variables
Summary
Chapter 8: Exploring the Basic APIs, Part 2
Exploring Random
Exploring References
Basic Terminology
Reference and ReferenceQueue
SoftReference
WeakReference
PhantomReference
Exploring Reflection
The Class Entry Point
Constructor, Field, and Method
Package
Array
Exploring StringTokenizer
Exploring Timer and TimerTask
Timer in Depth
TimerTask in Depth
Summary
Chapter 9: Exploring the Collections Framework
Exploring Collections Framework Fundamentals
Comparable vs. Comparator
Iterable and Collection
Exploring Lists
ArrayList
LinkedList
Exploring Sets
TreeSet
HashSet
EnumSet
Exploring Sorted Sets
Exploring Navigable Sets
Exploring Queues
PriorityQueue
Exploring Deques
ArrayDeque
Exploring Maps
TreeMap
HashMap
IdentityHashMap
WeakHashMap
EnumMap
Exploring Sorted Maps
Exploring Navigable Maps
Exploring the Arrays and Collections Utility APIs
Exploring the Legacy Collection APIs
Summary
Chapter 10: Exploring the Concurrency Utilities
Introducing the Concurrency Utilities
Exploring Executors
Exploring Synchronizers
Countdown Latches
Cyclic Barriers
Exchangers
Semaphores
Exploring the Concurrent Collections
Demonstrating BlockingQueue and ArrayBlockingQueue
Learning More About ConcurrentHashMap
Exploring the Locking Framework
Lock
ReentrantLock
Condition
ReadWriteLock
ReentrantReadWriteLock
Exploring Atomic Variables
Improving Performance with the Concurrency Utilities
Summary
Chapter 11: Performing Classic I/O
Working with the File API
Constructing File Instances
Learning About Stored Abstract Pathnames
Learning About a Pathname’s File or Directory
Obtaining Disk Space Information
Listing Directories
Creating and Manipulating Files and Directories
Setting and Getting Permissions
Exploring Miscellaneous Capabilities
Working with the RandomAccessFile API
Working with Streams
Stream Classes Overview
OutputStream and InputStream
ByteArrayOutputStream and ByteArrayInputStream
FileOutputStream and FileInputStream
PipedOutputStream and PipedInputStream
FilterOutputStream and FilterInputStream
BufferedOutputStream and BufferedInputStream
DataOutputStream and DataInputStream
Object Serialization and Deserialization
PrintStream
Standard I/O Revisited
Working with Writers and Readers
Writer and Reader Classes Overview
Writer and Reader
OutputStreamWriter and InputStreamReader
FileWriter and FileReader
Summary
Chapter 12: Accessing Networks
Accessing Networks via Sockets
Socket Addresses
Socket Options
Socket and ServerSocket
DatagramSocket and MulticastSocket
Accessing Networks via URLs
URL and URLConnection
URLEncoder and URLDecoder
URI
Accessing Network Interfaces and Interface Addresses
Managing Cookies
Summary
Chapter 13: Migrating to New I/O
Working with Buffers
Buffer and Its Children
Buffers in Depth
Working with Channels
Channel and Its Children
Channels in Depth
Working with Selectors
Selector Fundamentals
Selector Demonstration
Working with Regular Expressions
Pattern, PatternSyntaxException, and Matcher
Character Classes
Capturing Groups
Boundary Matchers and Zero-Length Matches
Quantifiers
Practical Regular Expressions
Working with Charsets
A Brief Review of the Fundamentals
Working with Charsets
Charsets and the String Class
Working with Formatter and Scanner
Working with Formatter
Working with Scanner
Summary
Chapter 14: Accessing Databases
Introducing Java DB
Java DB Installation and Configuration
Java DB Demos
Java DB Command-Line Tools
Introducing SQLite
Accessing Databases via JDBC
Data Sources, Drivers, and Connections
Exceptions
Statements
Metadata
Summary
Chapter 15: Parsing, Creating, and Transforming XML Documents
What Is XML?
XML Declaration
Elements and Attributes
Character References and CDATA Sections
Namespaces
Comment and Processing Instructions
Well-Formed Documents
Valid Documents
Parsing XML Documents with SAX
Exploring the SAX API
Demonstrating the SAX API
Creating a Custom Entity Resolver
Parsing and Creating XML Documents with DOM
A Tree of Nodes
Exploring the DOM API
Parsing XML Documents with XMLPULL V1
Selecting XML Document Nodes with XPath
XPath Language Primer
XPath and DOM
Advanced XPath
Transforming XML Documents with XSLT
Exploring the XSLT API
Demonstrating the XSLT API
Summary
Chapter 16: Focusing on Odds and Ends
Focusing on Additional Language Features
Numeric Literal Enhancements
Switch-on-String
Diamond Operator
Multicatch
Automatic Resource Management
Focusing on Classloaders
Kinds of Classloaders
Class-Loading Mechanics
Playing with Classloaders
Classloader Difficulties
Classloaders and Resources
Focusing on Console
Focusing on Design Patterns
Understanding Strategy
Implementing Strategy
Focusing on Double Brace Initialization
Focusing on Fluent Interfaces
Focusing on Immutability
Focusing on Internationalization
Locales
Resource Bundles
Break Iterators
Collators
Dates, Time Zones, and Calendars
Formatters
Focusing on Logging
Logging API Overview
A Hierarchy of Loggers
Logging Messages
Filtering LogRecords
Handlers and Formatters
LogManager and Configuration
ErrorManager
Focusing on Preferences
Exploring Preferences
Focusing on Runtime and Process
Focusing on the Java Native Interface
Creating a Hybrid Library
Testing the Hybrid Library
Focusing on ZIP and JAR
Focusing on the ZIP API
Focusing on the JAR API
Summary
Appendix A: Solutions to Exercises
Chapter 1: Getting Started with Java
Chapter 2: Learning Language Fundamentals
Chapter 3: Discovering Classes and Objects
Chapter 4: Discovering Inheritance, Polymorphism, and Interfaces
Chapter 5: Mastering Advanced Language Features, Part 1
Chapter 6: Mastering Advanced Language Features, Part 2
Chapter 7: Exploring the Basic APIs, Part 1
Chapter 8: Exploring the Basic APIs, Part 2
Chapter 9: Exploring the Collections Framework
Chapter 10: Exploring the Concurrency Utilities
Chapter 11: Performing Classic I/O
Chapter 12: Accessing Networks
Chapter 13: Migrating to New I/O
Chapter 14: Accessing Databases
Chapter 15: Parsing, Creating, and Transforming XML Documents
Chapter 16: Focusing on Odds and Ends
Appendix B: Four of a Kind
Understanding Four of a Kind
Modeling Four of a Kind in Pseudocode
Converting Pseudocode to Java Code
Compiling, Running, and Distributing FourOfAKind
Index