Java语言导学(英文版·第6版)
作者 : [美]雷蒙德·盖拉多(Raymond Gallardo) 斯科特·霍梅尔(Scott Hommel) 索娅·坎南(Sowmya Kannan) 琼尼·戈登(Joni Gordon) 沙伦·比奥卡·扎卡沃(Sharon Biocca Zakhour)著
译者 :
丛书名 : 经典原版书库
出版日期 : 2016-05-03
ISBN : 978-7-111-53433-4
定价 : 129.00元
教辅资源下载
扩展信息
语种 : 英文
页数 : 836
开本 : 16
原书名 : The Java Tutorial: A Short Course on the Basics,Sixth Edition
原出版社: Pearson Education Asia
属性分类: 教材
包含CD :
绝版 :
图书简介

本书是Oracle公司指定的Java语言入门教程,由Java语言和平台开发团队的多位成员亲自撰写。并由众多世界级Java专家精心评审,确保了准确性和及时性,多年来引领了一批又一批程序员步入Java殿堂。

图书特色

本书由Oracle公司Java语言和平台开发团队资深技术文档撰写人基于Java SE 8版本编写,并引用该版本的应用编程接口(API),经过了众多世界级Java专家细心审校,有力地保证了权威性和准确性,内容全面翔实,文字简洁易懂,可读性强,被视为Java语言编程的核心教程。
书中主要介绍了面向对象编程的概念、语言基础、类和对象、注解、接口和继承、泛型、包、数字和字符串、异常、基本I/O和NIO.2、集合、并发、正则表达式、平台环境、在JAR文件中打包程序、Java Web Start、applet、Java富互联网应用系统、日期/时间API等内容,涵盖了Lambda表达式、类型注解、默认方法、聚合操作、日期/时间API等Java SE 8的新特性,更新了限制恶意小程序的攻击和RIA等相关内容。每章的后面都有问题和练习,附录中还给出Java编程语言认证考试的相关内容。

作者简介
雷蒙德·盖拉多(Raymond Gallardo) Oracle公司高级技术文档工程师,曾担任过高校教师和IBM技术作家。他拥有多伦多大学计算机和英语双学士学位,纽约城市大学创意写作硕士学位。
斯科特·霍梅尔(Scott Hommel) Oracle公司高级技术文档工程师,负责Java SE文档工作。过去15年,他编写了大量Java SE和相关技术的教程、技术文章和核心文档。
索娅·坎南(Sowmya Kannan) 在Oracle公司Java SE技术文档编写团队承担多项工作,包括规划、编写、与开发团队沟通等。她有超过15年从事设计、开发和文档化Java平台、基于Java的中间件、Web应用程序的工作经历。
琼尼·戈登(Joni Gordon) Oracle公司首席技术文档工程师。她为Java SE和JavaFX的技术文档编写做出了杰出贡献。她有超过15年技术文档工程师的经历,技术背景是企业应用软件开发。
沙伦·比奥卡·扎卡沃(Sharon Biocca Zakhour) 曾担任Oracle公司和Sun公司首席技术文档工程师,先前就职于Sun公司,Sun并入Oracle后就职于Oracle。她曾编写过《The Java Tutorial, Fourth Edition》和《The JFC Swing Tutorial, Second Edition》。她毕业于加州大学伯克利分校,获得计算机科学学士学位,具有30年的程序员、开发支持工程师和技术文档工程师经历。

图书前言

自从2010年年初Oracle公司收购Sun公司以来,Java语言迎来了激动人心的时代。正如Java Community Process计划的活动所印证的,Java语言处于持续发展之中。本书是《The Java Tutorial》第6版,基于Java SE(Java Platform Standard Edition)版本 8并引用该版本的应用编程接口(API)。
相比本书第5版(针对的是Java版本7),第6版引入了一些新的特性:
Lambda表达式可用于将功能作为方法参数处理,或者将代码作为数据处理。Lambda表达式使得我们可以更简洁地表达单个方法的接口(简称功能性接口)实例。具体内容见第4章。
类型注解可用于关联可插拔的类型系统以改进类型检查,重复注解使得相同的注解可以用于一个声明或类型使用。具体内容见第5章。
默认方法是已经在接口中实现的方法。使用默认方法,可将新功能添加到接口库中,并确保与老版本接口的代码是二进制兼容的。具体内容见第6章。
聚合操作可用于在元素流上执行功能型操作,特别是集合上的批量操作,如序列变换、并行映射归约变换。具体内容见第12章。
在限制恶意小程序的攻击和RIA(富互联网应用)方面也做了一些改进。具体内容参见第16章、 第19章和第20章。
日期/时间API可用于表达日期和时间,并处理日期和时间的值。这些API支持国际标准组织(ISO)的日历系统,以及其他通用的国际历法。具体内容见第21章。
如果你准备参加Java SE 8认证考试,本书可提供一定的帮助。附录列出三个级别的考试,详细介绍每个级别考试覆盖的项目,并指出本书相关信息的章节。注意,这只是参加认证考试要准备的众多内容的一部分。在线教程提供了最新的认证考试大纲,以及该教程各章节的交叉引用。
所有内容都由Oracle Java工程团队的成员审核过,以确保书中信息都是正确和最新的。本书也基于Oracle网站的在线教程,其网址如下:
http://docs.oracle.com/javase/tutorial
本书内容通常被视作核心教程,是初学者和中级程序员的必学知识。一旦掌握了这些内容,就可以学习网站上的其余Java平台文档。如果你有兴趣开发复杂的RIA,可以学习JDK(Java SE Development Kit)中的图形用户接口(GUI)工具包JavaFX,具体内容参见第22章。
和以前的版本一样,本书的目的是构建一个易于阅读的实用程序员指南,以协助读者学习如何使用Java提供的丰富的环境构建应用程序、applet和构件。让我们继续学习编程吧!
读者对象
本书同时面向新手和有经验的程序员。
新手通读本书(包括第1章中编译和运行第一个程序的每一步指令)将有最大的收获。
有经验的过程式语言(如C语言)程序员可以从面向对象的概念和Java程序语言的特性开始学习。
有经验的程序员可以直接学习高级主题,如泛型、并发和部署等。
本书内容适于不同层次的程序员学习。
如何使用本书
本书可直接从头读到尾或忽略某些主题跳到另一个主题。这些信息的组织有一定的逻辑次序,并尽可能避免向前引用。
本书例子都在JDK 8版本中编译。读者需要下载该版本或更新的版本来编译和运行实例。
本书对引用的一些材料提供了在线帮助(如可下载的实例、问题和习题的答案、JDK 8手册和API规范),以脚注形式提供的链接类似下面所示:
8/docs/api/java/lang/Class.html

