Table of contents for A programmer's guide to Java certification : a comprehensive primer / Khalid A. Mughal, Rolf W. Rasmussen.


Bibliographic record and links to related information available from the Library of Congress catalog. Note: Contents data are machine generated based on pre-publication information provided by the publisher. Contents may have variations from the printed book or be incomplete or contain other coding.


Counter
Contents
   Foreword 	vii
   Preface [draft] 	ix
Writing the Second Edition 	ix
About this book 	x
Using the book 	xi
Book web sites 	xiii
Request for feedback 	xiii
About the Authors 	xiv
Acknowledgments (First Edition) 	xv
Acknowledgments (Second Edition) 	xv
   List of Tables 	xxx
   List of Examples 	xxxii
   List of Figures 	xxxv
	1 	Basics of Java Programming 	1
1.1 	Introduction 	2
1.2 	Classes 	2
Declaring Members: Fields and Methods 	3
1.3 	Objects 	4
Class Instantiation 	4
Object References 	5
1.4 	Instance Members 	6
Invoking Methods 	6
1.5 	Static Members 	7
1.6 	Inheritance 	10
1.7 	Aggregation 	12
1.8 	Tenets of Java 	12
Review Questions  	13
1.9 	Java Programs 	14
1.10 	Sample Java Application 	15
Essential Elements of a Java Application 	15
Compiling and Running an Application 	16
Review Questions  	17
Chapter Summary  	17
Programming Exercises  	17
	2 	Language Fundamentals 	19
2.1 	Basic Language Elements 	20
Lexical Tokens 	20
Identifiers 	20
Keywords 	21
Literals 	21
Integer Literals 	22
Floating-point Literals 	23
Boolean Literals 	23
Character Literals 	23
String Literals 	25
White Spaces 	26
Comments 	26
Review Questions  	27
2.2 	Primitive Data Types 	28
Integer Types 	29
Character Type 	29
Floating-point Types 	29
Boolean Type 	30
Review Questions  	31
2.3 	Variable Declarations 	31
Declaring and Initializing Variables 	31
Object Reference Variables 	32
Lifetime of Variables 	33
2.4 	Initial Values for Variables 	33
Default Values for Fields 	33
Initializing Local Variables of Primitive Data Types 	34
Initializing Local Reference Variables 	35
Review Questions  	36
2.5 	Java Source File Structure 	36
Review Questions  	38
2.6 	The main() Method 	38
Review Questions  	39
Chapter Summary  	39
Programming Exercises  	40
	3 	Operators and Assignments 	41
3.1 	Precedence and Associativity Rules for Operators 	42
3.2 	Evaluation order of operands 	43
3.3 	Conversions 	44
Unary Cast Operator: (type) 	44
Narrowing and Widening Conversions 	44
Numeric Promotions 	45
Type Conversion Contexts 	46
3.4 	Simple Assignment Operator = 	46
Assigning Primitive Values 	47
Assigning References 	47
Multiple Assignments 	48
Numeric Type Conversions on Assignment 	48
Review Questions  	50
3.5 	Arithmetic Operators: *, /, %, +, - 	51
Arithmetic Operator Precedence and Associativity 	51
Evaluation Order in Arithmetic Expressions 	51
Range of Numeric Values 	52
Unary Arithmetic Operators: -, + 	54
Multiplicative Binary Operators: *, /, % 	54
Additive Binary Operators: +, - 	56
Numeric Promotions in Arithmetic Expressions 	57
Arithmetic Compound Assignment Operators: *=, /=, %=, +=, -= 	59
Review Questions  	61
3.6 	The Binary String Concatenation Operator + 	62
3.7 	Variable Increment and Decrement Operators: ++, -- 	63
Increment Operator ++ 	63
Decrement Operator -- 	64
Review Questions  	65
3.8 	Boolean Expressions 	67
3.9 	Relational Operators: , >= 	67
3.10 	Equality 	68
Primitive Data Value Equality: ==, != 	68
Object Reference Equality: ==, != 	69
Object Value Equality 	70
3.11 	Boolean Logical Operators: !, ^, &, | 	70
Operand Evaluation for Boolean Logical Operators 	71
Boolean Logical Compound Assignment Operators: &=, ^=, |= 	72
3.12 	Conditional Operators: &&, || 	72
Short-circuit Evaluation 	73
Review Questions  	74
3.13 	Integer Bitwise Operators: 
, &, |, ^ 	76
Bitwise Compound Assignment Operators: &=, ^=, |= 	78
3.14 	Shift Operators: >, >>> 	79
The Shift-left Operator << 	80
The Shift-right-with-sign-fill Operator >> 	81
The Shift-right-with-zero-fill Operator >>> 	82
Shift Compound Assignment Operators: >=, >>>= 	83
3.15 	The Conditional Operator ? : 	84
3.16 	Other Operators: new, [], instanceof 	84
Review Questions  	85
3.17 	Parameter Passing 	86
3.18 	Passing Primitive Data Values 	88
3.19 	Passing Object Reference Values 	89
3.20 	Passing Array References 	91
3.21 	Array Elements as Actual Parameters 	93
3.22 	final Parameters 	94
3.23 	Program Arguments 	95
Review Questions  	96
Chapter Summary  	97
Programming Exercises  	98
	4 	Declarations and Access Control 	101
