Contents

Preface

Before You Begin

1.   Introduction

1.1   Introduction

1.2   The Internet and the World Wide Web

1.3   History of C and C++

1.4   History of Java

1.5   Java Class Libraries

1.6   Typical Java Development Environment

1.7   Notes about Java and Java for Programmers

1.8   Test-Driving a Java Application

1.9   Software Engineering Case Study: Introduction to Object Technology and the UML

1.10   Web 2.0

1.11   Software Technologies

1.12   Wrap-Up

1.13   Web Resources

2.   Introduction to Java Applications

2.1   Introduction

2.2   A First Program in Java: Printing a Line of Text

2.3   Modifying Our First Java Program

2.4   Displaying Text with printf

2.5   Another Java Application: Adding Integers

2.6   Arithmetic

2.7   Decision Making: Equality and Relational Operators

2.8   (Optional) Software Engineering Case Study: Examining the Requirements Document

2.9   Wrap-Up

3.   Introduction to Classes and Objects

3.1   Introduction

3.2   Classes, Objects, Methods and Instance Variables

3.3   Declaring a Class with a Method and Instantiating an Object of a Class

3.4   Declaring a Method with a Parameter

3.5   Instance Variables, set Methods and get Methods

3.6   Primitive Types vs. Reference Types

3.7   Initializing Objects with Constructors

3.8   Floating-Point Numbers and Type double

3.9   (Optional) Software Engineering Case Study: Identifying the Classes in a Requirements Document

3.10   Wrap-Up

4.   Control Statements: Part 1

4.1   Introduction

4.2   Control Structures

4.3   if Single-Selection Statement

4.4   if...else Double-Selection Statement

4.5   while Repetition Statement

4.6   Counter-Controlled Repetition

4.7   Sentinel-Controlled Repetition

4.8   Nested Control Statements

4.9   Compound Assignment Operators

4.10   Increment and Decrement Operators

4.11   Primitive Types

4.12   (Optional) Software Engineering Case Study: Identifying Class Attributes

4.13   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   (Optional) Software Engineering Case Study: Identifying Objects’ States and Activities

5.10   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   Introduction to Recursion

6.14   Recursion Concepts

6.15   Example Using Recursion: Factorials

6.16   Example Using Recursion: Fibonacci Series

6.17   Recursion and the Method-Call Stack

6.18   Recursion vs. Iteration

6.19   (Optional) Software Engineering Case Study: Identifying Class Operations

6.20   Wrap-Up

7.   Arrays

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   (Optional) Software Engineering Case Study: Collaboration Among Objects

7.14   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   Software Reusability

8.15   Data Abstraction and Encapsulation

8.16   Time Class Case Study: Creating Packages

8.17   Package Access

8.18   (Optional) Software Engineering Case Study: Starting to Program the Classes of the ATM System

8.19   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 a BasePlusCommissionEmployee Class without Using Inheritance

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   Object Class

9.8   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 Creating Abstract Superclass Employee

10.5.2 Creating Concrete Subclass SalariedEmployee

10.5.3 Creating Concrete Subclass HourlyEmployee

10.5.4 Creating Concrete Subclass CommissionEmployee

10.5.5 Creating Indirect Concrete Subclass BasePlusCommissionEmployee

10.5.6 Demonstrating 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 Declaring Interface Payable

10.7.3 Creating 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 Declaring Constants with Interfaces

10.7.8 Common Interfaces of the Java API

10.8   (Optional) Software Engineering Case Study: Incorporating Inheritance into the ATM System

10.9   Wrap-Up

11.   GUI Components: Part 1

11.1   Introduction

11.2   Simple GUI-Based Input/Output with JOptionPane

11.3   Overview of Swing Components

11.4   Displaying Text and Images in a Window

11.5   Text Fields and an Introduction to Event Handling with Nested Classes

11.6   Common GUI Event Types and Listener Interfaces

11.7   How Event Handling Works

11.8   JButton

11.9   Buttons That Maintain State

11.9.1 JCheckBox

11.9.2 JRadioButton