tutorial/java/generics/examples/BoxDemo.java
Oracle网站上的Java文档主页为:
http://docs.oracle.com/javase/
访问上述以脚注形式提供的链接文件时,只需在Java文档主页URL后添加链接文件,如下所示:
http://docs.oracle.com/javase/8/docs/api/java/lang/Class.html
http://docs.oracle.com/javase/tutorial/java/generics/examples/BoxDemo.java
Java教程也提供了两种格式的电子书:
移动电子书文件,适用于Kindle。
ePub电子书文件,适用于iPad、Nook和其他支持ePub格式的设备。
每本电子书包含唯一的路径,对应本书的相关章节。读者可通过Java教程主页上的链接“In Book Form”下载电子书:
http://docs.oracle.com/javase/tutorial/index.html
欢迎读者给我们反馈,请通过下述教程反馈页面联系我们:
http://docs.oracle.com/javase/feedback.html
致谢
如果没有Oracle Java工程团队不知疲倦地检查本书的技术内容,本书将不能面世。本书第6版的推出,要特别感谢Alan Bateman、Alex Buckley、Stephen Colebourne、Joe Darcy、Jeff Dinkins、Mike Duigou、Brian Goetz、Andy Herrick、Stuart Marks、Thomas Ng、Roger Riggs、Leif Samuelsson和Daniel Smith。
Jordan Douglas和Dawn Tyler快速高效地创建了本书中专业的插图。
编辑Janet Blowney、Deborah Owens和Susan Shepard仔细完整地对书稿进行了编辑加工。
感谢团队成员Devika Gollapudi、Ram Goyal和Alexey Zhebel的支持。
最后要感谢管理人员Sowmya Kannan、Sophia Mikulinsky、Alan Sommerer和Barbara Ramsey的支持。

上架指导

计算机\程序设计

封底文字

本书由Oracle公司Java语言和平台开发团队资深技术文档撰写人基于Java SE 8版本编写,并引用该版本的应用编程接口(API),经过了众多世界级Java专家细心审校,有力地保证了权威性和准确性,内容全面翔实,文字简洁易懂,可读性强,被视为Java的核心教程。
书中主要介绍了面向对象编程的概念、语言基础、类和对象、注解、接口和继承、泛型、包、数字和字符串、异常、基本I/O和NIO.2、集合、并发、正则表达式、平台环境、在JAR文件中打包程序、Java Web Start、applet、Java富互联网应用系统、日期/时间API等内容,涵盖了Lambda表达式、类型注解、默认方法、聚合操作、日期/时间API等Java SE 8的新特性,更新了限制恶意小程序的攻击和RIA等相关内容。每章的后面都有问题和练习,附录中还给出Java编程语言认证考试的相关内容。

作者简介

[美]雷蒙德·盖拉多(Raymond Gallardo) 斯科特·霍梅尔(Scott Hommel) 索娅·坎南(Sowmya Kannan) 琼尼·戈登(Joni Gordon) 沙伦·比奥卡·扎卡沃(Sharon Biocca Zakhour)著:雷蒙德?盖拉多(Raymond Gallardo) Oracle公司高级技术文档工程师,曾担任过高校教师和IBM技术作家。他拥有多伦多大学计算机和英语双学士学位,纽约城市大学创意写作硕士学位。
斯科特?霍梅尔(Scott Hommel) Oracle公司高级技术文档工程师,负责Java SE文档工作。过去15年,他编写了大量Java SE和相关技术的教程、技术文章和核心文档。
索娅?坎南(Sowmya Kannan) 在Oracle公司Java SE技术文档编写团队承担多项工作,包括规划、编写、与开发团队沟通等。她有超过15年从事设计、开发和文档化Java平台、基于Java的中间件、Web应用程序的工作经历。
琼尼?戈登(Joni Gordon) Oracle公司首席技术文档工程师。她为Java SE和JavaFX的技术文档编写做出了杰出贡献。她有超过15年技术文档工程师的经历,技术背景是企业应用软件开发。
沙伦?比奥卡?扎卡沃(Sharon Biocca Zakhour) 曾担任Oracle公司和Sun公司首席技术文档工程师,先前就职于Sun公司,Sun并入Oracle后就职于Oracle。她曾编写过《The Java Tutorial, Fourth Edition》和《The JFC Swing Tutorial, Second Edition》。她毕业于加州大学伯克利分校,获得计算机科学学士学位,具有30年的程序员、开发支持工程师和技术文档工程师经历。

图书目录

