SKIP THE SHIPPING
Use code NOSHIP during checkout to save 40% on eligible eBooks, now through January 5. Shop now.
Rough Cuts are manuscripts that are developed but not yet published, available through Safari. Rough Cuts provide you access to the very latest information on a given topic and offer you the opportunity to interact with the author to influence the final publication.
This is a working draft of a pre-release book. It is available before the published date as part of the Rough Cuts service.
This book will help you prepare for and pass the Sun Certified Programmer for the Java Platform SE 6 (CX-310-065) Exam. It is written for any experienced programmer (with or without previous knowledge of Java) interested in mastering the Java programming language and passing the SCJP 1.6 Exam.A Programmer’s Guide to Java™ SCJP Certification, Third Edition, provides detailed coverage of all exam topics and objectives, readily runnable code examples, programming exercises, extensive review questions, and a new mock exam. In addition, as a comprehensive primer to the Java programming language, this book is an invaluable reference tool.
This new edition has been thoroughly updated to focus on the latest version of the exam (CX-310-065). In particular, it contains in-depth explanations of the language features. Their usage is illustrated by way of code scenarios, as required by the exam. The companion Web site (www.ii.uib.no/~khalid/pgjc3e/) contains a version of the SCJP 1.6 Exam Simulator developed by the authors. The site also contains the complete source code for all the book’s examples, as well as solutions to the programming exercises.
What you will find in this book:
List of Figures xxiii
List of Tables xxvii
List of Examples xxix
Foreword xxxv
Preface xxxvii
Chapter 1: Basics of Java Programming 1
1.1 Introduction 2
1.2 Classes 2
1.3 Objects 4
1.4 Instance Members 6
1.5 Static Members 7
1.6 Inheritance 10
1.7 Aggregation 12
1.8 Tenets of Java 13
1.9 Java Programs 15
1.10 Sample Java Application 15
Chapter 2: Language Fundamentals 19
2.1 Basic Language Elements 20
2.2 Primitive Data Types 28
2.3 Variable Declarations 31
2.4 Initial Values for Variables 33
Chapter Summary 37
Programming Exercise 37
Chapter 3: Declarations 39
3.1 Class Declarations 40
3.2 JavaBeans Standard 41
3.3 Method Declarations 44
3.4 Constructors 48
3.5 Enumerated Types 54
3.6 Arrays 69
3.7 Parameter Passing 81
3.8 Variable Arity Methods 90
Chapter Summary 100
Programming Exercises 101
Chapter 4: Access Control 103
4.1 Java Source File Structure 104
4.2 Packages 105
4.3 Searching for Classes 117
4.4 The JAR Utility 120
4.5 System Properties 122
4.6 Scope Rules 129
4.7 Accessibility Modifiers for Top-Level Type Declarations 132
4.8 Other Modifiers for Classes 135
4.9 Member Accessibility Modifiers 138
4.10 Other Modifiers for Members 146
Chapter Summary 157
Programming Exercise 157
Chapter 5: Operators and Expressions 159
5.1 Conversions 160
5.2 Type Conversion Contexts 163
5.3 Precedence and Associativity Rules for Operators 166
5.4 Evaluation Order of Operands 168
5.5 The Simple Assignment Operator = 169
5.6 Arithmetic Operators: *, /, %, +, - 174
5.7 The Binary String Concatenation Operator + 185
5.8 Variable Increment and Decrement Operators: ++, -- 186
5.9 Boolean Expressions 190
5.10 Relational Operators: <, <=, >, >= 190
5.11 Equality 191
5.12 Boolean Logical Operators: !, ^, &, | 194
5.13 Conditional Operators: &&, || 196
5.14 The Conditional Operator: ?: 201
5.15 Other Operators: new, [], instanceof 201
Chapter Summary 202
Programming Exercise 202
Chapter 6: Control Flow 203
6.1 Overview of Control Flow Statements 204
6.2 Selection Statements 204
6.3 Iteration Statements 216
6.4 Transfer Statements 223
6.5 Stack-Based Execution and Exception Propagation 235
6.6 Exception Types 239
6.7 Exception Handling: try, catch, and finally 245
6.8 The throw Statement 255
6.9 The throws Clause 257
6.10 Assertions 265
Chapter Summary 279
Programming Exercises 279
Chapter 7: Object-Oriented Programming 283
7.1 Single Implementation Inheritance 284
7.2 Overriding Methods 288
7.3 Hiding Members 294
7.4 The Object Reference super 295
7.5 Chaining Constructors Using this() and super() 302
7.6 Interfaces 309
7.7 Arrays and Subtyping 317
7.8 Reference Values and Conversions 319
7.9 Reference Value Assignment Conversions 320
7.10 Method Invocation Conversions Involving References 323
7.11 Reference Casting and the instanceof Operator 327
7.12 Polymorphism and Dynamic Method Lookup 340
7.13 Inheritance Versus Aggregation 342
7.14 Basic Concepts in Object-Oriented Design 345
Chapter Summary 349
Programming Exercises 349
Chapter 8: Nested Type Declarations 351
8.1 Overview of Nested Type Declarations 352
8.2 Static Member Types 355
8.3 Non-Static Member Classes 359
8.4 Loca