11.10   JComboBox and Using an Anonymous Inner Class for Event Handling

11.11   JList

11.12   Multiple-Selection Lists

11.13   Mouse Event Handling

11.14   Adapter Classes

11.15   JPanel Subclass for Drawing with the Mouse

11.16   Key Event Handling

11.17   Layout Managers

11.17.1 FlowLayout

11.17.2 BorderLayout

11.17.3 GridLayout

11.18   Using Panels to Manage More Complex Layouts

11.19   JTextArea

11.20   Wrap-Up

12.   Graphics and Java 2D™

12.1   Introduction

12.2   Graphics Contexts and Graphics Objects

12.3   Color Control

12.4   Font Control

12.5   Drawing Lines, Rectangles and Ovals

12.6   Drawing Arcs

12.7   Drawing Polygons and Polylines

12.8   Java 2D API

12.9   Wrap-Up

13.   Exception Handling

13.1   Introduction

13.2   Exception-Handling Overview

13.3   Example: Divide by Zero without Exception Handling

13.4   Example: Handling ArithmeticExceptions and InputMismatchExceptions

13.5   When to Use Exception Handling

13.6   Java Exception Hierarchy

13.7   finally Block

13.8   Stack Unwinding

13.9   printStackTrace, getStackTrace and getMessage

13.10   Chained Exceptions

13.11   Declaring New Exception Types

13.12   Preconditions and Postconditions

13.13   Assertions

13.14   Wrap-Up

14.   Files and Streams

14.1   Introduction

14.2   Data Hierarchy

14.3   Files and Streams

14.4   Class File

14.5   Sequential-Access Text Files

14.5.1 Creating a Sequential-Access Text File

14.5.2 Reading Data from a Sequential-Access Text File

14.5.3 Case Study: A Credit-Inquiry Program

14.5.4 Updating Sequential-Access Files

14.6   Object Serialization

14.6.1 Creating a Sequential-Access File Using Object Serialization

14.6.2 Reading and Deserializing Data from a Sequential-Access File

14.7   Additional java.io Classes

14.8   Opening Files with JFileChooser

14.9   Wrap-Up

15.   Generics

15.1   Introduction

15.2   Motivation for Generic Methods

15.3   Generic Methods: Implementation and Compile-Time Translation

15.4   Additional Compile-Time Translation Issues: Methods That Use a Type Parameter as the Return Type

15.5   Overloading Generic Methods

15.6   Generic Classes

15.7   Raw Types

15.8   Wildcards in Methods That Accept Type Parameters

15.9   Generics and Inheritance: Notes

15.10   Wrap-Up

15.11   Internet and Web Resources

16.   Collections

16.1   Introduction

16.2   Collections Overview

16.3   Class Arrays

16.4   Interface Collection and Class Collections

16.5   Lists

16.5.1 ArrayList and Iterator

16.5.2 LinkedList

16.5.3 Vector

16.6   Collections Algorithms

16.6.1 Algorithm sort

16.6.2 Algorithm shuffle

16.6.3 Algorithms reverse, fill, copy, max and min

16.6.4 Algorithm binarySearch

16.6.5 Algorithms addAll, frequency and disjoint

16.7   Stack Class of Package java.util

16.8   Class PriorityQueue and Interface Queue

16.9   Sets

16.10   Maps

16.11   Properties Class

16.12   Synchronized Collections

16.13   Unmodifiable Collections

16.14   Abstract Implementations

16.15   Wrap-Up

17.   GUI Components: Part 2

17.1   Introduction

17.2   JSlider

17.3   Windows: Additional Notes

17.4   Using Menus with Frames

17.5   JPopupMenu

17.6   Pluggable Look-and-Feel

17.7   JDesktopPane and JInternalFrame

17.8   JTabbedPane

17.9   Layout Managers: BoxLayout and GridBagLayout

17.10   Wrap-Up

18.   Multithreading

18.1   Introduction

18.2   Thread States: Life Cycle of a Thread

18.3   Thread Priorities and Thread Scheduling

18.4   Creating and Executing Threads

