|
1. Introduction
|
1
|
|
Java Environment
|
2
|
|
Types of Java Programs
|
3
|
|
Java Program Development Process
|
4
|
|
Command Line Commands
|
6
|
|
Java Virtual Machine
|
7
|
|
Java Tools
|
8
|
|
Basic Code Structures
|
8
|
|
Statements and Code Blocks
|
8
|
|
Variables
|
9
|
|
Basic Types and Operations
|
10
|
|
Basic Types
|
10
|
|
Assignment
|
11
|
|
Conversions Between Basic Types
|
12
|
|
Numeric Operators
|
12
|
|
Relational Operators
|
14
|
|
Boolean Operators
|
15
|
|
Operator Precedence
|
15
|
|
Basic Operations Example Program
|
16
|
|
Control Structures
|
17
|
|
if Structure
|
17
|
|
Loop Structure
|
18
|
|
Break Statement
|
19
|
|
Switch Structure
|
20
|
|
Control Structures Example Program
|
20
|
|
2. Classes and Objects
|
22
|
|
Software Development Methodologies
|
22
|
|
Functional Decomposition Summary
|
22
|
|
Object Orientation Summary
|
23
|
|
Advantages of OO
|
24
|
|
OO Methodology Technique
|
27
|
|
Class and Object Principles
|
27
|
|
Classes as Java Code
|
27
|
|
Classes as Models
|
27
|
|
Classes as Object Factories
|
28
|
|
Object Behavior, Identity, and State
|
29
|
|
Object
|
30
|
|
Object Fields
|
32
|
|
Messages
|
33
|
|
Methods
|
35
|
|
Sending a Message versus Calling a Method
|
36
|
|
Defining a Class
|
37
|
|
Basic Structure
|
37
|
|
main Message
|
39
|
|
Encapsulation
|
41
|
|
Accessor and Mutator Messages
|
42
|
|
More Class and Object Principles
|
42
|
|
Passing Message Parameters
|
42
|
|
The this Object
|
45
|
|
Using Multiple Constructors
|
45
|
|
The Object Class
|
47
|
|
final Object References
|
47
|
|
Disposing of Objects
|
48
|
|
Classes as Objects
|
48
|
|
Class Objects and Instance Objects
|
48
|
|
Using Class Objects
|
51
|
|
Initialization Block
|
52
|
|
The Class
|
52
|
|
Working with Classes
|
53
|
|
Using Multiple Classes
|
53
|
|
Making Objects Communicate
|
55
|
|
Copying and Pasting
|
57
|
|
3. Commonly Used Classes
|
59
|
|
String Class
|
59
|
|
String API
|
60
|
|
System.out.println
|
62
|
|
Wrapper Classes for Basic Types
|
63
|
|
Array
|
65
|
|
Array Construction
|
65
|
|
Array Operations
|
66
|
|
Program Startup Parameters
|
69
|
|
ArrayList Class
|
69
|
|
4. Inheritance
|
72
|
|
Inheritance Principles
|
72
|
|
Inheritance and OO Models
|
72
|
|
The "is a" Rule
|
74
|
|
What is a Child Class?
|
75
|
|
Single and Multiple Inheritance
|
75
|
|
Subclass and Superclass
|
76
|
|
Java Inheritance Basics
|
76
|
|
Extending a Class
|
76
|
|
Access to Parent Class Properties
|
78
|
|
Instance of Operator
|
78
|
|
Parent and Child Constructors
|
79
|
|
Getting the Parent Class
|
80
|
|
Polymorphism
|
80
|
|
Assignment Polymorphism
|
81
|
|
Overloading
|
83
|
|
Overriding
|
84
|
|
Dynamic Binding and Object Reference Casts
|
86
|
|
Dynamic Binding
|
86
|
|
Object Reference Casts
|
87
|
|
Abstract Classes and Messages
|
89
|
|
Abstract Class Concept
|
90
|
|
Java Abstract Classes
|
90
|
|
Abstract Messages
|
92
|
|
The Object Class
|
93
|
|
Object Equality
|
94
|
|
Definition of equals
|
94
|
|
Implementation
|
95
|
|
Overloaded equals message
|
97
|
|
Preventing Inheritance
|
98
|
|
5. Interfaces
|
99
|
|
Interface Basics
|
99
|
|
Syntax
|
99
|
|
What an Interface Should Be
|
100
|
|
Implementing Interfaces
|
101
|
|
Comparison with Class Inheritance
|
102
|
|
Interface Inheritance
|
103
|
|
Object References
|
104
|
|
Tagging Interfaces
|
105
|
|
Cloneable Interface
|
105
|
|
Interface Uses
|
108
|
|
Collections
|
108
|
|
Event Callbacks
|
109
|
|
6. Packages and Nested Classes
|
113
|
|
Packages
|
113
|
|
What a Package Is
|
113
|
|
Defining a Package
|
113
|
|
Importing a Package
|
114
|
|
Package Access Modifier
|
115
|
|
Packages Within Packages
|
117
|
|
Classpath
|
118
|
|
Dynamic Class Loading
|
118
|
|
JVM and Compiler Classpath Use
|
119
|
|
Changing the classpath with the Current Directory
|
121
|
|
Setting the classpath Variable
|
121
|
|
classpath Option
|
122
|
|
Compiler and JVM Example
|
122
|
|
Java Archives
|
124
|
|
Nested Classes
|
124
|
|
static Nested Classes
|
125
|
|
Inner Class Basics
|
127
|
|
Inner Class Use
|
130
|
|
Anonymous Inner Classes
|
133
|
|
7. Windows and GUI Events
|
137
|
|
Window Basics
|
138
|
|
Swing Program Basic Procedure
|
138
|
|
Adapter Classes
|
142
|
|
JFrame Inheritance
|
143
|
|
JFrame Description
|
147
|
|
JFrame Sizing and Positioning
|
147
|
|
GUI Event Handling
|
149
|
|
AWT Event Classes
|
149
|
|
Handling Keyboard Events
|
151
|
|
Handling Mouse Events
|
154
|
|
Handling Action Events
|
158
|
|
Handling Multiple Events
|
161
|
|
8. Swing Components
|
165
|
|
Swing Component Basics
|
165
|
|
Swing Components Summary
|
165
|
|
Swing Components Hierarchy
|
166
|
|
GUI Design with Swing Components
|
168
|
|
Common Top-Level Containers
|
169
|
|
Elementary Swing Components
|
169
|
|
Colors
|
172
|
|
Layout Managers
|
173
|
|
GridLayout
|
174
|
|
FlowLayout
|
176
|
|
BorderLay
|
179
|
|
BoxLayout
|
183
|
|
CardLayout
|
183
|
|
GridBagLayout and SpringLayout
|
186
|
|
Dynamic Layout Updates
|
186
|
|
Common Swing Components
|
189
|
|
JTextField
|
190
|
|
JList
|
190
|
|
JScrollPane
|
192
|
|
JComboBox
|
196
|
|
Menus
|
200
|
|
Effect of Subclassing on Design
|
207
|
|
JDialog
|
210
|
|
JFileChoose
|
216
|
|
9. Graphics
|
222
|
|
Drawing Procedure and Graphics Context
|
222
|
|
Drawing 2D Geometrical Shapes
|
224
|
|
Shape In
|
224
|
|
Graphics Shape Classes
|
225
|
|
Drawing Text with Fonts
|
233
|
|
Procedure
|
233
|
|
Font Terminology and Font Class
|
234
|
|
Positioning and Drawing Text
|
236
|
|
Fonts with Components
|
239
|
|
Displaying Images
|
242
|
|
Drawing without paintComponent
|
245
|
|
10. Exceptions
|
247
|
|
Why Exceptions
|
247
|
|
Error Handling without Exceptions
|
247
|
|
Error Handling with Exceptions
|
248
|
|
Exception Basics
|
249
|
|
Exception Classes
|
249
|
|
Exception Handling Syntax
|
251
|
|
Exception Propagation
|
252
|
|
When to Propagate
|
256
|
|
Checked Exceptions and the Compiler
|
257
|
|
Other Exception Features
|
257
|
|
Throwing and Rethrowing Exceptions
|
257
|
|
Custom Exception Classes
|
258
|
|
11. Files
|
259
|
|
Pathnames
|
259
|
|
Abstract Pathname
|
260
|
|
Canonical Pathname
|
260
|
|
Pathname
|
261
|
|
Absolute and Relative Pathnames
|
261
|
|
The File Class
|
262
|
|
File.separator
|
265
|
|
Filename Filter
|
266
|
|
File Management Summary
|
268
|
|
12. Input and Output
|
269
|
|
Streams
|
269
|
|
Types of Stream I/O
|
270
|
|
Stream I/O Basic Procedure
|
270
|
|
Top-Level Stream Classes
|
272
|
|
Stream Class Hierarchy
|
274
|
|
InputStream
|
274
|
|
OutputStream
|
275
|
|
Readers
|
276
|
|
Writers
|
277
|
|
Filtered Streams
|
278
|
|
Filter Stream
|
278
|
|
Structuring Filtered Streams
|
279
|
|
Example I/O Programs
|
280
|
|
Integer I/O Program
|
280
|
|
Character Encoding Program
|
281
|
|
Predefined Streams
|
282
|
|
More on Text I/O
|
282
|
|
Reading Text Lines
|
282
|
|
Delimited Text I/O
|
283
|
|
Object Streams
|
285
|
|
Serializable Interface
|
285
|
|
Specifying the Serial Version
|
289
|
|
Custom Serialization
|
290
|
|
Externalizable Interface
|
292
|
|
Appendix A. Abbreviations
|
295
|
|
Appendix B. OO Summary
|
296
|
|
Appendix C. Java Summary
|
298
|
|
Appendix D. Exercise Answers
|
301
|