目录
Chapter 1 Introduction 1
1.1 What is a Computer 1
1.2 Instruction Execution Cycle 3
1.3 Compilers and Interpreters 3
1.4 Programs and Algorithms 4
1.5 Code Debugging 5
1.6 Compiling and Execution 6
1.7 Chapter Exercises 8
Chapter 2 Characters and Strings 9
2.1 Java Program Components 9
2.2 Naming Identifiers 10
2.3 Characters and Strings 12
2.4 Declaration of Variables 13
2.5 Assignment Statements 14
2.6 Named Constants 15
2.7 Standard Output 16
2.8 Standard Input 17
2.9 String Concatenation 18
2.10 The Length of a String 19
2.11 The Preprocessor 20
2.12 Chapter Exercises 20
Chapter 3 Numerical Data 23
3.1 Integers and Floating Numbers 23
3.2 Arithmetic Operations 24
3.3 Coercion and Cast 25
3.4 Operations with Mixed Types 26
3.5 Modulo Operations 27
3.6 Increments and Decrements 28
3.7 Combined Assignment Operators 28
3.8 Precedence of Operators 29
3.9 Commonly Used Methods of Math Class 30
3.10 Section Exercises 31
3.11 Formatting the Floating Numbers 32
3.12 Standard Input for Numerical Data 33
3.13 Chapter Exercises 33
Chapter 4 Input/Output and File I/O Operations 35
4.1 More on Input Statements 36
4.2 Input for Strings with Spaces 39
4.3 Input for Characters 40
4.4 Skipping Lines 41
4.5 Section Exercises 42
4.6 File I/O Operations 45
4.7 Redirection for File I/O 48
4.8 Procedure of Software Design 49
4.9 Chapter Exercises 50
Chapter 5 Selection Structures 53
5.1 The Boolean Data Type 53
5.2 Relational Operators 53
5.3 Logical Operators 54
5.4 Precedence of Operators 56
5.5 String Comparisons 57
5.6 Statement Blocks 58
5.7 If Statements 60
5.8 If-Else Statements 60
5.9 Nested If Statements 63
5.10 Section Exercises 65
5.11 More Examples 65
5.12 An Alternative Selection Structure 68
5.13 Chapter Exercises 70
Chapter 6 Loops 73
6.1 While Loops 73
6.2 EOF-Controlled Loops 76
6.3 Sentinel-Controlled Loops 78
6.4 Do-While Loops 81
6.5 For Loops 82
6.6 Chapter Exercises 85
Chapter 7 Static or Class Methods 87
7.1 Value-Returning Methods 89
7.2 Void Methods 92
7.3 Local and Global Variables 94
7.4 Section Exercises 95
7.5 More Examples 95
7.6 Chapter Exercises 98
Chapter 8 Classes 101
8.1 Definition of a Class 103
8.2 Instance Variables 103
8.3 Constructors 104
8.4 Instance Methods 104
8.5 Chapter Exercises 108
Chapter 9 Arrays 111
9.1 Declaration of an Array 112
9.2 I/O Work for Array’s Components 116
9.3 Initialization of an Array 117
9.4 Section Exercises 118
9.5 Aggregate Operations 119
9.6 Chapter Exercises 121
Chapter 10 More on Arrays 123
10.1 The Length of an Array 123
10.2 Arrays Used in Methods 124
10.3 Section Exercises 129
10.4 Parallel Arrays 130
10.5 Section Exercises 131
10.6 Two-Dimensional Arrays 131
10.7 Section Exercises 133
10.8 More on 2-D Arrays 133
10.9 2-D Arrays in Methods 135
10.10 Chapter Exercises 136
Chapter 11 More on Classes 139
11.1 Abstract Data Type (ADT) 139
11.2 Definition of a Class 140
11.3 The TimeType Class 143
11.4 Class Objects 145
11.5 Accessing Class Members 145
11.6 Code Example 146
11.7 Section Exercises 148
11.8 Aggregate Operations 149
11.9 Information Hiding150
11.10 Section Exercises152
11.11 Class Constructors152
11.12 Section Exercises157
11.13 The Fraction Class158
11.14 The Split Method160
11.15 Arrays of Objects161
11.16 Chapter Exercises163
Chapter 12 Lists 165
12.1 What is a List165
12.2 Sequential Search168
12.3 Selection Sort169
12.4 The List Class173
12.5 Section Exercises179
12.6 Sorted Lists 180
12.7 Java Generics188
12.8 Big-O Notation189
12.9 Using the ArrayList Class 192
12.10 Chapter Exercises 193
Chapter 13 Object-Oriented Programming197
13.1 OOP Inheritance 198
13.2 Using the toString Method 203
13.3 Section Exercises208
13.4 OOP Composition210
13.5 The Line Class213
13.6 Section Exercises214
13.7 OOP Polymorphism216
13.8 Java Interface218
13.9 Chapter Exercises220
Chapter 14 Exception Handling223
14.1 The Try-Catch Structure223
14.2 Exception Classes 227
14.3 More on Exception Classes230
14.4 Chapter Exercises 233
Chapter 15 Linked Lists 235
15.1 The ListNode Class 236
15.2 Creating a Linked List237
15.3 Using the LinkedList Class243
15.4 More on Java Generics 245
15.5 Chapter Exercises 249
Chapter 16 Recursion 251
16.1 Recursive Methods 251
16.2 Recursion or Repetition253
16.3 More Examples 254
16.4 Chapter Exercises 254
Chapter 17 Java Applets and Applications257
17.1 Java Applets 257
17.2 The Graphics Class 259
17.3 The Simulation of Cell Division261
17.4 The Dynamic Iteration of Triangles264
Bibliography 269
Appendix A Using Linux for Java 271
A.1 New Users on Linux 271
A.2 User Login 272
A.3 PICO Editor 273
A.4 Using Secure File Transfer 276
Appendix B Installation of Java and TextPad279
B.1 Installation of Java 279
B.2 Downloading and Installing TextPad282
B.3 Execution of Java Applications 283
B.4 Execution of Java Applets 285
Index 287