4.1 	Arrays 	102
Declaring Array Variables 	102
Constructing an Array 	103
Initializing an Array 	104
Using an Array 	105
Anonymous Arrays 	106
Multidimensional Arrays 	108
Review Questions  	111
4.2 	Defining Classes 	113
4.3 	Defining Methods 	114
Statements 	115
Instance Methods and Object Reference this 	116
Method Overloading 	117
4.4 	Constructors 	119
Default Constructor 	120
Overloaded Constructors 	121
4.5 	Scope Rules 	122
Class Scope for Members 	122
Block Scope for Local Variables 	125
Review Questions  	126
4.6 	Packages 	128
Defining Packages 	129
Using Packages 	130
Compiling and Running Code from Packages 	131
4.7 	Accessibility Modifiers for Top-level Classes and Interfaces 	133
4.8 	Other Modifiers for Classes 	136
abstract Classes 	136
final Classes 	137
Review Questions  	138
4.9 	Member Accessibility Modifiers 	139
public Members 	140
protected Members 	141
Default Accessibility for Members 	143
private Members 	144
Review Questions  	145
4.10 	Other Modifiers for Members 	146
static Members 	146
final Members 	148
abstract Methods 	149
synchronized Methods 	150
native Methods 	150
transient Fields 	151
volatile Fields 	152
Review Questions  	153
Chapter Summary  	156
Programming Exercises  	156
	5 	Control Flow, Exception Handling and Assertions 	159
5.1 	Overview of Control Flow Statements 	160
5.2 	Selection Statements 	160
Simple if Statement 	160
if-else Statement 	161
switch Statement 	163
Review Questions  	167
5.3 	Iteration Statements 	169
while Statement 	169
do-while Statement 	170
for Statement 	170
5.4 	Transfer Statements 	173
Labeled Statements 	173
break Statement 	174
continue Statement 	176
return Statement 	178
Review Questions  	179
5.5 	Stack-based Execution and Exception Propagation 	183
5.6 	Exception Types 	187
Class Exception 	189
Class RuntimeException 	189
Class Error 	189
Checked and Unchecked Exceptions 	190
Defining New Exceptions 	190
5.7 	Exception Handling: try, catch and finally 	191
try Block 	192
catch Block 	192
finally Block 	198
5.8 	throw Statement 	202
5.9 	throws Clause 	203
Review Questions  	206
5.10 	Assertions 	211
assert Statement and AssertionError Class 	211
Compiling Assertions 	214
Runtime Enabling and Disabling of Assertions 	215
Using Assertions 	218
Review Questions  	222
Chapter Summary  	224
Programming Exercises  	225
	6 	Object-oriented Programming 	229
