1 Introduction to Computers and Programming 1
1.1 History of Computer 1
1.2 What is a Computer? 1
1.3 Introduction to Software 2
1.4 Software Development Life-Cycle 2
1.5 Development of Programs 3
1.6 Programming Languages 3
1.7 Questions on the Chapter 5
2 Introduction to Object-Oriented Programming and Java 6
2.1 Introduction 6
2.2 Object-Oriented Concepts 6
2.3 Introduction to Java 7
2.4 Versions of Java 8
2.5 Writing the First Java Program 9
2.6 Running Java Programs 10
2.7 A Comprehensive understanding of Object-Oriented Concepts in Java 17
2.8 Questions on the Chapter 21
3 Programming Basics 22
3.1 Introduction 22
3.2 Variables 22
3.3 Identifiers 22
3.4 Java Keywords 23
3.5 Literals 24
3.6 Data Types 24
3.7 Type Casting 26
3.8 Questions on the Chapter 27
4 Operators and Expressions 29
4.1 Introduction 29
4.2 Relational and Equality Operators 29
4.3 Arithmetic Operators 30
4.4 Bit-Wise Operators 31
4.5 Assignment Operators 32
4.6 Increment and Decrement Operators 32
4.7 Logical Operators 33
4.8 Conditional Operators 34
4.9 Operator Precedence 34
4.10 Mathematical Functions 35
4.11 Operator Overloading 36
4.12 Questions on the Chapter 37
5 Selection Statements 38
5.1 Introduction 38
5.2 The ifStatements 38
5.3 The if..else Statements 40
5.4 The if..else…if Statements 41
5.5 Nested if..else Statements 43
5.6 The switch Statement 45
5.7 The Ternary Operator 49
5.8 Questions on the Chapter 50
6 Looping Statements 52
6.1 Introduction 52
6.2 The while Loop 52
6.3 The do...while Loop 54
6.4 The for Loop 58
6.5 Nesting of Loops 61
6.6 The break statement 62
6.7 The continue statement 66
6.8 Jumping Statements 67
6.9 Questions on the Chapter 72
7 Arrays 75
7.1 Introduction 75
7.2 One-Dimensional Arrays 76
7.3 Multi-Dimensional Arrays 79
7.4 Applications of Two-Dimensional Arrays 81
7.5 Questions on the Chapter 89
8 Strings 90
8.1 Introduction 90
8.2 Creating Strings 90
8.3 String Methods 91
8.4 Arrays ofStrings 94
8.5 Converting Strings to Numerical Data 95
8.6 Converting Numerical Data to Strings 97
8.7 Command line Arguments 97
8.8 Questions on the Chapter 99
9 Classes and 0bjects 100
9.1 Introduction 100
9.2 Object Definition 100
9.3 Class Definition 101
9.4 Overloaded Methods 105
9.5 Multiple Objects 106
9.6 ArrayofObjects 108
9.7 Access Modifiers 110
9.8 Questions onthe Chapter 113
10 Searching and Sorting 115
10.1 Introduction 115
10.2 Searching 115
10.3 Linear Search 115
10.4 Binary Search 117
10.5 Sorting 119
10.6 Insertion Sort 120
10.7 Selection Sort 122
10.8 Bubble Sort 125
10.9 Sorting Characters and Strings 128
10.10 Questions on the Chapter 132
11 Constructors 133
11.1 Introduction 133
11.2 Default Constructers 135
11.3 Constructors with Parameters 136
11.4 Multiple Constructors 138
11.5 The this Keyword 139
11.6 Questions on the Chapter 143
12 Inheritance 145
12.1 Introduction 145
12.2 Single Inheritance 145
12.3 The protected Keyword 150
12.4 Overriding Data and Methods 152
12.5 The super Keyword 153
12.6 Constructors and Inheritance 154
12.7 Questions on the Chapter 156
13 Polymorphism 158
13.1 Introduction 158
13.2 The instance ofOperator 164
13.3 Abstract Methods 167
13.4 Abstract Class 167
13.5 Questions on the Chapter 169
14 Exception Handling 170
14.1 Introduction 170
14.2 Handling Exceptions 171
14.3 Kinds of Exceptions 173
14.4 Catching Multiple Exceptions 176
14.5 The throw Keyword 177
14.6 Questions on the Chapter 178
15 GUI Objects and Event Programming 180
15.1 Introduction 180
15.2 GUI Objects in Java 180
15.3 Layout Managers 188
15.4 Positioning of GUI Components 193
15.5 Event-Driven Programming 195
15.6 Menu Handling 204
15.7 Questions on the Chapter 208
16 Applets 209
16.1 Introduction 209
16.2 The FirstApplet Program 209
16.3 Applets and HTML 211
16.4 Life Cycle ofan Applet 211
16.5 More Applet Programs 214
16.6 Sound and Image Programs 220
16.7 Questions on the Chapter 223
17 Thread Programming 224
17.1 Introduction 224
17.2 ASimpleThread 224
17.3 The setName() and getName() Methods 228
17.4 The setPriority0 and getPriority() Methods 229
17.5 The sleep () Method 232
17.6 The Runnable Interface 233
17.7 Questions on the Chapter 234
18 Input and Output Streams 235
18.1 Introduction 235
18.2 Input and Output Streams 235
18.3 File I/O 237
18.4 Questions on the Chapter 242
19 Network Programming in Java 243
19.1 Introduction 243
19.2 The Client and Server 243
19.3 Understanding the Socket Object 243
19.4 Questions on the Chapter 246
AppendixA: Model Questions 247
Appendix B: English-Chinese Vocabulary List 252