第1章 快速入门 1
关于Java技术 1
Java程序语言 2
Java平台 2
Java技术的功能 4
Java技术的优势 4
“Hello World!”示例程序 5
用NetBeans IDE开发“Hello World!” 6
在Microsoft Windows中开发“Hello World!” 15
在Solaris和Linux中开发“Hello World!” 20
“Hello World!”示例程序剖析 23
源码注释 24
HelloWorldApp类定义 25
main方法 25
常见问题(及其解决方案) 27
编译器问题 ..27
运行时问题 ..29
问题和练习:快速入门 31
问题 31
练习 32
答案 32
第2章 面向对象的编程概念 33
对象 34
类 36
继承 38
接口 39
包 40
问题和练习:面向对象的编程概念 41
问题 41
练习 41
答案 41
第3章 语言基础 43
变量 44
命名 45
基本数据类型 46
数组 51
小结 57
问题和练习:变量 57
运算符 58
赋值运算符、算术运算符和一元运算符 59
等式运算符、关系运算符和条件运算符 62
位运算符和移位运算符 65
小结 66
问题和练习:运算符 67
表达式、语句和块 68
表达式 68
语句 70
块 71
问题和练习:表达式、语句和块 71
控制流语句 72
if-then语句和if-then-else语句 72
switch语句 74
while语句和do-while语句 ..79
for语句 80
分支语句 82
小结 85
问题和练习:控制流语句 86
第4章 类和对象 87
类 88
声明类 89
声明成员变量 90
定义方法 92
构建构造器 94
将消息传给方法或构造器 95
对象 99
创建对象 100
使用对象 104
类的更多细节 107
方法的返回值 107
使用this关键字 109
控制对类成员的访问 110
类成员 112
初始化字段 116
小结 118
问题和练习:类 119
问题和练习:对象 120
嵌套类 121
为什么使用嵌套类 122
静态嵌套类 122
内部类 123
隐藏 123
序列化 124
内部类示例 125
局部类和匿名类 127
修饰符 127
局部类 127
匿名类 131
Lambda表达式 136
何时使用嵌套类、局部类、匿名类和Lambda表达式 155
问题和练习:嵌套类 156
枚举类型 157
问题和练习:枚举类型 161
第5章 注解 163
注解的基本概念 164
注解格式 164
哪些地方使用注解 165
声明注解类型 165
预定义注解类型 167
Java语言使用的注解类型 167
应用于其他注解的注解类型 169
类型注解和可插拔类型系统 170
重复注解 171
步骤1:声明可重复的注解类型 172
步骤2:声明包含的注解类型 172
检索注解 173
设计注意事项 .173
问题和练习:注解 173
问题 173
练习 174
答案 174
第6章 接口与继承 175
接口 175
Java语言的接口 176
将接口用作API 177
定义接口 177
实现接口 178
将接口用作类型 180
演化接口 181
默认方法 182
小结 192
问题和练习:接口 193
继承 193
Java平台中类的层次结构 194
继承示例 195
子类能做什么 196
超类的私有成员 196
转换对象 197
状态、实现和类型的多继承 198
覆盖和屏蔽方法 199
多态性 203
屏蔽字段 206
使用super关键字 206
将对象用作超类 208
编写final类和方法 212
抽象方法和类 212
小结 216
问题和练习:继承 216
第7章  泛型 219
为什么用泛型 220
泛型类型 220
一个简单的Box类 220
Box类的泛型版本 221
类型参数命名约定 221
泛型类型的调用和实例化 222
钻石运算符 223
多个类型参数 223
参数化类型 224
原生类型 224
泛型方法 226
受限类型参数 227
多重限制 228
泛型方法和受限类型参数 229
泛型、继承和子类型 229
泛型类和子类型 230
类型推导 232
类型推导与泛型方法 232
类型推导与泛型类的实例化 233
类型推导与泛型类和非泛型类的泛型构造器 234
目标类型 235
通配符 236
上界通配符 236
界通配符 237
下界通配符 238
通配符和子类型 239
通配符匹配和辅助方法 240
通配符使用指南 243
类型擦除 244
泛型类型的擦除 245
泛型方法的擦除 246
类型擦除效果和桥方法 247
不可具体化类型和可变长参数方法 249
泛型的局限性 252
不能用基本数据类型实例化泛型类型 252
不能创建类型参数实例 253
不能声明类型为“类型参数”的静态字段 254
对参数化类型不能用类型转换或运算符 254
不能创建参数化类型数组 255
不能创建、捕获或抛出参数化类型的对象 255
不能重载方法,若方法每次重载的形式参数类型都被擦为相同的原生类型 256
问题和练习:泛型 256
答案 258
第8章 程序包 259
创建和使用程序包 259
创建程序包 261
命名程序包 262
使用程序包成员 263
管理源文件和类文件 267
小结 269
问题和练习:创建和使用程序包 269
问题 269
练习 270
答案 270
第9章 数和字符串 271
数 271
Number类 272
格式化数字打印输出 274
其他数学运算方法 279
自动装箱和拆箱 283
小结 286
问题和练习:数 286
字符 287
转义字符 288
字符串 288
创建字符串 289
字符串长度 290
字符串连接 291
创建格式字符串 292
数字和字符串之间的转换 292
操作字符串中的字符 295
比较字符串和字符串的子串 300
StringBuilder类 302
小结 306
问题和练习:字符和字符串 307
第10章 异常 309
什么是异常 310
捕获或指明规定 311
三类异常 311
绕过捕获或指明 312
捕获和处理异常 .313
try块 314
catch块 315
finally块 316
try-with-resources语句 317
汇总 320
指明一个方法抛出的异常 323
如何抛出异常 324
throw语句 325
Throwable类及其子类 325
Error类 326
Exception类 326
链式异常 ..326
创建异常类 328
未检查异常:争议 329
异常的优点 330
优点1:从正规代码中分离出错误处理代码 331
优点2:根据调用栈上传错误 332
优点3:分组和区分错误类型 334
小结 335
问题和练习 336
问题 336
练习 337
答案 337
第11章 基本I/O和NIO.2 339
I/O流 339
字节流 340
字符流 342
缓冲流 345
扫描和格式化 346
命令行I/O 352
数据流 354
对象流 357
文件I/O(以NIO.2为特征) 359
什么是路径(以及其他文件系统情况) 359
Path类 362
文件操作 370
检查文件或目录 374
删除文件或目录 375
复制文件或目录 376
移动文件或目录 377
管理元数据(文件和文件存储属性) 378
读取、写入和创建文件 386
随机存取文件 393
创建和读取目录 395
符号链接或其他方式的链接 399
遍历文件树 401
查找文件 407
监视目录的变化 410
其他有用的方法 416
遗留文件的 I/O代码 418
小结 421
问题和练习:基本I/O 422
问题 422
练习 422
答案 422
第12章 集合 423
集合简介 424
集合框架是什么 424
Java集合框架的好处 425
接口 426
Collection接口 428
遍历集合 429
Collection接口的批量操作 432
Collection接口的数组操作 432
Set接口 433
List接口 438
Queue接口 446
Deque接口 448
Map接口 449
对象排序 458
SortedSet接口 464
SortedMap接口 467
小结 469
问题和练习:接口 470
聚合操作 471
管道和流 472
聚合操作和迭代的区别 474
归约 474
并行 480
副作用 484
问题和练习:聚合操作 487
实现 489
Set实现 492
List实现 493
Map实现 495
Queue实现 496
Deque实现 498
封装实现 499
简单实现 502
小结 504
问题和练习:实现 504
算法 505
排序 505
混排 508
常规数据操作. 508
查询 508
组合 509
查找极值 509
自定义集合实现 509
为何自定义实现 510
如何编写自定义实现 511
互操作性 513
兼容性 513
API设计 515
第13章 并发 519
进程和线程 520
进程 520
线程 520
线程对象 521
定义和启动一个线程 521
使用Sleep函数暂停执行 522
中断 523
联合 525
简单线程例子 525
同步 527
线程冲突 527
内存一致性错误 528
同步方法 529
内部锁和同步 531
原子访问 533
活性 533
死锁 534
饥饿和活锁 535
保护块 535
不可变对象 539
同步类举例 540
定义不可变对象的策略 541
高级并发对象 543
锁对象 544
执行器 546
并发集合 552
原子变量 553
并发随机数 554
问题和练习:并发 555
问题 555
练习 555
答案 556
第14章 正则表达式 557
简介 558
什么是正则表达式 558
包中的正则表达式如何表示 558
测试工具 559
字符串文字 560
元字符 .561
字符类 562
简单类 562
预定义字符类 566
量词 568
零长度匹配 569
捕获组和带有量词的字符类 572
贪婪型、勉强型和占有型量词之间的区别 573
捕获组 574
编号 574
反向引用 575
边界匹配器 576
模式类的方法 578
使用标记创建模式 578
嵌套标记表达式 580
使用matches(String, CharSequence)方法 580
使用split(String)方法 581
其他实用方法 582
java.lang.String中模式方法的等价 582
Matcher类的方法 583
索引方法 583
学习方法 584
替换方法 584
使用start和end方法 585
使用matches和lookingAt方法 586
使用replaceFirst(String) 和replaceAll(String) 587
使用appendReplacement(StringBuffer, String)和appendTail(StringBuffer) 588
Matcher方法在java.lang.String中的等价 589
PatternSyntaxException类的方法 589
Unicode支持 591
匹配特定代码点 591
Unicode字符属性 591
问题和练习:正则表达式 592
问题 592
练习 593
答案 593
第15章 平台环境 595
配置工具 595
属性 596
命令行参数 600
环境变量 601
其他配置工具 602
系统工具 603
命令行I/O对象 603
系统属性 604
安全管理器 607
系统的其他方法 608
路径和类路径 609
更新PATH环境变量(Microsoft Windows) 609
更新PATH变量(Solaris、Linux和OS X) 611
检查CLASSPATH变量(所有平台) 612
问题和练习:平台环境 613
问题 613
练习 614
答案 614
第16章 在JAR文件中打包程序 615
JAR文件使用入门 616
创建JAR文件 616
查看JAR文件内容 620
抽取JAR文件内容 622
更新JAR文件 623
运行打包为JAR的软件 625
清单文件使用入门 627
理解默认的清单文件 627
修改清单文件 628
设置应用程序的入口点 629
将类文件加入JAR文件的类路径 630
设置包版本信息 631
用JAR文件封装包 633
加强清单文件属性的安全性 634
JAR文件的签名和验证 635
理解签名和验证 636
对JAR文件签名 639
验证签名的JAR文件 641
使用JAR相关API 642
例子:JarRunner应用 643
JarClassLoader类 643
JarRunner类 646
问题和练习:在JAR文件中打包程序 648
问题 648
答案 648
第17章 Java Web Start 649
其他参考文献 650
开发Java Web Start应用 650
创建顶层JPanel类 651
创建应用 652
从最后部署机制中分离出核心功能的好处 652
获取资源 653
部署Java Web Start应用 653
设置Web服务器 656
显示自定义的加载进度指示器 656
开发自定义的加载进度指示器 657
为Java Web Start应用指定自定义的加载进度指示器 659
运行Java Web Start应用 660
通过浏览器运行Java Web Start应用 660
通过Java Cache Viewer运行Java Web Start应用 660
从桌面运行Java Web Start应用 661
Java Web Start与安全 661
动态下载HTTPS认证 662
Java Web Start常见问题 662
问题和练习:Java Web Start 663
问题 663
练习 664
答案 664
第18章 applet 665
开始使用applet 666
定义Applet类的子类 666
里程碑方法 667
applet的生命周期 668
applet的执行环境 670
开发applet 670
部署applet 673
applet更多功能 ..677
查找和加载数据文件 677
定义和使用applet参数 .678
显示简短的状态字符串 681
在浏览器中显示文档 682
从applet调用JavaScript代码 683
从JavaScript代码中调用applet方法 686
通过事件句柄处理初始化状态 689
操纵applet网页的DOM 691
显示自定义加载进度指示器 693
将诊断写入标准输出和错误流 698
开发可拖动的applet 698
和其他applet通信 701
与服务器端应用交互… 703
applet能做什么和不能做什么 705
applet常见问题及解决方案 707
问题和练习:applet 708
问题 708
练习 709
答案 709
第19章 Java富互联网应用系统 711
设置可信参数和安全属性 711
系统属性 713
JNLP API 714
通过JNLP API访问客户端 715
cookie 719
cookie的类型 719
RIA中的cookie支持 719
获取cookie 720
自定义加载体验 722
RIA的安全性 722
安全RIA入门 724
安全代码入门 724
测试最新的JRE 724
导入清单文件属性 725
使用签名的JNLP文件 725
对JAR文件进行签名和加时间戳 725
使用HTTPS协议 726
避免局部RIA 726
问题和练习:Java富互联网应用系统 726
问题 726
练习 726
答案 727
第20章 深入理解部署 729
RIA的用户接受度 729
部署工具 731
部署工具脚本所在位置 731
部署applet 732
部署Java Web Start应用 735
检查客户端的JRE软件版本 738
Java网络加载协议 739
JNLP文件结构 739
部署的最佳实践 748
减少下载时间 748
避免不必要的更新检查 749
确保JRE软件存在 751
问题和练习:深入理解部署 753
问题 753
练习 753
答案 753
第21章 日期/时间API 755
日期/时间API简介 756
日期/时间API设计原则 756
清晰 756
流畅 757
不可变 757
可扩展 757
日期/时间程序包 757
法命名约定 758
标准日历 759
简介 759
枚举类型DayOfWeek和Month 760
DayOfWeek 760
Month 762
日期类 762
LocalDate 763
YearMonth 763
MonthDay 764
Year 764
日期时间类 764
LocalTime 764
LocalDateTime 765
时区和偏移量类 766
ZoneId和ZoneOffset 766
日期/时间类 767
实例类 770
解析和格式化 772
解析 772
格式化 773
时间包 774
Temporal和TemporalAccessor 774
ChronoField和IsoFields 775
ChronoUnit 775
时间调节器 776
时间查询 778
周期和持续时间 780
持续时间 781
ChronoUnit 781
周期 782
时钟 783
非ISO日期约定 784
转换成非ISO类型的日期 784
转换成ISO类型的日期 786
遗留的日期/时间代码 787
与遗留代码的互操作 787
将java.util的日期和时间类功能映射到java.time 788
日期和时间的格式 789
小结 789
问题和练习:日期/时间API 791
问题 791
练习 791
答案 791
第22章 JavaFX简介 793
附录 Java程序语言认证复习大纲 795
程序员I级考试 795
主题1:Java基础 795
主题2:Java数据类型的使用 796
主题3:运算符和判定构造的使用 797
主题4:数组的创建和使用 797
主题5:循环构造的使用 798
主题6:方法和封装的使用 798
主题7:继承的使用 799
主题8:异常处理 799
主题9:选用Java API中的类 800
程序员II级考试 801
Java SE 8升级考试 801
主题1:Lambda表达式 801
主题2:内置Lambda类型的使用 801
主题3:过滤带Lambda类型的集合 802
主题4:Lambda类型的集合操作 803
主题5:并行流 803
主题6:Lambda详情 804
主题7:增强的方法 804
主题8:Java SE 8日期/时间API的使用 804
主题9:带Nashorn的Java的JavaScript使用 805