6.1 	Single Implementation Inheritance 	230
Object-oriented Programming Concepts 	233
Review Questions  	237
6.2 	Overriding and Hiding Members 	237
Instance Method Overriding 	237
Field Hiding 	240
Static Method Hiding 	241
Overriding vs. Overloading 	241
Object Reference super 	242
Review Questions  	245
6.3 	Chaining Constructors using this() and super() 	247
this() Constructor Call 	248
super() Constructor Call 	250
Review Questions  	254
6.4 	Interfaces 	255
Defining Interfaces 	255
Method Prototype Declarations 	256
Implementing Interfaces 	257
Extending Interfaces 	259
Constants in Interfaces 	260
Review Questions  	261
6.5 	Completing the Type Hierarchy 	263
6.6 	Assigning, Passing and Casting Reference Values 	265
Reference Value Assignment Conversions 	267
Parameter Passing Conversions 	268
Reference Casting and instanceof Operator 	269
Converting References of Class and Interface Types 	273
Review Questions  	273
6.7 	Polymorphism and Dynamic Method Lookup 	277
 	279
6.8 	Inheritance vs. Aggregation 	280
Encapsulation 	280
Choosing between Inheritance and Aggregation 	280
Review Questions  	284
Chapter Summary  	285
Programming Exercises  	285
	7 	Nested Classes and Interfaces 	287
7.1 	Overview of Nested Classes and Interfaces 	288
7.2 	Static Member Classes and Interfaces 	291
Declaring and Using Static Member Classes and Interfaces 	291
Accessing Members in Enclosing Context 	293
7.3 	Non-static Member Classes 	296
Instantiating Non-static Member Classes 	297
Accessing Members in Enclosing Context 	298
Review Questions  	303
7.4 	Local Classes 	306
Accessing Declarations in Enclosing Context 	308
Instantiating Local Classes 	309
7.5 	Anonymous Classes 	312
Extending an Existing Class 	312
Implementing an Interface 	314
Instantiating Anonymous Classes 	315
Accessing Declarations in Enclosing Context 	315
Review Questions  	316
Chapter Summary  	318
Programming Exercise  	318
	8 	Object Lifetime 	321
8.1 	Garbage Collection 	322
Reachable References 	322
Facilitating Garbage Collection 	325
Object Finalization 	328
Finalizer Chaining 	329
Invoking Garbage Collection 	331
Review Questions  	334
8.2 	Initializers 	335
Field Initializer Expressions 	336
Static Initializer Blocks 	340
Instance Initializer Blocks 	343
Constructing Initial Object State 	346
Review Questions  	349
Chapter Summary  	352
	9 	Threads 	353
9.1 	Multitasking 	354
9.2 	Overview of Threads 	354
The Main Thread 	355
9.3 	Thread Creation 	355
Implementing the Runnable Interface 	356
Extending the Thread Class 	359
Review Questions  	362
9.4 	Synchronization 	363
Locks 	363
Synchronized Methods 	364
Synchronized Blocks 	367
Review Questions  	369
9.5 	Thread Transitions 	371
Thread States 	371
Thread Priorities 	372
Thread Scheduler 	373
Running and Yielding 	373
Sleeping and Waking Up 	374
Waiting and Notifying 	374
Joining 	381
Blocking for I/O 	383
Thread Termination 	384
Deadlocks 	385
Review Questions  	387
Chapter Summary  	389
Programming Exercises  	390
	10 	Fundamental Classes 	391
