Cover
Title Page
Copyright Page
Contents
Preface
Acknowledgments
About the Authors
Before You Begin
1 Introduction to Computers and Java
1.1 Introduction
1.2 Computers: Hardware and Software
1.3 Data Hierarchy
1.4 Computer Organization
1.5 Machine Languages, Assembly Languages and High-Level Languages
1.6 Introduction to Object Technology
1.7 Operating Systems
1.8 Programming Languages
1.9 Java and a Typical Java Development Environment
1.10 Test-Driving a Java Application
1.11 Web 2.0: Going Social
1.12 Software Technologies
1.13 Keeping Up-to-Date with Information Technologies
1.14 Wrap-Up
2 Introduction to Java Applications
2.1 Introduction
2.2 Your First Program in Java: Printing a Line of Text
2.3 Modifying Your First Java Program
2.4 Displaying Text with printf
2.5 Another Application: Adding Integers
2.6 Memory Concepts
2.7 Arithmetic
2.8 Decision Making: Equality and Relational Operators
2.9 Wrap-Up
3 Introduction to Classes, Objects, Methods and Strings
3.1 Introduction
3.2 Declaring a Class with a Method and Instantiating an Object of a Class
3.3 Declaring a Method with a Parameter
3.4 Instance Variables, set Methods and get Methods
3.5 Primitive Types vs. Reference Types
3.6 Initializing Objects with Constructors
3.7 Floating-Point Numbers and Type double
3.8 (Optional) GUI and Graphics Case Study: Using Dialog Boxes
3.9 Wrap-Up
4 Control Statements: Part 1
4.1 Introduction
4.2 Algorithms
4.3 Pseudocode
4.4 Control Structures
4.5 if Single-Selection Statement
4.6 if …else Double-Selection Statement
4.7 while Repetition Statement
4.8 Formulating Algorithms: Counter-Controlled Repetition
4.9 Formulating Algorithms: Sentinel-Controlled Repetition
4.10 Formulating Algorithms: Nested Control Statements
4.11 Compound Assignment Operators
4.12 Increment and Decrement Operators
4.13 Primitive Types
4.14 (Optional) GUI and Graphics Case Study: Creating Simple Drawings
4.15 Wrap-Up
5 Control Statements: Part 2
5.1 Introduction
5.2 Essentials of Counter-Controlled Repetition
5.3 for Repetition Statement
5.4 Examples Using the for Statement
5.5 do…while Repetition Statement
5.6 switch Multiple-Selection Statement
5.7 break and continue Statements
5.8 Logical Operators
5.9 Structured Programming Summary
5.10 (Optional) GUI and Graphics Case Study: Drawing Rectangles and Ovals
5.11 Wrap-Up
6 Methods: A Deeper Look
6.1 Introduction
6.2 Program Modules in Java
6.3 static Methods, static Fields and Class Math
6.4 Declaring Methods with Multiple Parameters
6.5 Notes on Declaring and Using Methods
6.6 Method-Call Stack and Activation Records
6.7 Argument Promotion and Casting
6.8 Java API Packages
6.9 Case Study: Random-Number Generation
6.9.1 Generalized Scaling and Shifting of Random Numbers
6.9.2 Random-Number Repeatability for Testing and Debugging
6.10 Case Study: A Game of Chance; Introducing Enumerations
6.11 Scope of Declarations
6.12 Method Overloading
6.13 (Optional) GUI and Graphics Case Study: Colors and Filled Shapes
6.14 Wrap-Up
7 Arrays and ArrayLists
7.1 Introduction
7.2 Arrays
7.3 Declaring and Creating Arrays
7.4 Examples Using Arrays
7.5 Case Study: Card Shuffling and Dealing Simulation
7.6 Enhanced for Statement
7.7 Passing Arrays to Methods
7.8 Case Study: Class GradeBook Using an Array to Store Grades
7.9 Multidimensional Arrays
7.10 Case Study: Class GradeBook Using a Two-Dimensional Array
7.11 Variable-Length Argument Lists
7.12 Using Command-Line Arguments
7.13 Class Arrays
7.14 Introduction to Collections and Class ArrayList
7.15 (Optional) GUI and Graphics Case Study: Drawing Arcs
7.16 Wrap-Up
8 Classes and Objects: A Deeper Look
8.1 Introduction
8.2 Time Class Case Study
8.3 Controlling Access to Members
8.4 Referring to the Current Object’s Members with the this Reference
8.5 Time Class Case Study: Overloaded Constructors
8.6 Default and No-Argument Constructors
8.7 Notes on Set and Get Methods
8.8 Composition
8.9 Enumerations
8.10 Garbage Collection and Method finalize
8.11 static Class Members
8.12 static Import
8.13 final Instance Variables
8.14 Time Class Case Study: Creating Packages
8.15 Package Access
8.16 (Optional) GUI and Graphics Case Study: Using Objects with Graphics
8.17 Wrap-Up
9 Object-Oriented Programming: Inheritance
9.1 Introduction
9.2 Superclasses and Subclasses
9.3 protected Members
9.4 Relationship between Superclasses and Subclasses
9.4.1 Creating and Using a CommissionEmployee Class
9.4.2 Creating and Using a BasePlusCommissionEmployee Class
9.4.3 Creating a CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy
9.4.4 CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using protected Instance Variables
9.4.5 CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using private Instance Variables
9.5 Constructors in Subclasses
9.6 Software Engineering with Inheritance
9.7 Class Object
9.8 (Optional) GUI and Graphics Case Study: Displaying Text and Images Using Labels
9.9 Wrap-Up
10 Object-Oriented Programming: Polymorphism
10.1 Introduction
10.2 Polymorphism Examples
10.3 Demonstrating Polymorphic Behavior
10.4 Abstract Classes and Methods
10.5 Case Study: Payroll System Using Polymorphism
10.5.1 Abstract Superclass Employee
10.5.2 Concrete Subclass SalariedEmployee
10.5.3 Concrete Subclass HourlyEmployee
10.5.4 Concrete Subclass CommissionEmployee
10.5.5 Indirect Concrete Subclass BasePlusCommissionEmployee
10.5.6 Polymorphic Processing, Operator instanceof and Downcasting
10.5.7 Summary of the Allowed Assignments Between Superclass and Subclass Variables
10.6 final Methods and Classes
10.7 Case Study: Creating and Using Interfaces
10.7.1 Developing a Payable Hierarchy
10.7.2 Interface Payable
10.7.3 Class Invoice
10.7.4 Modifying Class Employee to Implement Interface Payable
10.7.5 Modifying Class SalariedEmployee for Use in the Payable Hierarchy
10.7.6 Using Interface Payable to Process Invoices and Employees Polymorphically
10.7.7 Common Interfaces of the Java API
10.8 (Optional) GUI and Graphics Case Study: Drawing with Polymorphism
10.9 Wrap-Up
11 Exception Handling: A Deeper Look
11.1 Introduction
11.2 Example: Divide by Zero without Exception Handling
11.3 Example: Handling ArithmeticExceptions and InputMismatchExceptions
11.4 When to Use Exception Handling
11.5 Java Exception Hierarchy
11.6 finally Block
11.7 Stack Unwinding and Obtaining Information from an Exception Object
11.8 Chained Exceptions
11.9 Declaring New Exception Types
11.10 Preconditions and Postconditions
11.11 Assertions
11.12 (New in Java SE 7) Multi-catch: Handling Multiple Exceptions in One catch
11.13 (New in Java SE 7) try-with-Resources: Automatic Resource Deallocation
11.14 Wrap-Up
12 ATM Case Study, Part 1: Object-Oriented Design with the UML
12.1 Case Study Introduction
12.2 Examining the Requirements Document
12.3 Identifying the Classes in a Requirements Document
12.4 Identifying Class Attributes
12.5 Identifying Objects’ States and Activities
12.6 Identifying Class Operations
12.7 Indicating Collaboration Among Objects
12.8 Wrap-Up
13 ATM Case Study Part 2: Implementing an Object-Oriented Design
13.1 Introduction
13.2 Starting to Program the Classes of the ATM System
13.3 Incorporating Inheritance and Polymorphism into the ATM System
13.4 ATM Case Study Implementation
13.4.1 Class ATM
13.4.2 Class Screen
13.4.3 Class Keypad
13.4.4 Class CashDispenser
13.4.5 Class DepositSlot
13.4.6 Class Account
13.4.7 Class BankDatabase
13.4.8 Class Transaction
13.4.9 Class BalanceInquiry
13.4.10 Class Withdrawal
13.4.11 Class Deposit
13.4.12 Class ATMCaseStudy
13.5 Wrap-Up
14 GUI Components: Part 1
14.1 Introduction
14.2 Java’s New Nimbus Look-and-Feel
14.3 Simple GUI-Based Input/Output with JOptionPane
14.4 Overview of Swing Components
14.5 Displaying Text and Images in a Window
14.6 Text Fields and an Introduction to Event Handling with Nested Classes
14.7 Common GUI Event Types and Listener Interfaces
14.8 How Event Handling Works
14.9 JButton
14.10 Buttons That Maintain State
14.10.1 JCheckBox
14.10.2 JRadioButton
14.11 JComboBox; Using an Anonymous Inner Class for Event Handling
14.12 JList
14.13 Multiple-Selection Lists
14.14 Mouse Event Handling
14.15 Adapter Classes
14.16 JPanel Subclass for Drawing with the Mouse
14.17 Key Event Handling
14.18 Introduction to Layout Managers
14.18.1 FlowLayout
14.18.2 BorderLayout
14.18.3 GridLayout
14.19 Using Panels to Manage More Complex Layouts
14.20 JTextArea
14.21 Wrap-Up
15 Graphics and Java 2D
15.1 Introduction
15.2 Graphics Contexts and Graphics Objects
15.3 Color Control
15.4 Manipulating Fonts
15.5 Drawing Lines, Rectangles and Ovals
15.6 Drawing Arcs
15.7 Drawing Polygons and Polylines
15.8 Java 2D API
15.9 Wrap-Up
16 Strings, Characters and Regular Expressions
16.1 Introduction
16.2 Fundamentals of Characters and Strings
16.3 Class String
16.3.1 String Constructors
16.3.2 String Methods length, charAt and getChars
16.3.3 Comparing Strings
16.3.4 Locating Characters and Substrings in Strings
16.3.5 Extracting Substrings from Strings
16.3.6 Concatenating Strings
16.3.7 Miscellaneous String Methods
16.3.8 String Method valueOf
16.4 Class StringBuilder
16.4.1 StringBuilder Constructors
16.4.2 StringBuilder Methods length, capacity, setLength and ensureCapacity
16.4.3 StringBuilder Methods charAt, setCharAt, getChars and reverse
16.4.4 StringBuilder append Methods
16.4.5 StringBuilder Insertion and Deletion Methods
16.5 Class Character
16.6 Tokenizing Strings
16.7 Regular Expressions, Class Pattern and Class Matcher
16.8 Wrap-Up
17 Files, Streams and Object Serialization
17.1 Introduction
17.2 Files and Streams
17.3 Class File
17.4 Sequential-Access Text Files
17.4.1 Creating a Sequential-Access Text File
17.4.2 Reading Data from a Sequential-Access Text File
17.4.3 Case Study: A Credit-Inquiry Program
17.4.4 Updating Sequential-Access Files
17.5 Object Serialization
17.5.1 Creating a Sequential-Access File Using Object Serialization
17.5.2 Reading and Deserializing Data from a Sequential-Access File
17.6 Additional java.io Classes
17.6.1 Interfaces and Classes for Byte-Based Input and Output
17.6.2 Interfaces and Classes for Character-Based Input and Output
17.7 Opening Files with JFileChooser
17.8 Wrap-Up
18 Recursion
18.1 Introduction
18.2 Recursion Concepts
18.3 Example Using Recursion: Factorials
18.4 Example Using Recursion: Fibonacci Series
18.5 Recursion and the Method-Call Stack
18.6 Recursion vs. Iteration
18.7 Towers of Hanoi
18.8 Fractals
18.9 Recursive Backtracking
18.10 Wrap-Up
19 Searching, Sorting and Big O
19.1 Introduction
19.2 Searching Algorithms
19.2.1 Linear Search
19.2.2 Binary Search
19.3 Sorting Algorithms
19.3.1 Selection Sort
19.3.2 Insertion Sort
19.3.3 Merge Sort
19.4 Wrap-Up
20 Generic Collections
20.1 Introduction
20.2 Collections Overview
20.3 Type-Wrapper Classes for Primitive Types
20.4 Autoboxing and Auto-Unboxing
20.5 Interface Collection and Class Collections
20.6 Lists
20.6.1 ArrayList and Iterator
20.6.2 LinkedList
20.7 Collections Methods
20.7.1 Method sort
20.7.2 Method shuffle
20.7.3 Methods reverse, fill, copy, max and min
20.7.4 Method binarySearch
20.7.5 Methods addAll, frequency and disjoint
20.8 Stack Class of Package java.util
20.9 Class PriorityQueue and Interface Queue
20.10 Sets
20.11 Maps
20.12 Properties Class
20.13 Synchronized Collections
20.14 Unmodifiable Collections
20.15 Abstract Implementations
20.16 Wrap-Up
21 Generic Classes and Methods
21.1 Introduction
21.2 Motivation for Generic Methods
21.3 Generic Methods: Implementation and Compile-Time Translation
21.4 Additional Compile-Time Translation Issues: Methods That Use a Type Parameter as the Return Type
21.5 Overloading Generic Methods
21.6 Generic Classes
21.7 Raw Types
21.8 Wildcards in Methods That Accept Type Parameters
21.9 Generics and Inheritance: Notes
21.10 Wrap-Up
22 Custom Generic Data Structures
22.1 Introduction
22.2 Self-Referential Classes
22.3 Dynamic Memory Allocation
22.4 Linked Lists
22.5 Stacks
22.6 Queues
22.7 Trees
22.8 Wrap-Up
23 Applets and Java Web Start
23.1 Introduction
23.2 Sample Applets Provided with the JDK
23.3 Simple Java Applet: Drawing a String
23.3.1 Executing WelcomeApplet in the appletviewer
23.3.2 Executing an Applet in a Web Browser
23.4 Applet Life-Cycle Methods
23.5 Initialization with Method init
23.6 Sandbox Security Model
23.7 Java Web Start and the Java Network Launch Protocol (JNLP)
23.7.1 Packaging the DrawTest Applet for Use with Java Web Start
23.7.2 JNLP Document for the DrawTest Applet
23.8 Wrap-Up
24 Multimedia: Applets and Applications
24.1 Introduction
24.2 Loading, Displaying and Scaling Images
24.3 Animating a Series of Images
24.4 Image Maps
24.5 Loading and Playing Audio Clips
24.6 Playing Video and Other Media with Java Media Framework
24.7 Wrap-Up
24.8 Web Resources
25 GUI Components: Part 2
25.1 Introduction
25.2 JSlider
25.3 Windows: Additional Notes
25.4 Using Menus with Frames
25.5 JPopupMenu
25.6 Pluggable Look-and-Feel
25.7 JDesktopPane and JInternalFrame
25.8 JTabbedPane
25.9 Layout Managers: BoxLayout and GridBagLayout
25.10 Wrap-Up
26 Multithreading
26.1 Introduction
26.2 Thread States: Life Cycle of a Thread
26.3 Creating and Executing Threads with Executor Framework
26.4 Thread Synchronization
26.4.1 Unsynchronized Data Sharing
26.4.2 Synchronized Data Sharing—Making Operations Atomic
26.5 Producer/Consumer Relationship without Synchronization
26.6 Producer/Consumer Relationship: ArrayBlockingQueue
26.7 Producer/Consumer Relationship with Synchronization
26.8 Producer/Consumer Relationship: Bounded Buffers
26.9 Producer/Consumer Relationship: The Lock and Condition Interfaces
26.10 Concurrent Collections Overview
26.11 Multithreading with GUI
26.11.1 Performing Computations in a Worker Thread
26.11.2 Processing Intermediate Results with SwingWorker
26.12 Interfaces Callable and Future
26.13 Java SE 7: Fork/Join Framework
26.14 Wrap-Up
27 Networking
27.1 Introduction
27.2 Manipulating URLs
27.3 Reading a File on a Web Server
27.4 Establishing a Simple Server Using Stream Sockets
27.5 Establishing a Simple Client Using Stream Sockets
27.6 Client/Server Interaction with Stream Socket Connections
27.7 Datagrams: Connectionless Client/Server Interaction
27.8 Client/Server Tic-Tac-Toe Using a Multithreaded Server
27.9 [Web Bonus] Case Study: DeitelMessenger
27.10 Wrap-Up
28 Accessing Databases with JDBC
28.1 Introduction
28.2 Relational Databases
28.3 Relational Database Overview: The books Database
28.4 SQL
28.4.1 Basic SELECT Query
28.4.2 WHERE Clause
28.4.3 ORDER BY Clause
28.4.4 Merging Data from Multiple Tables: INNER JOIN
28.4.5 INSERT Statement
28.4.6 UPDATE Statement
28.4.7 DELETE Statement
28.5 Instructions for Installing MySQL and MySQL Connector/J
28.6 Instructions for Setting Up a MySQL User Account
28.7 Creating Database books in MySQL
28.8 Manipulating Databases with JDBC
28.8.1 Connecting to and Querying a Database
28.8.2 Querying the books Database
28.9 RowSet Interface
28.10 Java DB/Apache Derby
28.11 PreparedStatements
28.12 Stored Procedures
28.13 Transaction Processing
28.14 Wrap-Up
28.15 Web Resources
29 JavaServer™ FacesWeb Apps: Part 1
29.1 Introduction
29.2 HyperText Transfer Protocol (HTTP) Transactions
29.3 Multitier Application Architecture
29.4 Your First JSF Web App
29.4.1 The Default index.xhtml Document: Introducing Facelets
29.4.2 Examining the WebTimeBean Class
29.4.3 Building the WebTime JSF Web App in NetBeans
29.5 Model-View-Controller Architecture of JSF Apps
29.6 Common JSF Components
29.7 Validation Using JSF Standard Validators
29.8 Session Tracking
29.8.1 Cookies
29.8.2 Session Tracking with @SessionScoped Beans
29.9 Wrap-Up
30 JavaServer™ FacesWeb Apps: Part 2
30.1 Introduction
30.2 Accessing Databases in Web Apps
30.2.1 Setting Up the Database
30.2.2 @ManagedBean Class AddressBean
30.2.3 index.xhtml Facelets Page
30.2.4 addentry.xhtml Facelets Page
30.3 Ajax
30.4 Adding Ajax Functionality to the Validation App
30.5 Wrap-Up
31 Web Services
31.1 Introduction
31.2 Web Service Basics
31.3 Simple Object Access Protocol (SOAP)
31.4 Representational State Transfer (REST)
31.5 JavaScript Object Notation (JSON)
31.6 Publishing and Consuming SOAP-Based Web Services
31.6.1 Creating a Web Application Project and Adding a Web Service Class in NetBeans
31.6.2 Defining the WelcomeSOAP Web Service in NetBeans
31.6.3 Publishing the WelcomeSOAP Web Service from NetBeans
31.6.4 Testing the WelcomeSOAP Web Service with GlassFish Application Server’s Tester Web Page
31.6.5 Describing a Web Service with the Web Service Description Language (WSDL)
31.6.6 Creating a Client to Consume the WelcomeSOAP Web Service
31.6.7 Consuming the WelcomeSOAP Web Service
31.7 Publishing and Consuming REST-Based XML Web Services
31.7.1 Creating a REST-Based XML Web Service
31.7.2 Consuming a REST-Based XML Web Service
31.8 Publishing and Consuming REST-Based JSON Web Services
31.8.1 Creating a REST-Based JSON Web Service
31.8.2 Consuming a REST-Based JSON Web Service
31.9 Session Tracking in a SOAP Web Service
31.9.1 Creating a Blackjack Web Service
31.9.2 Consuming the Blackjack Web Service
31.10 Consuming a Database-Driven SOAP Web Service
31.10.1 Creating the Reservation Database
31.10.2 Creating a Web Application to Interact with the Reservation Service
31.11 Equation Generator: Returning User-Defined Types
31.11.1 Creating the EquationGeneratorXML Web Service
31.11.2 Consuming the EquationGeneratorXML Web Service
31.11.3 Creating the EquationGeneratorJSON Web Service
31.11.4 Consuming the EquationGeneratorJSON Web Service
31.12 Wrap-Up
A: Operator Precedence Chart
B: ASCII Character Set
C: Keywords and Reserved Words
D: Primitive Types
E: Using the Java API Documentation
E.1 Introduction
E.2 Navigating the Java API
F: Using the Debugger
F.1 Introduction
F.2 Breakpoints and the run, stop, cont and print Commands
F.3 The print and set Commands
F.4 Controlling Execution Using the step, step up and next Commands
F.5 The watch Command
F.6 The clear Command
F.7 Wrap-Up
G: Formatted Output
G.1 Introduction
G.2 Streams
G.3 Formatting Output with printf
G.4 Printing Integers
G.5 Printing Floating-Point Numbers
G.6 Printing Strings and Characters
G.7 Printing Dates and Times
G.8 Other Conversion Characters
G.9 Printing with Field Widths and Precisions
G.10 Using Flags in the printf Format String
G.11 Printing with Argument Indices
G.12 Printing Literals and Escape Sequences
G.13 Formatting Output with Class Formatter
G.14 Wrap-Up
H: Number Systems
H.1 Introduction
H.2 Abbreviating Binary Numbers as Octal and Hexadecimal Numbers
H.3 Converting Octal and Hexadecimal Numbers to Binary Numbers
H.4 Converting from Binary, Octal or Hexadecimal to Decimal
H.5 Converting from Decimal to Binary, Octal or Hexadecimal
H.6 Negative Binary Numbers: Two’s Complement Notation
I: GroupLayout
I.1 Introduction
I.2 GroupLayout Basics
I.3 Building a ColorChooser
I.4 GroupLayout Web Resources
J: Java Desktop Integration Components
J.1 Introduction
J.2 Splash Screens
J.3 Desktop Class
J.4 Tray Icons
K: Mashups
K.1 Introduction
K.2 Popular Mashups
K.3 APIs Commonly Used in Mashups
K.4 Deitel Mashups Resource Center
K.5 Deitel RSS Resource Center
K.6 Mashup Performance and Reliability Issues
L: Unicode®
L.1 Introduction
L.2 Unicode Transformation Formats
L.3 Characters and Glyphs
L.4 Advantages/Disadvantages of Unicode
L.5 Using Unicode
L.6 Character Ranges
Appendices on the Web
Index
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z