Table of Contents
How to Use This Book xi
Barron's Essential 5 xiv
Introduction xvii
Diagnostic Test 1
Section I 5
Section II 35
Answer Key (Section I) 42
Diagnostic Chart 42
Answer Explanations 44
1 Tips for Taking the Exam 55
Tips for the Multiple-Choice Section 55
What is Tested? 55
Time Management 55
Guessing 56
The Java Quick Reference 56
An Active Pencil 56
Troubleshooting-What's Wrong with This Code? 57
Loop Tracing 57
Java Exceptions 57
Matrix Manipulation 58
Comparing Algorithms 58
Mechanics of Answering Multiple-Choice Questions 58
Tips for the Free-Response Section 59
What Is the Format? 59
What Is Tested? 59
What Types of Questions Might Be Asked? 59
Skill Focus in Free-Response Questions 59
The Java Quick Reference 60
Time Management 60
Grading the Free-Response Questions 61
Writing Code 61
Maximizing Your Score 62
2 Introductory Java Language Features 63
Packages and Classes 63
Javadoc Comments 65
Types and Identifiers 65
Identifiers 65
Built-in Types 65
Storage of Numbers 66
Hexadecimal and Octal Numbers 67
Final Variables 67
Operators 68
Arithmetic Operators 68
Relational Operators 69
Logical Operators 70
Assignment Operators 71
Increment and Decrement Operators 71
Operator Precedence 72
Input/Output 72
Input 72
Output 72
Escape Sequences 73
Control Structures 74
Decision-Making Control Structures 74
Iteration 76
Errors and Exceptions 80
Multiple-Choice Questions on Introductory Java Language Concepts 82
Answer Key 94
Answer Explanations 94
3 Classes and Objects 99
Objects 99
Classes 99
Public, Private, and Static 100
Methods 101
Headers 101
Types of Methods 102
Method Overloading 106
Scope 106
The this Keyword 107
References 108
Reference vs. Primitive Data Types 108
The Null Reference 109
Method Parameters 110
Multiple-Choice Questions on Classes and Objects 118
Answer Key 133
Answer Explanations 133
4 Inheritance and Polymorphism 139
Inheritance 139
Superclass and Subclass 139
Inheritance Hierarchy 139
Implementing Subclasses 140
Declaring Subclass Objects 145
Polymorphism 146
Dynamic Binding (Late Binding) 147
Using SUPER in a Subclass 149
Type Compatibility 150
Downcasting 150
Abstract Classes 151
Interfaces 151
Multiple-Choice Questions on Inheritance and Polymorphism 153
Answer Key 167
Answer Explanations 167
5 Some Standard Classes 171
The Object Class 171
The Universal Superclass 171
Methods in Object 171
The String Class 173
String Objects 173
Constructing String Objects 174
The Concatenation Operator 174
Comparison of String Objects 175
Other String Methods 176
Special Emphasis 177
Wrapper Classes 179
The Integer Class 179
The Double Class 179
Autoboxing and Unboxing 180
The Math Class 182
Random Numbers 183
Multiple-Choice Questions on Some Standard Classes 185
Answer Key 205
Answer Explanations 205
6 Program Design and Analysis 213
Software Development 213
Program Specification 213
Program Design 213
Program Implementation 214
Testing and Debugging 214
Program Maintenance 215
Object-Oriented Program Design 215
Identifying Classes 215
Identifying Behaviors 216
Determining Relationships Between Classes 216
UML Diagrams 217
Implementing Classes 217
Implementing Methods 218
Vocabulary Summary 224
Program Analysis 224
Program Correctness 224
Assertions 225
Efficiency 225
Multiple-Choice Questions on Program Design and Analysis 226
Answer Key 235
Answer Explanations 235
7 Arrays and Array Lists 239
One-Dimensional Arrays 239
Initialization 239
Length of Array 240
Traversing a One-Dimensional Array 241
Arrays as Parameters 241
Array Variables in a Class 246
Array of Class Objects 247
Analyzing Array Algorithms 248
Array Lists 249
The ArrayList Class 249
The Methods of ArrayList<E> 250
Autoboxing and Unboxing 250
Using ArrayList<E> 251
Two-Dimensional Arrays 257
Declarations 258
Matrix as Array of Row Arrays 258
Processing a Two-Dimensional Array 259
Two-Dimensional Array as Parameter 262
Multiple-Choice Questions on Arrays and Array Lists 265
Answer Key 301
Answer Explanations 301
8 Recursion 309
Recursive Methods 309
General Form of Simple Recursive Methods 310
Writing Recursive Methods 312
Analysis of Recursive Methods 313
Sorting Algorithms That Use Recursion 314
Recursive Helper Methods 314
Recursion in Two-Dimensional Grids 317
Sample Free-Response Question 1 319
Sample Free-Response Question 2 322
Multiple-Choice Questions on Recursion 326
Answer Key 337
Answer Explanations 337
9 Sorting and Searching 343
Sorts: Selection and Insertion Sorts 343
Selection Sort 343
Insertion Sort 344
Recursive Sorts: Merge Sort and Quicksort 344
Merge Sort 344
Quicksort 346
Sorting Algorithms in Java 347
Sequential Search 348
Binary Search 348
Analysis of Binary Search 350
Multiple-Choice Questions on Sorting and Searching 352
Answer Key 364
Answer Explanations 364
Practice Tests
Practice Test 1 371
Section I 373
Section II 400
Answer Key (Section I) 409
Answer Explanations 409
Practice Test 2 421
Section I 423
Section II 449
Answer Key (Section I) 459
Answer Explanations 459
Appendix: Glossary of Useful Computer Terms 471
Index 475