10.1 	Overview of the java.lang package 	392
10.2 	The Object Class 	392
Review Questions  	396
10.3 	The Wrapper Classes 	397
Common Wrapper Class Constructors 	398
Common Wrapper Class Utility Methods 	398
Numeric Wrapper Classes 	401
Character Class 	404
Boolean Class 	404
Review Questions  	404
10.4 	The Math Class 	406
Miscellaneous Rounding Functions 	406
Exponential Functions 	408
Trigonometry Functions 	409
Pseudorandom Number Generator	 	409
Review Questions  	410
10.5 	The String Class 	411
Creating and Initializing Strings 	412
Reading Characters from a String 	415
Comparing Strings 	416
Character Case in a String 	418
Concatenation of Strings 	418
Searching for Characters and Substrings 	419
Extracting Substrings 	421
Converting Primitive Values and Objects to Strings 	421
Review Questions  	422
10.6 	The StringBuffer Class 	425
Constructing String Buffers 	426
Reading and Changing Characters in String Buffers 	427
Constructing Strings from String Buffers 	427
Appending, Inserting and Deleting Characters in String Buffers 	427
Controlling String Buffer Capacity 	430
Review Questions  	430
Chapter Summary  	432
Programming Exercises  	432
	11 	Collections and Maps 	433
11.1 	The Collections Framework 	434
Core interfaces 	434
Implementations 	436
11.2 	Collections 	438
Basic Operations 	439
Bulk Operations 	439
Array Operations 	440
Iterators 	440
Review Questions  	443
11.3 	Sets 	443
HashSet and LinkedHashSet 	444
11.4 	Lists 	447
ArrayList, LinkedList and Vector 	449
Review Questions  	452
11.5 	Maps 	454
Basic Operations 	455
Bulk Operations 	455
Collection Views 	456
HashMap, LinkedHashMap and Hashtable 	456
11.6 	Sorted Sets and Sorted Maps 	460
The Comparator Interface 	460
The Comparable Interface 	460
The SortedSet Interface 	463
The SortedMap Interface 	464
TreeSet and TreeMap 	464
Review Questions  	467
11.7 	Implementing the equals(), hashCode() and compareTo() methods 	468
The equals() method 	469
The hashCode() method 	479
The compareTo() method 	484
11.8 	Working with Collections 	488
Synchronized Collection Decorators 	489
Unmodifiable Collection Decorators 	489
Sorting Collections 	490
Searching in Collections 	490
Singleton Collections 	490
Other Utility Methods in the Collections Class 	491
Utility Methods in the Arrays Class 	492
Abstract Implementations 	493
Review Questions  	493
Chapter Summary  	495
Programming Exercise  	495
	A 	Taking the SCPJ2 1.4 Exam 	497
A.1 	Preparing for the programmer exam 	497
A.2 	Registering for the exam 	498
Obtaining an exam voucher 	498
Signing up for the test 	499
Contact information 	499
After taking the exam 	499
A.3 	How the examination is conducted 	499
The testing locations 	499
Utilizing the allotted time 	499
The exam program 	500
A.4 	The questions 	500
Types of questions asked 	500
Types of answers expected 	501
Topics covered by the questions 	502
A.5 	Moving on to the developer exam 	503
	B 	Objectives for the SCPJ2 1.4 Exam 	505
	C 	Objectives for the Java 2 Platform Upgrade Exam 	513
	D 	Annotated Answers to Review Questions 	519
	E 	Solutions to Programming Exercises 	553
	F 	Sample Exam 	569
	G 	Number Systems and Number Representation 	603
G.1 	Number Systems 	603
Binary, Octal and Hexadecimal Number System 	603
Converting Binary Numbers to Decimals 	604
Converting Octal and Hexadecimal Numbers to Decimals 	604
G.2 	Relationship between Binary, Octal and Hex Numbers 	605
G.3 	Converting Decimals 	606
Converting Decimals to Binary Numbers 	606
Converting Decimals to Octal and Hexadecimal Numbers 	607
G.4 	Representing Integers 	607
Calculating 2's Complement 	608
	H 	Using the CD 	611
H.1 	Contents of the CD 	611
H.2 	Installing the Programs 	611
H.3 	Using the Programs 	611
	Index 	 	613
 

Library of Congress Subject Headings for this publication: