Chapter 1:An Introduction to Java / Java概述 1
1.1 Java as a Programming Platform/Java程序设计平台 1
1.2 The Java “White Paper” Buzzwords / Java“白皮书”中的口号 2
1.2.1 Simple/简单 3
1.2.2 Object-Oriented/面向对象 4
1.2.3 Distributed/分布式 4
1.2.4 Robust/健壮 4
1.2.5 Secure/安全 5
1.2.6 Architecture-Neutral/体系结构中立 6
1.2.7 Portable/可移植 6
1.2.8 Interpreted/解释型 7
1.2.9 High-Performance/高性能 7
1.2.1 0 Multithreaded/多线程 8
1.2.1 1 Dynamic/动态 8
1.3 Java Applets and the Internet/Java Applet与Internet 9
1.4 A Short History of Java / Java简史 10
1.5 Common Misconceptions about Java/对Java的常见误解 13
Chapter 2: The Java Programming Environment / Java编程环境 17
2.1 Installing the Java Development Kit /安装Java开发包(JDK) 18
2.1.1 Downloading the JDK/下载JDK 18
2.1.2 Setting up the JDK/设置JDK 20
2.1.3 Installing Source Files and Documentation/安装源文件和文档 22
2.2 Using the Command-Line Tools/使用命令行工具 23
2.3 Using an Integrated Development Environment/使用集成开发环境 29
2.4 JShell 32
Chapter 3: Fundamental Programming Structures in Java /Java的基本编程结构 37
3.1 A Simple Java Program/一个简单的Java程序 38
3.2 Comments/注释 41
3.3 Data Types/数据类型 42
3.3.1 Integer Types/整型 43
3.3.2 Floating-Point Types/浮点型 44
3.3.3 The char Type/ char类型 46
3.3.4 Unicode and the char Type/Unicode与char类型 47
3.3.5 The bool ean Type/ bool ean类型 48
3.4 Variables and Constants/变量和常量 48
3.4.1 Declaring Variables/声明变量 48
3.4.2 Initializing Variables/初始化变量 50
3.4.3 Constants/常量 51
3.4.4 Enumerated Types/枚举类型 52
3.5 Operators/运算符 52
3.5.1 Arithmetic Operators/算术运算符 52
3.5.2 Mathematical Functions and Constants/数学函数和常量 54
3.5.3 Conversions between Numeric Types/数值类型之间的转换 56
3.5.4 Casts/强制类型转换 57
3.5.5 Combining Assignment with Operators/组合赋值运算符 58
3.5.6 Increment and Decrement Operators/自增与自减运算符 58
3.5.7 Relational and boolean Operators/关系与boolean运算符 59
3.5.8 Bitwise Operators/位运算符 60
3.5.9 Parentheses and Operator Hierarchy/括号与运算符优先级 61
3.6 Strings/字符串 62
3.6.1 Substrings/子串 62
3.6.2 Concatenation/拼接 63
3.6.3 Strings Are Immutable/String是不可变的 63
3.6.4 Testing Strings for Equality/测试字符串是否相等 65
3.6.5 Empty and Null Strings/空串与null串 66
3.6.6 Code Points and Code Units/码位与编码单元 66
3.6.7 The String API/String API 68
3.6.8 Reading the Online API Documentation/阅读在线API文档 71
3.6.9 Building Strings/构建字符串 74
3.7 Input and Output/输入和输出 75
3.7.1 Reading Input/读取输入 75
3.7.2 Formatting Output/格式化输出 78
3.7.3 File Input and Output/文件输入和输出 83
3.8 Control Flow/控制流 86
3.8.1 Block Scope/块作用域 86
3.8.2 Conditional Statements/条件语句 87
3.8.3 Loops/循环 91
3.8.4 Determinate Loops/确定性循环 95
3.8.5 Multiple Selections——The switch Statement/多重选择:switch语句 99
3.8.6 Statements That Break Control Flow/用于跳出控制流的语句 102
3.9 Big Numbers/大数 105
3.1 0 Arrays/数组 108
3.1 0.1 Declaring Arrays/声明数组 108
3.1 0.2 Accessing Array Elements/访问数组元素 109
3.1 0.3 The “for each” Loop/“for each”循环 110
3.1 0.4 Array Copying/数组复制 111
3.1 0.5 Command-Line Parameters/命令行参数 112
3.1 0.6 Array Sorting/数组排序 113
3.1 0.7 Multidimensional Arrays/多维数组 116
3.1 0.8 Ragged Arrays/不规则数组 120
Chapter 4: Objects and Classes /对象与类 125
4.1 Introduction to Object-Oriented Programming 126
面向对象编程简介 126
4.1.1 Classes/类 127
4.1.2 Objects/对象 128
4.1.3 Identifying Classes/识别类 129
4.1.4 Relationships between Classes/类之间的关系 129
4.2 Using Predefined Classes/使用预定义类 131
4.2.1 Objects and Object Variables/对象与对象变量 132
4.2.2 The Local Date Class of the Java Library/Java库中的LocalDate类 135
4.2.3 Mutator and Accessor Methods/更改器方法与访问器方法 138
4.3 Defining Your Own Classes/定义自己的类 141
4.3.1 An Employee Class/Employee类 142
4.3.2 Use of Multiple Source Files/使用多个源文件 145
4.3.3 Dissecting the Employee Class/分析Employee类 146
4.3.4 First Steps with Constructors/从构造器开始 146
4.3.5 Declaring Local Variables with var/使用var声明局部变量 148
4.3.6 Working with null References/使用null引用 148
4.3.7 Implicit and Explicit Parameters/隐式参数与显式参数 150
4.3.8 Benefits of Encapsulation/封装的好处 151
4.3.9 Class-Based Access Privileges/基于类的访问权限 154
4.3.1 0 Private Methods/私有方法 155
4.3.1 1 Final Instance Fields/final实例字段 155
4.4 Static Fields and Methods/静态的字段与方法 156
4.4.1 Static Fields/静态字段 156
4.4.2 Static Constants/静态常量 157
4.4.3 Static Methods/静态方法 158
4.4.4 Factory Methods/工厂方法 159
4.4.5 The main Method/main方法 160
4.5 Method Parameters/方法参数 163
4.6 Object Construction/对象构建 170
4.6.1 Overloading/重载 170
4.6.2 Default Field Initialization/默认字段初始化 171
4.6.3 The Constructor with No Arguments/无参构造器 172
4.6.4 Explicit Field Initialization/显式字段初始化 173
4.6.5 Parameter Names/参数名 174
4.6.6 Calling Another Constructor/调用另一个构造器 175
4.6.7 Initialization Blocks/初始化块 175
4.6.8 Object Destruction and the finalize Method/对象析构与finalize方法 180
4.7 Packages/包 180
4.7.1 Package Names/包名 181
4.7.2 Class Importation/导入类 181
4.7.3 Static Imports/静态导入 183
4.7.4 Addition of a Class into a Package/将类添加到某个包中 184
4.7.5 Package Access/包访问权限 187
4.7.6 The Class Path/类路径 189
4.7.7 Setting the Class Path/设置类路径 191
4.8 JAR Files / JAR文件 192
4.8.1 Creating JAR files/创建JAR文件 192
4.8.2 The Manifest/清单文件 193
4.8.3 Executable JAR Files/可执行的JAR文件 194
4.8.4 Multi-Release JAR Files/支持多个Java版本的JAR文件 195
4.8.5 A Note about Command-Line Options/关于命令行选项的说明 197
4.9 Documentation Comments/文档注释 198
4.9.1 Comment Insertion/插入注释 199
4.9.2 Class Comments/类注释 199
4.9.3 Method Comments/方法注释 200
4.9.4 Field Comments/字段注释 201
4.9.5 General Comments/通用注释 201
4.9.6 Package Comments/包注释 202
4.9.7 Comment Extraction/提取注释 203
4.10 Class Design Hints/类设计建议 204
Chapter 5: Inheritance/继承 207
5.1 Classes, Superclasses, and Subclasses/类、超类与子类 208
5.1.1 Defining Subclasses/定义子类 208
5.1.2 Overriding Methods/覆盖方法 210
5.1.3 Subclass Constructors/子类构造器 211
5.1.4 Inheritance Hierarchies/继承层次 216
5.1.5 Polymorphism/多态 217
5.1.6 Understanding Method Calls/理解方法调用 218
5.1.7 Preventing Inheritance: Final Classes and Methods/阻止继承:final修饰的类和方法 221
5.1.8 Casting/强制类型转换 223
5.1.9 Abstract Classes/抽象类 225
5.1.10 Protected Access/受保护访问 231
5.2 Object: The Cosmic Superclass/Object:所有类的超类 232
5.2.1 Variables of Type Object/ Object类型的变量 232
5.2.2 The equals Method/equals方法 233
5.2.3 Equality Testing and Inheritance/相等测试与继承 234
5.2.4 The hashCode Method/hashCode方法 238
5.2.5 The toString Method/toString方法 241
5.3 Generic Array Lists/泛型数组列表 248
5.3.1 Declaring Array Lists/声明数组列表 248
5.3.2 Accessing Array List Elements/访问数组列表的元素 251
5.3.3 Compatibility between Typed and Raw Array Lists/类型化和原始数组列表的兼容性 255
5.4 Object Wrappers and Autoboxing/对象包装器与自动装箱 256
5.5 Methods with a Variable Number of Parameters/参数数量可变的方法 260
5.6 Enumeration Classes/枚举类 261
5.7 Reflection/反射 264
5.7.1 The Class Class/Class类 264
5.7.2 A Primer on Declaring Exceptions/初步了解如何声明异常 267
5.7.3 Resources/资源 268
5.7.4 Using Reflection to Analyze the Capabilities of Classes/使用反射分析类的能力 271
5.7.5 Using Reflection to Analyze Objects at Runtime/使用反射在运行时分析对象 277
5.7.6 Using Reflection to Write Generic Array Code/使用反射编写泛型数组代码 283
5.7.7 Invoking Arbitrary Methods and Constructors/调用任意方法和构造器 286
5.8 Design Hints for Inheritance/继承的设计建议 290
Chapter 6: Interfaces, Lambda Expressions, and Inner Classes /接口、 Lambda表达式和内部类 295
6.1 Interfaces/接口 296
6.1.1 The Interface Concept/接口的概念 296
6.1.2 Properties of Interfaces/接口的特性 303
6.1.3 Interfaces and Abstract Classes/接口与抽象类 305
6.1.4 Static and Private Methods/静态和私有方法 306
6.1.5 Default Methods/默认方法 307
6.1.6 Resolving Default Method Conflicts/解决默认方法的冲突 308
6.1.7 Interfaces and Callbacks/接口与回调 310
6.1.8 The Comparator Interface / Comparator接口 313
6.1.9 Object Cloning/对象克隆 314
6.2 Lambda Expressions / Lambda表达式 322
6.2.1 Why Lambdas?/为什么引入Lambda表达式 322
6.2.2 The Syntax of Lambda Expressions/Lambda表达式的语法 323
6.2.3 Functional Interfaces/函数式接口 326
6.2.4 Method References/方法引用 328
6.2.5 Constructor References/构造器引用 332
6.2.6 Variable Scope/变量作用域 333
6.2.7 Processing Lambda Expressions/处理Lambda表达式 335
6.2.8 More about Comparators/再谈Comparator 339
6.3 Inner Classes/内部类 340
6.3.1 Use of an Inner Class to Access Object State/使用内部类访问对象状态 341
6.3.2 Special Syntax Rules for Inner Classes/内部类的特殊语法规则 345
6.3.3 Are Inner Classes Useful? Actually Necessary? Secure?/内部类是否有用、必要和安全 346
6.3.4 Local Inner Classes/局部内部类 349
6.3.5 Accessing Variables from Outer Methods/从外部方法访问变量 350
6.3.6 Anonymous Inner Classes /匿名内部类 352
6.3.7 Static Inner Classes/静态内部类 356
6.4 Service Loaders/服务加载器 360
6.5 Proxies/代理 362
6.5.1 When to Use Proxies/何时使用代理 363
6.5.2 Creating Proxy Objects/创建代理对象 363
6.5.3 Properties of Proxy Classes/代理类的特性 368
Chapter 7: Exceptions, Assertions, and Logging /异常、断言与日志 371
7.1 Dealing with Errors/处理错误 372
7.1.1 The Classification of Exceptions/异常分类 373
7.1.2 Declaring Checked Exceptions/声明检查型异常 375
7.1.3 How to Throw an Exception/如何抛出异常 378
7.1.4 Creating Exception Classes/创建异常类 380
7.2 Catching Exceptions/捕获异常 381
7.2.1 Catching an Exception/捕获一个异常 381
7.2.2 Catching Multiple Exceptions/捕获多个异常 383
7.2.3 Rethrowing and Chaining Exceptions/再次抛出异常与异常链 384
7.2.4 The final l y Clause/finally子句 386
7.2.5 The try-with-Resources Statement/try-with-resources语句 389
7.2.6 Analyzing Stack Trace Elements/分析栈轨迹元素 391
7.3 Tips for Using Exceptions/异常使用技巧 396
7.4 Using Assertions/使用断言 399
7.4.1 The Assertion Concept/断言的概念 399
7.4.2 Assertion Enabling and Disabling/启用和禁用断言 400
7.4.3 Using Assertions for Parameter Checking/使用断言检查参数 401
7.4.4 Using Assertions for Documenting Assumptions/使用断言保证文档中假定成立的条件 402
7.5 Logging/日志 403
7.5.1 Basic Logging/基本日志 404
7.5.2 Advanced Logging/高级日志 405
7.5.3 Changing the Log Manager Configuration/修改日志管理器配置 407
7.5.4 Localization/本地化 409
7.5.5 Handlers/处理器 410
7.5.6 Filters/过滤器 414
7.5.7 Formatters/格式化器 415
7.5.8 A Logging Recipe/常见日志操作总结 415
7.6 Debugging Tips/调试技巧 425