Contents
Chapter 1 Getting Started 1
The Java Technology Phenomenon 1
The Java Programming Language 2
The Java Platform 2
What Can Java Technology Do 4
How Will Java Technology Change My Life 4
The “Hello World!” Application 5
“Hello World!” for the NetBeans IDE 6
“Hello World!” for Microsoft Windows 15
“Hello World!” for Solaris and Linux 20
A Closer Look at the “Hello World!” Application 23
Source Code Comments 24
The HelloWorldApp Class De.nition 25
The main Method 25
Common Problems (and Their Solutions) 27
Compiler Problems 27
Runtime Problems 29
Questions and Exercises: Getting Started 31
Questions 31
Exercises 32
Answers 32
Chapter 2 Object- Oriented Programming Concepts 33
What Is an Object 34
What Is a Class 36
What Is Inheritance 38
What Is an Interface 39
What Is a Package 40
Questions and Exercises: Object- Oriented Programming Concepts 41
Questions 41
Exercises 41
Answers 41
Chapter 3 Language Basics 43
Variables 44
Naming 45
Primitive Data Types 46
Arrays 51
Summary of Variables 57
Questions and Exercises: Variables 57
Operators 58
Assignment, Arithmetic, and Unary Operators 59
Equality, Relational, and Conditional Operators 62
Bitwise and Bit Shift Operators 65
Summary of Operators 66
Questions and Exercises: Operators 67
Expressions, Statements, and Blocks 68
Expressions 68
Statements 70
Blocks 71
Questions and Exercises: Expressions, Statements, and Blocks 71
Control Flow Statements 72
The if- then and if- then- else Statements 72
The switch Statement 74
The while and do- while Statements 79
The for Statement 80
Branching Statements 82
Summary of Control Flow Statements 85
Questions and Exercises: Control Flow Statements 86
Chapter 4 Classes and Objects 87
Classes 88
Declaring Classes 89
Declaring Member Variables 90
De.ning Methods 92
Providing Constructors for Your Classes 94
Passing Information to a Method or a Constructor 95
Objects 99
Creating Objects 100
Using Objects 104
More on Classes 107
Returning a Value from a Method 107
Using the this Keyword 109
Controlling Access to Members of a Class 110
Understanding Class Members 112
Initializing Fields 116
Summary of Creating and Using Classes and Objects 118
Questions and Exercises: Classes 119
Questions and Exercises: Objects 120
Nested Classes 121
Why Use Nested Classes 122
Static Nested Classes 122
Inner Classes 123
Shadowing 123
Serialization 124
Inner Class Example 125
Local and Anonymous Classes 127
Modi.ers 127
Local Classes 127
Anonymous Classes 131
Lambda Expressions 136
When to Use Nested Classes, Local Classes, Anonymous Classes, and Lambda Expressions 155
Questions and Exercises: Nested Classes 156
Enum Types 157
Questions and Exercises: Enum Types 161
Chapter 5 Annotations 163
Annotations Basics 164
The Format of an Annotation 164
Where Annotations Can Be Used 165
Declaring an Annotation Type 165
Prede.ned Annotation Types 167
Annotation Types Used by the Java Language 167
Annotations That Apply to Other Annotations 169
Type Annotations and Pluggable Type Systems 170
Repeating Annotations 171
Step 1: Declare a Repeatable Annotation Type 172
Step 2: Declare the Containing Annotation Type 172
Retrieving Annotations 173
Design Considerations 173
Questions and Exercises: Annotations 173
Questions 173 Exercise 174
Answers 174
Chapter 6 Interfaces and Inheritance 175
Interfaces 175
Interfaces in Java 176
Interfaces as APIs 177
De.ning an Interface 177
Implementing an Interface 178
Using an Interface as a Type 180
Evolving Interfaces 181
Evolving Interfaces Default Methods 182
Summary of Interfaces 192
Questions and Exercises: Interfaces 193
Inheritance 193
The Java Platform Class Hierarchy 194
An Example of Inheritance 195
What You Can Do in a Subclass 196
Private Members in a Superclass 196
Casting Objects 197
Multiple Inheritance of State, Implementation, and Type 198
Overriding and Hiding Methods 199
Polymorphism 203
Hiding Fields 206
Using the Keyword super 206
Object as a Superclass 208
Writing Final Classes and Methods 212
Abstract Methods and Classes 212
Summary of Inheritance 216
Questions and Exercises: Inheritance 216
Chapter 7 Generics 219
Why Use Generics 220
Generic Types 220
A Simple Box Class 220
A Generic Version of the Box Class 221
Type Parameter Naming Conventions 221
Invoking and Instantiating a Generic Type 222
The Diamond 223
Multiple Type Parameters 223
Parameterized Types 224
Raw Types 224
Generic Methods 226
Bounded Type Parameters 227
Multiple Bounds 228
Generic Methods and Bounded Type Parameters 229
Generics, Inheritance, and Subtypes 229
Generic Classes and Subtyping 230
Type Inference 232
Type Inference and Generic Methods 232
Type Inference and Instantiation of Generic Classes 233
Type Inference and Generic Constructors of Generic and Nongeneric Classes 234
Target Types 235
Wildcards 236
Upper- Bounded Wildcards 236
Unbounded Wildcards 237
Lower- Bounded Wildcards 238
Wildcards and Subtyping 239
Wildcard Capture and Helper Methods 240
Guidelines for Wildcard Use 243
Type Erasure 244
Erasure of Generic Types 245
Erasure of Generic Methods 246
Effects of Type Erasure and Bridge Methods 247
Nonrei.able Types and Varargs Methods 249
Restrictions on Generics 252
Cannot Instantiate Generic Types with Primitive Types 252
Cannot Create Instances of Type Parameters 253
Cannot Declare Static Fields Whose Types Are Type Parameters 254
Cannot Use Casts or instanceof with Parameterized Types 254
Cannot Create Arrays of Parameterized Types 255
Cannot Create, Catch, or Throw Objects of Parameterized Types 255
Cannot Overload a Method Where the Formal Parameter Types of Each Overload Erase to the Same Raw Type 256
Questions and Exercises: Generics 256
Answers 258
Chapter 8 Packages 259
Creating and Using Packages 259
Creating a Package 261
Naming a Package 262
Using Package Members 263
Managing Source and Class Files 267
Summary of Creating and Using Packages 269
Questions and Exercises: Creating and Using Packages 269
Questions 269
Exercises 270
Answers 270
Chapter 9 Numbers and Strings 271
Numbers 271
The Numbers Classes 272
Formatting Numeric Print Output 274
Beyond Basic Arithmetic 279
Autoboxing and Unboxing 283
Summary of Numbers 286
Summary of Numbers Questions and Exercises: Numbers 286
Characters 287
Escape Sequences 288
Strings 288
Creating Strings 289
String Length 290
Concatenating Strings 291
Creating Format Strings 292
Converting between Numbers and Strings 292
Manipulating Characters in a String 295
Comparing Strings and Portions of Strings 300
The StringBuilder Class 302
Summary of Characters and Strings 306
Questions and Exercises: Characters and Strings 307
Chapter 10 Exceptions 309
What Is an Exception 310
The Catch or Specify Requirement 311
The Three Kinds of Exceptions 311
Bypassing Catch or Specify 312
Catching and Handling Exceptions 313
The try Block 314
The catch Blocks 315
The .nally Block 316
The try- with- resources Statement 317
Putting It All Together 320
Specifying the Exceptions Thrown by a Method 323
How to Throw Exceptions 324
The throw Statement 325
Throwable Class and Its Subclasses 325
Error Class 326
Exception Class 326
Chained Exceptions 326
Creating Exception Classes 328
Unchecked Exceptions: The Controversy 329
Advantages of Exceptions 330
Advantage 1: Separating Error- Handling Code from “Regular” Code 331
Advantage 2: Propagating Errors Up the Call Stack 332
Advantage 3: Grouping and Differentiating Error Types 334
Summary 335
Questions and Exercises: Exceptions 336
Questions 336
Exercises 337
Answers 337
Chapter 11 Basic I/O and NIO.2 339
I/O Streams 339
Byte Streams 340
Character Streams 342
Buffered Streams 345
Scanning and Formatting 346
I/O from the Command Line 352
Data Streams 354
Object Streams 357
File I/O (Featuring NIO.2) 359
What Is a Path (And Other File System Facts) 359
The Path Class 362
File Operations 370
Checking a File or Directory 374
Deleting a File or Directory 375
Copying a File or Directory 376
Moving a File or Directory 377
Managing Metadata (File and File Store Attributes) 378
Reading, Writing, and Creating Files 386
Random Access Files 393
Creating and Reading Directories 395
Links, Symbolic or Otherwise 399
Walking the File Tree 401
Finding Files 407
Watching a Directory for Changes 410
Other Useful Methods 416
Legacy File I/O Code 418
Summary 421
Questions and Exercises: Basic I/O 422
Questions 422
Exercises 422
Answers 422
Chapter 12 Collections 423
Introduction to Collections 424
What Is a Collections Framework 424
Bene.ts of the Java Collections Framework 425
Interfaces 426
The Collection Interface 428
Traversing Collections 429
Collection Interface Bulk Operations 432
Collection Interface Bulk Operations Collection Interface Array Operations 432
The Set Interface 433
The List Interface 438
The Queue Interface 446
The Deque Interface 448
The Map Interface 449
Object Ordering 458
The SortedSet Interface 464
The SortedMap Interface 467
Summary of Interfaces 469
Questions and Exercises: Interfaces 470
Aggregate Operations 471
Pipelines and Streams 472
Differences between Aggregate Operations and Iterators 474
Reduction 474
Parallelism 480
Side Effects 484
Questions and Exercises: Aggregate Operations 487
Implementations 489
Set Implementations 492
List Implementations 493
Map Implementations 495
Queue Implementations 496
Deque Implementations 498
Wrapper Implementations 499
Convenience Implementations 502
Summary of Implementations 504
Questions and Exercises: Implementations 504
Algorithms 505
Sorting 505
Shuf.ing 508
Routine Data Manipulation 508
Searching 508
Composition 509
Finding Extreme Values 509
Custom Collection Implementations 509
Reasons to Write an Implementation 510
How to Write a Custom Implementation 511
Interoperability 513
Compatibility 513
API Design 515
API Design
Chapter 13 Concurrency 519
Processes and Threads 520
Processes 520
Threads 520
Thread Objects 521
De.ning and Starting a Thread 521
Pausing Execution with Sleep 522
Interrupts 523
Joins 525
The SimpleThreads Example 525
Synchronization 527
Thread Interference 527
Memory Consistency Errors 528
Synchronized Methods 529
Intrinsic Locks and Synchronization 531
Atomic Access 533
Liveness 533
Deadlock 534
Starvation and Livelock 535
Guarded Blocks 535
Immutable Objects 539
A Synchronized Class Example 540
A Strategy for De.ning Immutable Objects 541
High- Level Concurrency Objects 543
Lock Objects 544
Executors 546
Concurrent Collections 552
Atomic Variables 553
Concurrent Random Numbers 554
Questions and Exercises: Concurrency 555
Question 555
Exercises 555 Answers 556
Chapter 14 Regular Expressions 557
Introduction 558
What Are Regular Expressions 558
How Are Regular Expressions Represented in This Package 558
Test Harness 559
String Literals 560
Metacharacters 561
Character Classes 562
Simple Classes 562
Prede.ned Character Classes 566
Quanti.ers 568
Zero- Length Matches 569
Capturing Groups and Character Classes with Quanti.ers 572
Differences among Greedy, Reluctant, and Possessive Quanti.ers 573
Capturing Groups 574
Numbering 574
Backreferences 575
Boundary Matchers 576
Methods of the Pattern Class 578
Creating a Pattern with Flags 578
Embedded Flag Expressions 580
Using the matches(String,CharSequence) Method 580
Using the split(String) Method 581
Other Utility Methods 582
Pattern Method Equivalents in java.lang.String 582
Methods of the Matcher Class 583
Index Methods 583
Study Methods 584
Replacement Methods 584
Using the start and end Methods 585
Using the matches and lookingAt Methods 586
Using replaceFirst(String) and replaceAll(String) 587
Using appendReplacement(StringBuffer,String) and appendTail(StringBuffer) 588
Matcher Method Equivalents in java.lang.String 589
Methods of the PatternSyntaxException Class 589
Unicode Support 591
Matching a Speci.c Code Point 591
Unicode Character Properties 591
Questions and Exercises: Regular Expressions 592
Questions 592
Exercise 593
Answers 593
Chapter 15 The Platform Environment 595
Con.guration Utilities 595
Properties 596
Command- Line Arguments 600
Environment Variables 601
Other Con.guration Utilities 602
System Utilities 603
Command- Line I/O Objects 603
System Properties 604
The Security Manager 607
Miscellaneous Methods in System 608
PATH and CLASSPATH 609
Update the PATH Environment Variable (Microsoft Windows) 609
Update the PATH Variable (Solaris, Linux, and OS X) 611
Checking the CLASSPATH Variable (All Platforms) 612
Questions and Exercises: The Platform Environment 613
Question 613
Exercise 614
Answers 614
Chapter 16 Packaging Programs in JAR Files 615
Using JAR Files: The Basics 616
Creating a JAR File 616
Viewing the Contents of a JAR File 620 Extracting the Contents of a JAR File 622
Updating a JAR File 623 Running JAR- Packaged Software 625
Working with Manifest Files: The Basics 627
Understanding the Default Manifest 627
Modifying a Manifest File 628
Setting an Application’s Entry Point 629
Adding Classes to the JAR File’s Class Path 630
Setting Package Version Information 631
Sealing Packages within a JAR File 633 Enhancing Security with Manifest Attributes 634
Signing and Verifying JAR Files 635
Understanding Signing and Veri.cation 636
Signing JAR Files 639
Verifying Signed JAR Files 641
Using JAR- Related APIs 642
An Example: The JarRunner Application 643
The JarClassLoader Class 643
The JarRunner Class 646
Questions and Exercises: Packaging Programs in JAR Files 648
Questions 648 Answers 648
Chapter 17 Java Web Start 649
Additional References 650
Developing a Java Web Start Application 650
Creating the Top JPanel Class 651
Creating the Application 652
Bene.ts of Separating Core Functionality from the Final Deployment Mechanism 652
Retrieving Resources 653
Deploying a Java Web Start Application 653
Setting Up a Web Server 656
Displaying a Customized Loading Progress Indicator 656
Developing a Customized Loading Progress Indicator 657
Specifying a Customized Loading Progress Indicator for a Java Web Start Application 659
Running a Java Web Start Application 660
Running a Java Web Start Application from a Browser 660
Running a Java Web Start Application from the Java Cache Viewer 660
Running a Java Web Start Application from the Desktop 661
Java Web Start and Security 661
Dynamic Downloading of HTTPS Certi.cates 662
Common Java Web Start Problems 662
Questions and Exercises: Java Web Start 663 Questions 663
Exercises 664 Answers 664
Chapter 18 Applets 665
Getting Started with Applets 666
De.ning an Applet Subclass 666
Methods for Milestones 667 Life Cycle of an Applet 668
Applet’s Execution Environment 670
Developing an Applet 670
Deploying an Applet 673
Doing More with Applets 677
Finding and Loading Data Files 677
De.ning and Using Applet Parameters 678
Displaying Short Status Strings 681
Displaying Documents in the Browser 682 Invoking JavaScript Code from an Applet 683
Invoking Applet Methods from JavaScript Code 686 Handling Initialization Status with Event Handlers 689
Manipulating DOM of Applet’s Web Page 691 Displaying a Customized Loading Progress Indicator 693
Writing Diagnostics to Standard Output and Error Streams 698
Developing Draggable Applets 698
Communicating with Other Applets 701
Working with a Server- Side Application 703
What Applets Can and Cannot Do 705
Solving Common Applet Problems 707
Questions and Exercises: Applets 708
Questions 708
Exercises 709
Answers 709
Chapter 19 Doing More with Java Rich Internet Applications 711
Setting Trusted Arguments and Secure Properties 711
System Properties 713
JNLP API 714
Accessing the Client Using the JNLP API 715 Cookies 719
Types of Cookies 719
Cookie Support in RIAs 719 Accessing Cookies 720
Customizing the Loading Experience 722
Security in Rich Internet Applications 722
Guidelines for Securing RIAs 724
Follow Secure Coding Guidelines 724
Test with the Latest Version of the JRE 724
Include Manifest Attributes 725
Use a Signed JNLP File 725
Sign and Time Stamp JAR Files 725
Use the HTTPS Protocol 726
Avoid Local RIAs 726
Questions and Exercises: Doing More with Rich Internet Applications 726
Questions 726
Exercise 726
Answers 727
Chapter 20 Deployment in Depth 729
User Acceptance of RIAs 729
Deployment Toolkit 731
Location of Deployment Toolkit Script 731 Deploying an Applet 732
Deploying a Java Web Start Application 735
Checking the Client JRE Software Version 738
Java Network Launch Protocol 739
Structure of the JNLP File 739
Deployment Best Practices 748
Reducing the Download Time 748
Avoiding Unnecessary Update Checks 749
Ensuring the Presence of the JRE Software 751
Questions and Exercises: Deployment in Depth 753
Questions 753
Exercise 753
Answers 753
Chapter 21 Date- Time 755
Date- Time Overview 756
Date- Time Design Principles 756
Clear 756 Fluent 757
Immutable 757 Extensible 757
The Date- Time Packages 757
Method Naming Conventions 758
Standard Calendar 759 Overview 759
DayOfWeek and Month Enums 760
DayOfWeek 760
Month 762
Date Classes 762
LocalDate 763 YearMonth 763
MonthDay 764
Year 764
Date and Time Classes 764
LocalTime 764
LocalDateTime 765
Time Zone and Offset Classes 766
ZoneId and ZoneOffset 766
The Date- Time Classes 767
Instant Class 770
Parsing and Formatting 772
Parsing 772
Formatting 773
The Temporal Package 774
Temporal and TemporalAccessor 774
ChronoField and IsoFields 775
ChronoUnit 775 Temporal Adjuster 776
Temporal Query 778
Period and Duration 780
Duration 781
ChronoUnit 781
Period 782
Clock 783
Non- ISO Date Conversion 784
Converting to a Non- ISO- Based Date 784
Converting to an ISO- Based Date 786
Legacy Date- Time Code 787 Interoperability with Legacy Code 787
Mapping java.util Date and Time Functionality to java.time 788
Date and Time Formatting 789
Summary 789
Questions and Exercises: Date- Time 791
Questions 791 Exercises 791
Answers 791
Chapter 22 Introduction to JavaFX 793
Appendix Preparation for Java Programming Language Certi. cation 795
Programmer Level I Exam 795
Section 1: Java Basics 795
Section 2: Working with Java Data Types 796 Section 3: Using Operators and Decision Constructs 797
Section 4: Creating and Using Arrays 797 Section 5: Using Loop Constructs 798
Section 6: Working with Methods and Encapsulation 798
Section 7: Working with Inheritance 799 Section 8: Handling Exceptions 799
Section 9: Working with Selected Classes from the Java API 800

教学资源推荐
作者: 邱李华 曹青 郭志强 编著
作者: (美)Dennis Kafura
作者: [美]克洛维斯· L.汤多(Clovis L. Tondo) 斯科特· E.吉姆佩尔(Scott E. Gimpel)著
参考读物推荐
作者: [美]特恩斯?帕尔(Terence Parr)著
作者: (美)Kevin Brothaler 著
作者: [印]纳拉辛哈·卡鲁曼希(Narasimha Karumanchi) 著