Ivor Horton's beginning Java : Java 7 edition - GBV

12 downloads 167 Views 528KB Size Report
1. What Is Java All About? 1. Features of the Java Language. 2. Learning Java. 2. Java Programs. 3. Learning Java—-the Road Ahead. 3. The Java Environment.
IVOR HORTON'S

BEGINN1N0

Java®

Java 7 Edition

Ivor Horton

WILEY

John Wiley

&

Sons,

Inc.

CONTENTS

WELCOME

xxix

CHAPTER 1: INTRODUCING JAVA What Is

1

Java All About?

Features of the Java

1

Language

2

Learning Java Java

2

Programs

Learning

3

Java—-the Road Ahead

3

The Java Environment

4

Java

Program Development Object-Oriented Programming in Java

4

11

So What Are Objects? What Defines

a Class of

Operating

Objects

Java

on

Program

11

13

Objects?

15

Statements

17

Encapsulation

18

Classes and Data

Types

18

Classes and Subclasses

18

Advantages

of

Using Objects

19

Annotations

19

Generic Classes

19

Java Program Structure Java's Class Java

20 20

Library

22

Applications

Java and Unicode

24

Summary

25

Resources

26

CHAPTER 2:

PROGRAMS, DATA, VARIABLES,

Data and Variables

Naming

Your Variables

Variable Names and Unicode Variables and Types

Integer

Data

Types

Declaring Integer Variables

Floating-Point Data Types

AND CALCULATION

27 27 28 28 29

29 31

33

CONTENTS

Floating-Point

33

Literals

34

Declaring Floating-Point Variables

Fixing the

34

Value of a Variable

34

Arithmetic Calculations

Integer

Calculations

35

Integer

Division and Remainders

39

The Increment and Decrement

Computation Errors in

Operators

with Shorter Integer Arithmetic

Calculations

42

Other Floating-Point Arithmetic Operators Error Conditions in Mixed Arithmetic

Floating-Point

Arithmetic

Assignments

Operators

50 50

Sequences

51

Character Arithmetic

Using Using Shift

53

Operations the AND and OR Operators

54

the Exclusive OR Operator

56 57

Operations

Methods for Bitwise

Integer

Boolean Variables Precedence

Operator Program

61

Operations

Variables with a Fixed Set of

Comments

Documentation Comments

Values

63 64 65 66 67 68

Summary CHAPTER 3: LOOPS AND LOGIC

Making Decisions

71 71

Making Comparisons

72

The if Statement

72

Nested if Statements

76

Comparing

n

46 49

the Math Class Methods

Storing Characters

Bitwise

45

45

Mathematical Functions and Constants

Character Escape

43

44

Automatic Type Conversions in

Importing

43

44

Expressions

Explicit Casting The op=

41 42

Integer

Floating-Point

Types

40

Enumeration Values

79

Logical Operators

79

The Conditional Operator

84

CONTENTS

The switch Statement

85

The General Case of the switch Statement

Variable

87

Scope

91

Loops

93

Varieties of

Loop

93

Counting Using Floating-Point Nested

Values

99

Loops

100

The continue Statement

101

The Labeled continue Statement the break Statement in

Using

a

102 103

Loop

Assertions More

107

Complex

Assertions

109

Summary

110

CHAPTER 4: ARRAYS AND STRINGS

113 113

Arrays Array Variables

114

Defining

114

The

an

Length

Array of

Reusing Array

115

Array

an

Accessing Array

Elements

115

Variables

115 116

Initializing Arrays Using Arrays Arrays

of

119

Arrays

122

Arrays of Characters

126

127

Strings String Literals

127

Creating String Objects

128

Arrays

of

129

Strings

Operations

on

130

Strings

Joining Strings

130

Comparing Strings

134

Sequencing Strings

139

Accessing String Searching Strings

Characters

141

for Characters

143

Searching for Substrings

144

Extracting Substrings

146

Modified Versions of String Objects

Creating Using

151

Character Arrays from String Objects

the Collection-Based for

Obtaining the

Characters in

a

Loop

String

with as an

a

151 152

String

Array

of

Bytes

152

xllf

CONTENTS

Creating String Objects from Character Arrays Mutable Strings Creating StringBuffer Objects

154

The Capacity of

154

a

StringBuffer Object

a StringBuffer Object Changing the String Length Adding to a StringBuffer Object

for

the Position of

Finding

Replacing

a

a

Extracting

159

Characters from

a

Mutable

String

Other Mutable

Creating

a

String Operations String Object from a StringBuffer Object

160 160 161

163

Summary

165

CHAPTER 5: DEFINING CLASSES What Is

156

159

in the Buffer

Substring

156

158

Substring

Inserting Strings

165

a Class?

Fields in a Class Definition

166

Methods in a Class Definition

167

Accessing

168

Variables and Methods

169

Final Fields

169

Defining Classes Defining Methods

170 171

from a Method

Returning

171

The Parameter List

174

Class Methods

Defining

Accessing

Class Data Members in

a

Method

Initializing

176

Data Members

178

Constructors

179

The Default Constructor

Creating Objects Method

of

and Using

Defining

Class

180

Class

182

a

a

184

Overloading Constructors

Multiple

Duplicating Objects Using

185 a

Constructor

Using Objects Creating

174 175

The Variable this

a Point from Two Lines

187

188 191

Recursion

194

Understanding Packages

195

Packaging Up Your Classes Adding