Mehr lesen
Preface xxi Chapter 1: A Quick Tour 1 1.1 Getting Started 1 1.2 Variables 3 1.3 Comments in Code 6 1.4 Named Constants 7 1.5 Unicode Characters 8 1.6 Flow of Control 9 1.7 Classes and Objects 12 1.8 Methods and Parameters 15 1.9 Arrays 18 1.10 String Objects 21 1.11 Extending a Class 24 1.12 Interfaces 27 1.13 Generic Types 29 1.14 Exceptions 32 1.15 Annotations 35 1.16 Packages 36 1.17 The Java Platform 38 1.18 Other Topics Briefly Noted 39 Chapter 2: Classes and Objects 41 2.1 A Simple Class 42 2.2 Fields 44 2.3 Access Control 47 2.4 Creating Objects 49 2.5 Construction and Initialization 50 2.6 Methods 56 2.7 this 68 2.8 Overloading Methods 69 2.9 Importing Static Member Names 71 2.10 The main Method 73 2.11 Native Methods 74 Chapter 3: Extending Classes 75 3.1 An Extended Class 76 3.2 Constructors in Extended Classes 80 3.3 Inheriting and Redefining Members 84 3.4 Type Compatibility and Conversion 90 3.5 What protected Really Means 93 3.6 Marking Methods and Classes final 96 3.7 Abstract Classes and Methods 97 3.8 The Object Class 99 3.9 Cloning Objects 101 3.10 Extending Classes: How and When 107 3.11 Designing a Class to Be Extended 108 3.12 Single Inheritance versus Multiple Inheritance 114 Chapter 4: Interfaces 117 4.1 A Simple Interface Example 118 4.2 Interface Declarations 120 4.3 Extending Interfaces 122 4.4 Working with Interfaces 126 4.5 Marker Interfaces 130 4.6 When to Use Interfaces 131 Chapter 5: Nested Classes and Interfaces 133 5.1 Static Nested Types 133 5.2 Inner Classes 136 5.3 Local Inner Classes 142 5.4 Anonymous Inner Classes 144 5.5 Inheriting Nested Types 146 5.6 Nesting in Interfaces 148 5.7 Implementation of Nested Types 149 Chapter 6: Enumeration Types 151 6.1 A Simple Enum Example 151 6.2 Enum Declarations 152 6.3 Enum Constant Declarations 154 6.4 java.lang.Enum 159 6.5 To Enum or Not 160 Chapter 7: Tokens, Values, and Variables 161 7.1 Lexical Elements 161 7.2 Types and Literals 166 7.3 Variables 169 7.4 Array Variables 173 7.5 The Meanings of Names 178 Chapter 8: Primitives as Types 183 8.1 Common Fields and Methods 184 8.2 Void 187 8.3 Boolean 187 8....