18.4.1 Runnables and the Thread Class

18.4.2 Thread Management with the Executor Framework

18.5   Thread Synchronization

18.5.1 Unsynchronized Data Sharing

18.5.2 Synchronized Data Sharing—Making Operations Atomic

18.6   Producer/Consumer Relationship without Synchronization

18.7   Producer/Consumer Relationship: ArrayBlockingQueue

18.8   Producer/Consumer Relationship with Synchronization

18.9   Producer/Consumer Relationship: Bounded Buffers

18.10   Producer/Consumer Relationship: The Lock and Condition Interfaces

18.11   Multithreading with GUI

18.11.1 Performing Computations in a Worker Thread

18.11.2 Processing Intermediate Results with SwingWorker

18.12   Other Classes and Interfaces in java.util.concurrent

18.13   Wrap-Up

19.   Networking

19.1   Introduction

19.2   Manipulating URLs

19.3   Reading a File on a Web Server

19.4   Establishing a Simple Server Using Stream Sockets

19.5   Establishing a Simple Client Using Stream Sockets

19.6   Client/Server Interaction with Stream Socket Connections

19.7   Connectionless Client/Server Interaction with Datagrams

19.8   Client/Server Tic-Tac-Toe Using a Multithreaded Server

19.9   Security and the Network

19.10   [Web Bonus] Case Study: DeitelMessenger Server and Client

19.11   Wrap-Up

20.   Accessing Databases with JDBC

20.1   Introduction

20.2   Relational Databases

20.3   Relational Database Overview: The books Database

20.4   SQL

20.4.1 Basic SELECT Query

20.4.2 WHERE Clause

20.4.3 ORDER BY Clause

20.4.4 Merging Data from Multiple Tables: INNER JOIN

20.4.5 INSERT Statement

20.4.6 UPDATE Statement

20.4.7 DELETE Statement

20.5   Instructions for Installing MySQL and MySQL Connector/J

20.6   Instructions for Setting Up a MySQL User Account

20.7   Creating Database books in MySQL

20.8   Manipulating Databases with JDBC

20.8.1 Connecting to and Querying a Database

20.8.2 Querying the books Database

20.9   RowSet Interface

20.10   Java DB/Apache Derby

20.11   PreparedStatements

20.12   Stored Procedures

20.13   Transaction Processing

20.14   Wrap-Up

20.15   Web Resources

21.   JavaServer™ Faces Web Applications

21.1   Introduction

21.2   Simple HTTP Transactions

21.3   Multitier Application Architecture

21.4   Java Web Technologies

21.4.1 Servlets

21.4.2 JavaServer Pages

21.4.3 JavaServer Faces

21.4.4 Web Technologies in Netbeans

21.5   Creating and Running a Simple Application in Netbeans

21.5.1 Examining a JSP Document

21.5.2 Examining a Page Bean File

21.5.3 Event-Processing Life Cycle

21.5.4 Building a Web Application in Netbeans

21.6   JSF Components

21.6.1 Text and Graphics Components

21.6.2 Validation Using Validator Components and Custom Validators

21.7   Session Tracking

21.7.1 Cookies

21.7.2 Session Tracking with Session Beans

21.8   Wrap-Up

22.   Ajax-Enabled JavaServer™ Faces Web Applications

22.1   Introduction

22.2   Accessing Databases in Web Applications

22.2.1 Building a Web Application That Displays Data from a Database

22.2.2 Modifying the Page Bean File for the AddressBook Application

22.3   Ajax-Enabled JSF Components

22.4   Creating an Autocomplete Text Field and Using Virtual Forms

22.4.1 Configuring Virtual Forms

22.4.2 JSP File with Virtual Forms and an Autocomplete Text Field

22.4.3 Providing Suggestions for an Autocomplete Text Field

22.4.4 Displaying the Contact’s Information

22.5   Wrap-Up

23.   JAX-WS Web Services

23.1   Introduction

23.2   Java Web Services Basics

23.3   Creating, Publishing, Testing and Describing a Web Service

