CHAPTER 1 The Java Programming Environment
1.1 History of Java2
1.2 Preparing to Write Java Programs2
1.3 A Simple Java Program3
1.4 How to Run a Java Program?4
1.5 Commonly Encountered Problems5
Workshops5
Workshop 1.1: Preparing the Environment for Java Programming5
Workshop 1.2: How to Run a Java Program?10
Workshop 1.3: How to Compile and Run a Java Program in DOS Prompt?12
Exercises13
CHAPTER 2 The Java Language Components
2.1 Print2Numbers Java Program17
2.2 The Java Vocabulary and Character Sets19
2.3 Primitive Data Types19
2.3.1 Boolean20
2.3.2 Characters20
2.3.3 Integers21
2.3.4 Floating Point22
2.3.5 Object References22
2.3.6 String22
2.4 Identifiers22
2.5 Reserved Words23
2.6 Comments24
2.7 Basic Program Structure25
Workshops26
Workshop 2.1: Understanding the Sequence of Program Execution26
Exercises28
CHAPTER 3 Expressions, Statements and Operators
3.1 Expression Statements31
3.1.1 Types of Expressions31
3.1.2 Assignment Expression Statements31
3.1.3 Prefix or Postfix Forms of "++" and "--" Statements32
3.1.4 Method Call Statements32
3.1.5 Object Creation Statements32
3.2 Declaration Statements33
3.3 Operators33
3.3.1 Arithmetic Operators34
3.3.2 Auto-Increment and Auto-Decrement Operators35
3.3.3 Logical Operators35
3.3.4 Relational Operators37
3.3.5 Bitwise Operators39
3.3.6 The Conditional Operator "?:" 40
3.3.7 Assignment Operators41
3.3.8 "+" Operator43
3.3.9 "." Operator44
3.3.10 Precedence and Associativity44
Workshops47
Workshop 3.1: Entering Data for Program Execution47
Exercises53
CHAPTER 4 Program Flow Controls
4.1 Sequence56
4.2 Selection57
4.2.1 Block57
4.2.2 Types of Selection Statements59
4.3 Iteration64
4.3.1 The while Statement64
4.3.2 The do-while Statement66
4.3.3 The for Statement67
4.3.4 The Enhanced‘for’ Statement70
4.4 Labels70
4.5 The break Statement71
4.6 The continue Statement71
Exercises71
CHAPTER 5 Arrays
5.1 Array75
5.1.1 Declaring and Creating an Array75
5.1.2 Initializing an Array77
5.1.3 Using Arrays77
5.2 Two-dimensional Arrays79
5.2.1 One-dimensional Array Approach79
5.2.2 Two-dimensional Array Approach80
5.2.3 Populating Two-dimensional Arrays82
5.3 Applying the Enhanced‘for’ Statement in Arrays83
5.4 An Application: Printing Numbers Divisible by 384
5.4.1 Using Label and break Statement85
5.4.2 Using continue Statement88
Workshops90
Workshop 5.1: Copying Arrays90
Exercises96
CHAPTER 6 Methods
6.1 Defining a Problem98
6.2 A Problem Solving Approach99
6.3 Improving the Problem-Solving Approach103
6.3.1 Advantage of Using Methods107
6.3.2 Walking Through readInputValues() Method107
6.3.3 Walking Through convertMarksToGrades() Method107
6.3.4 Walking Through printDetails() Method107
6.4 Block Structure and Scope108
6.4.1 Local Variables108
6.4.2 Global Variables109
6.4.3 Determining Scope of Variables across Methods110
6.4.4 Distinguishing Local Variables from Global Variables111
6.4.5 Scope of Identifier Declaration112
6.5 Parameters113
6.5.1 Actual and Formal Parameters113
6.5.2 Value Parameters117
6.6 Methods that Return Values119
6.6.1 Returning Values119
6.6.2 The return Statement121
Workshops121
Workshop 6.1: Using Methods121
Exercises125
CHAPTER 7 Class and Objects
CHAPTER 8 The Java Application Programming Interface (API)
CHAPTER 9 Inputs and Outputs
CHAPTER 10 File Handling
CHAPTER 11 Inheritance
CHAPTER 12 Encapsulation
CHAPTER 13 Polymorphism
CHAPTER 14 Interface
CHAPTER 15 Sorting, Searching, and Recursion