Ivor Horton's Begining Java_ Java 7 Edition
Published in 2011 by John Wiley & Sons
Author(s): Ivor Horton
Edition: Java 7 Edition
Publisher: John Wiley & Sons
Year: 2011
Language: English
Commentary: Size redacted using Foxit PhantomPDF Business
Pages: 1154
Tags: Java, Ivor, Horton, Ivor Horton, Horton Ivor, Java 7, Beginning Java, Java Beginning, Wiley, JDK 7, JDK, Programming, Java Programming
Ivor Horton's Beginning Java®
Contents
Welcome
Chapter 1: Introducing Java
What Is Java All About?
Features of the Java Language
Learning Java
Java Programs
Learning Java—the Road Ahead
The Java Environment
Java Program Development
Object-Oriented Programming in Java
So What Are Objects?
What Defines a Class of Objects?
Operating on Objects
Java Program Statements
Encapsulation
Classes and Data Types
Classes and Subclasses
Advantages of Using Objects
Annotations
Generic Classes
Java Program Structure
Java's Class Library
Java Applications
Java and Unicode
Summary
Resources
Chapter 2: Programs, Data, Variables, and Calculation
Data and Variables
Naming Your Variables
Variable Names and Unicode
Variables and Types
Integer Data Types
Declaring Integer Variables
Floating-Point Data Types
Floating-Point Literals
Declaring Floating-Point Variables
Fixing the Value of a Variable
Arithmetic Calculations
Integer Calculations
Integer Division and Remainders
The Increment and Decrement Operators
Computation with Shorter Integer Types
Errors in Integer Arithmetic
Floating-Point Calculations
Other Floating-Point Arithmetic Operators
Error Conditions in Floating-Point Arithmetic
Mixed Arithmetic Expressions
Explicit Casting
Automatic Type Conversions in Assignments
The op= Operators
Mathematical Functions and Constants
Importing the Math Class Methods
Storing Characters
Character Escape Sequences
Character Arithmetic
Bitwise Operations
Using the AND and OR Operators
Using the Exclusive OR Operator
Shift Operations
Methods for Bitwise Operations
Variables with a Fixed Set of Integer Values
Boolean Variables
Operator Precedence
Program Comments
Documentation Comments
Summary
Chapter 3: Loops and Logic
Making Decisions
Making Comparisons
The if Statement
Nested if Statements
Comparing Enumeration Values
Logical Operators
The Conditional Operator
The switch Statement
The General Case of the switch Statement
Variable Scope
Loops
Varieties of Loop
Counting Using Floating-Point Values
Nested Loops
The continue Statement
The Labeled continue Statement
Using the break Statement in a Loop
Assertions
More Complex Assertions
Summary
Chapter 4: Arrays and Strings
Arrays
Array Variables
Defining an Array
The Length of an Array
Accessing Array Elements
Reusing Array Variables
Initializing Arrays
Using Arrays
Arrays of Arrays
Arrays of Characters
Strings
String Literals
Creating String Objects
Arrays of Strings
Operations on Strings
Joining Strings
Comparing Strings
Sequencing Strings
Accessing String Characters
Searching Strings for Characters
Searching for Substrings
Extracting Substrings
Modified Versions of String Objects
Creating Character Arrays from String Objects
Using the Collection-Based for Loop with a String
Obtaining the Characters in a String as an Array of Bytes
Creating String Objects from Character Arrays
Mutable Strings
Creating StringBuffer Objects
The Capacity of a StringBuffer Object
Changing the String Length for a StringBuffer Object
Adding to a StringBuffer Object
Finding the Position of a Substring
Replacing a Substring in the Buffer
Inserting Strings
Extracting Characters from a Mutable String
Other Mutable String Operations
Creating a String Object from a StringBuffer Object
Summary
Chapter 5: Defining Classes
What Is a Class?
Fields in a Class Definition
Methods in a Class Definition
Accessing Variables and Methods
Final Fields
Defining Classes
Defining Methods
Returning from a Method
The Parameter List
Defining Class Methods
Accessing Class Data Members in a Method
The Variable this
Initializing Data Members
Constructors
The Default Constructor
Creating Objects of a Class
Defining and Using a Class
Method Overloading
Multiple Constructors
Duplicating Objects Using a Constructor
Using Objects
Creating a Point from Two Lines
Recursion
Understanding Packages
Packaging Up Your Classes
Adding Classes from a Package to Your Program
Packages and Names in Your Programs
Importing Static Class Members
Standard Packages
Controlling Access to Class Members
Using Access Attributes
Specifying Access Attributes
Choosing Access Attributes
Nested Classes
Static Nested Classes
Using a Non-Static Nested Class
Using a Nested Class Outside the Top-Level Class
Local Nested Classes
Summary
Chapter 6: Extending Classes and Inheritance
Using Existing Classes
Class Inheritance
Inheriting Data Members
Inherited Methods
Overriding a Base Class Method
The @Override Annotation
Choosing Base Class Access Attributes
Polymorphism
Using Polymorphism
Multiple Levels of Inheritance
Abstract Classes
The Universal Superclass
The toString() Method
Determining the Type of an Object
Duplicating Objects
Methods Accepting a Variable Number of Arguments
Limiting the Types in a Variable Argument List
Casting Objects
When to Cast Objects
Identifying Objects
More on Enumerations
Adding Members to an Enumeration Class
Designing Classes
A Classy Example
Using the final Modifier
Interfaces
Encapsulating Constants in a Program
Interfaces Declaring Methods
Extending Interfaces
Using Interfaces
Interface Types as Method Parameters
Nesting Classes in an Interface Definition
Interfaces and the Real World
Anonymous Classes
Summary
Chapter 7: Exceptions
The Idea Behind Exceptions
Types of Exceptions
Exceptions of Type Error
Exceptions of Type RuntimeException
Other Subclasses of Exception
Dealing with Exceptions
Specifying the Exceptions a Method Can Throw
Handling Exceptions
The try Block
The catch Block
Catching Multiple Exception Types in a Block
The finally Block
Structuring a Method
Execution Sequence
Nested try Blocks
Rethrowing Exceptions
Exception Objects
The Throwable Class
Standard Exceptions
Defining Your Own Exceptions
Defining an Exception Class
Throwing Your Own Exception
An Exception Handling Strategy
Summary
Chapter 8: Understanding Streams
Streams and Input/Output Operations
Understanding Streams
Input and Output Streams
Binary and Character Streams
The Classes for Input and Output
Basic Input Stream Operations
Buffered Input Streams
Basic Output Stream Operations
Stream Readers and Writers
The Standard Streams
Getting Data from the Keyboard
Writing to the Command Line
The printf() Method
Formatting Data into a String
Summary
Chapter 9: Accessing Files and Directories
Accessing the File System
Working with Path Objects
Accessing System Properties
Setting System Properties
Testing and Checking Path Objects
Querying Files and Directories
Obtaining File Attributes
Other Path Operations
Creating and Deleting Directories and Files
Creating Directories
Creating Files
Deleting Files and Directories
Getting the Contents of a Directory
Closing a Stream
Moving and Copying Files and Directories
Renaming a File or Directory
Copying Files and Directories
Walking a File Tree
Summary
Chapter 10: Writing Files
File I/O Basics
File Output
Writing a File via an Output Stream
Writing a File Using a Writer
Buffers
Buffer Capacity
Buffer Position and Limit
Setting the Position and Limit
Creating Buffers
Marking a Buffer
Buffer Data Transfers
Using View Buffers
Preparing a Buffer for Output to a File
Writing a File Using a Channel
Channel Interfaces
Channel Operations
Obtaining a Channel for a File
Channel Write Operations
File Write Operations
Writing Part of a Buffer to a File
File Position
Using a View Buffer to Load a Byte Buffer
Writing Varying Length Strings to a File
Direct and Indirect Buffers
Writing Numerical Data Using a Channel
Writing Mixed Data to a File
Writing from Multiple Buffers
Forcing Data to Be Written to a Device
Summary
Chapter 11: Reading Files
File Read Operations
Reading a File Using an Input Stream
Reading a File Using a Buffered Reader
Reading a File Using a Channel
Reading a Text File
Getting Data from the Buffer
Reading Binary Data
Reading Mixed Data
Compacting a Buffer
Copying Files
Random Access to a File
Memory-Mapped Files
Locking a File
Locking Part of a File
Practical File Locking Considerations
Summary
Chapter 12: Serializing Objects
Storing Objects in a File
Writing an Object to a File
Writing Primitive Data Types to an Object Stream
Implementing the Serializable Interface
Reading an Object from a File
Determining the Class of a Deserialized Object
Using Object Serialization
Serializing Classes Yourself
Serialization Problems and Complications
Summary
Chapter 13: Generic Class Types
What Are Generic Types?
Defining a Generic Class Type
Implementing a Generic Type
Instantiating a Generic Type
The Runtime Type of Generic Type Instances
Relationships between Generic Type Instances
Multiple Type Parameters
Type Parameter Scope
Static Fields in a Generic Type
Type Parameter Bounds
Generic Types and Generic Interfaces
Enabling the Collection-Based for Loop for a Container Class
Implementing an Iterator Capability
A Parameterized Type for Binary Trees
Variables of a Raw Type
Wildcards as Type Parameter Arguments
Constraints on a Wildcard
More on the Class Class
Arrays and Parameterized Types
Parameterized Methods
Generic Constructors
Parameterized Types and Inheritance
Summary
Chapter 14: The Collections Framework
Understanding the Collections Framework
Collections of Objects
Sets
Sequences
Maps
Iterators
List Iterators
Collection Classes
Collection Interfaces
Using EnumSet
Array Collection Classes
Creating a Vector
Storing Objects
Retrieving Objects
Removing Objects
Searching for Objects
Applying Vectors
Sorting a Collection
Stack Storage
Linked Lists
Using Maps
The Hashing Process
Using Your Own Class Objects as Keys
Creating a HashMap Container
Storing, Retrieving, and Removing Objects
Processing all the Elements in a Map
Summary
Chapter 15: A Collection of Useful Classes
Utility Methods for Arrays
Filling an Array
Copying an Array
Comparing Arrays
Sorting Arrays
Searching Arrays
Array Contents as a String
Observable and Observer Objects
Defining Classes of Observable Objects
Observable Class Methods
Generating Random Numbers
Random Operations
Dates and Times
The Date Class
Interpreting Date Objects
Gregorian Calendars
Regular Expressions
Defining Regular Expressions
Using a Scanner
Creating Scanner Objects
Getting Input from a Scanner
Testing for Tokens
Defining Your Own Patterns for Tokens
Summary
Chapter 16: Threads
Understanding Threads
Creating Threads
Stopping a Thread
Connecting Threads
Thread Scheduling
Implementing the Runnable Interface
Managing Threads
Synchronization
Deadlocks
Using Executors
Working with an Executor
Executing Callable Tasks
Future Object Methods
Shutting down a Thread Pool
Thread Priorities
Using Thread Priorities
Summary
Chapter 17: Creating Windows
Graphical User Interfaces in Java
Model-View-Controller (MVC) Architecture
Creating a Window
Framing a Window
Preventing Deadlocks in GUI Code
Components and Containers
Window and Frame Components
Window Panes
Basics of Components
Component Attributes
The Size and Position of a Component
Points and Rectangles
Visual Characteristics of a Component
Swing Components
Using Swing Containers
Adding Components to a Container
Container Layout Managers
The Flow Layout Manager
Using a Border Layout Manager
Using a Card Layout Manager
Using a Grid Layout Manager
Using a BoxLayout Manager
Using a GridBagLayout Manager
Using a SpringLayout Manager
Adding a Menu to a Window
Creating JMenu and JMenuItem
Creating a Menu
Adding Menu Items to a Menu
Adding Menu Shortcuts and Accelerators
Summary
Chapter 18: Handling Events
Interactive Java Programs
Event-Driven Programs
The Event-Handling Process
Event Classes
Low-Level Event Classes
Making a Window Handle Its Own Events
Enabling Other Low-Level Events
Low-Level Event Listeners
Using Adapter Classes
Semantic Events
Semantic Event Listeners
Semantic Event Handling in Applets
Alternative Event-Handling Approaches
Handling Low-Level and Semantic Events
Semantic Event Listeners in an Application
Listening to Menu Items
Using Actions
The Action Interface
Action Methods
Using Actions as Menu Items
Defining Action Classes
Adding a Toolbar
Adding Buttons to a Toolbar
Adding Menu Icons
Adding Tooltips
Disabling Actions
Summary
Chapter 19: Drawing In a Window
Using the Model/ View Architecture
Component Coordinate Systems
Drawing on a Component
Graphics Contexts
The Drawing Process
Rendering Operations
Shapes
Classes Defining Points
Lines and Rectangles
Arcs and Ellipses
Curves
Complex Paths
Filling Shapes
Gradient Fill
Managing Shapes
Storing Shapes in the Model
Drawing Shapes
Drawing Using the Mouse
Handling Mouse Events
Defining Your Own Shape Classes
Defining Lines
Defining Rectangles
Defining Circles
Drawing Curves
Changing the Cursor
Summary
Chapter 20: Extending the GUI
Creating a Status Bar
A Status Bar Class for Sketcher
Updating the Panes
Using Dialogs
Modal and Modeless Dialogs
A Simple Modal Dialog
Instant Message Dialogs
Instant Input Dialogs
Using a Dialog to Create Text Elements
Defining the Menu Item and Toolbar Button for Text
Defining the Text Class
Creating Text Elements
A Font Selection Dialog
The FontDialog Class
Creating the Font Dialog Buttons
Adding the Data Pane
Implementing the Font List
Displaying the Selected Font
Using a Split Pane
Using a Spinner
Using Radio Buttons to Select the Font Style
Listening for Radio Buttons
Pop-Up Menus
Displaying a Pop-Up Menu
Implementing a Context Menu
Transforming the User Coordinate System
The AffineTransform Class
Choosing Custom Colors
Using a Buffered Image
Using a JColorChooser Dialog
Adding the Custom Color GUI
Displaying the Color Chooser Dialog
Summary
Chapter 21: Filing and Printing Documents
Serializing the Sketch
Implementing Serialization
Serializing the List of Elements
Basic Infrastructure for Saving Sketches
Assigning a Document Name
Validating the Directory for Sketches
Recording Changes to a Sketch
Handling File Menu Events
Using a File Chooser
Displaying a File Save Dialog
Displaying a File Open Dialog
Customizing a File Chooser Dialog
Implementing File Operations
Creating a Customized File Dialog
Implementing the Save Operation
Implementing the Save As Operation
Implementing the File Open Operation
Starting a New Sketch
Preventing Data Loss on Close
Printing in Java
Creating and Using PrinterJob Objects
Printing Pages
Printing the Whole Sketch
Printing in Landscape Orientation
Improving the Printing Facilities
Implementing Page Setup
Using the Java Print Dialog
Multipage Document Printing
Printing Using a Book
Printing Swing Components
Summary
Chapter 22: Java and XML
XML
The Purpose of XML
Processing XML in Java
XML Document Structure
Well-Formed XML Documents
Valid XML Documents
Elements in an XML Document
Element Attributes
Data Structure in XML
Document Type Definitions
Declaring a DTD
Defining a DTD
A DTD for Sketcher
Rules for a Well-Formed Document
XML Namespaces
Namespace Declarations
XML Namespaces and DTDs
XML Schemas
Defining a Schema
Defining Schema Elements
Specifying Data Types
Defining Attributes for Complex Elements
Restrictions on Values
Defining Groups of Attributes
Specifying a Group of Element Choices
A Schema for Sketcher
Defining Line Elements
Defining a Rectangle Element Type
Defining a Circle Element Type
Defining a Curve Element Type
Defining a Text Element Type
A Document That Uses a Schema
Programming with XML Documents
SAX Processing
DOM Processing
Accessing Parsers
Using SAX
Parser Features and Properties
Parsing Documents with SAX
Implementing a SAX Handler
Handling Other Parsing Events
Parsing a Schema Instance Document
Summary
Chapter 23: Creating and Modifying XML Documents
The Document Object Model
Setting DOM Parser Features
Parsing a Document
Navigating a Document Object Tree
Node Types
Ignorable Whitespace and Element Content
Accessing Attributes
Transforming XML
Transformer Objects
Creating Document Objects
Adding to a Document
Storing a Sketch as XML
Adding Element Nodes
Creating a Document Object for a Complete Sketch
Saving a Sketch as XML
Reading an XML Representation of a Sketch
Creating the Base Class Object from XML
Creating Elements from XML Nodes
Handling Import XML Events
Reading the XML File
Creating the Model
Summary
Appendix A: Keywords
Appendix B: Computer Arithmetic
Binary Numbers
Hexadecimal Numbers
Octal Numbers
Negative Binary Numbers
Floating-Point Numbers
Index
Advertisement