23.3.1 Creating a Web Application Project and Adding a Web Service Class in Netbeans

23.3.2 Defining the HugeInteger Web Service in Netbeans

23.3.3 Publishing the HugeInteger Web Service from Netbeans

23.3.4 Testing the HugeInteger Web Service with GlassFish Application Server’s Tester Web Page

23.3.5 Describing a Web Service with the Web Service Description Language (WSDL)

23.4   Consuming a Web Service

23.4.1 Creating a Client in Netbeans to Consume the HugeInteger Web Service

23.4.2 Consuming the HugeInteger Web Service

23.5   SOAP

23.6   Session Tracking in Web Services

23.6.1 Creating a Blackjack Web Service

23.6.2 Consuming the Blackjack Web Service

23.7   Consuming a Database-Driven Web Service from a Web Application

23.7.1 Creating the Reservation Database

23.7.2 Creating a Web Application to Interact with the Reservation Web Service

23.8   Passing an Object of a User-Defined Type to a Web Service

23.9   Wrap-Up

24.   Formatted Output

24.1   Introduction

24.2   Streams

24.3   Formatting Output with printf

24.4   Printing Integers

24.5   Printing Floating-Point Numbers

24.6   Printing Strings and Characters

24.7   Printing Dates and Times

24.8   Other Conversion Characters

24.9   Printing with Field Widths and Precisions

24.10   Using Flags in the printf Format String

24.11   Printing with Argument Indices

24.12   Printing Literals and Escape Sequences

24.13   Formatting Output with Class Formatter

24.14   Wrap-Up

25.   Strings, Characters and Regular Expressions

25.1   Introduction

25.2   Fundamentals of Characters and Strings

25.3   Class String

25.3.1 String Constructors

25.3.2 String Methods length, charAt and getChars

25.3.3 Comparing Strings

25.3.4 Locating Characters and Substrings in Strings

25.3.5 Extracting Substrings from Strings

25.3.6 Concatenating Strings

25.3.7 Miscellaneous String Methods

25.3.8 String Method valueOf

25.4   Class StringBuilder

25.4.1 StringBuilder Constructors

25.4.2 StringBuilder Methods length, capacity, setLength and ensureCapacity

25.4.3 StringBuilder Methods charAt, setCharAt, getChars and reverse

25.4.4 StringBuilder append Methods

25.4.5 StringBuilder Insertion and Deletion Methods

25.5   Class Character

25.6   Class StringTokenizer

25.7   Regular Expressions, Class Pattern and Class Matcher

25.8   Wrap-Up

A.   Operator Precedence Chart

A.1   Operator Precedence

B.   ASCII Character Set

C.   Keywords and Reserved Words

D.   Primitive Types

E.   GroupLayout

E.1   Introduction

E.2   GroupLayout Basics

E.3   Building a ColorChooser

E.4   GroupLayout Web Resources

F.   Java Desktop Integration Components (JDIC)

F.1   Introduction

F.2   Splash Screens

F.3   Desktop Class

F.4   Tray Icons

F.5   JDIC Incubator Projects

F.6   JDIC Demos

G.   Using the Java API Documentation

G.1   Introduction

G.2   Navigating the Java API

H.   ATM Case Study Code

H.1   ATM Case Study Implementation

H.2   Class ATM

H.3   Class Screen

H.4   Class Keypad

H.5   Class CashDispenser

H.6   Class DepositSlot

H.7   Class Account

H.8   Class BankDatabase

H.9   Class Transaction

H.10   Class BalanceInquiry

H.11   Class Withdrawal

H.12   Class Deposit

H.13   Class ATMCaseStudy

H.14   Wrap-Up

I.   UML 2: Additional Diagram Types

I.1   Introduction

I.2   Additional Diagram Types

J.   Using the Debugger

J.1   Introduction

J.2   Breakpoints and the run, stop, cont and print Commands

J.3   The print and set Commands

J.4   Controlling Execution Using the step, step up and next Commands

J.5   The watch Command

J.6   The clear Command

J.7   Wrap-Up

Index

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset