出版时间:2014-1 出版社:清华大学出版社 作者:张峰
内容概要
本书从学习Java 7 编程的初学者角度出发,根据作者多年的程序设计经验,按照科学的学习规律,由浅
入深、循序渐进地向读者讲述Java 7 开发环境的搭建、Java 基础语法知识、Java 算法流程、面向对象高级特
性、Java 的输入/输出、多线程机制、Swing界面编程、Applet 的基本知识、Java 2D/3D、Java 流媒体、JDBC
编程等。同时每章都配有大量的程序设计案例和上机实验指导,包括实验目的、实验要求和实验内容;另每
章都有Java 开发过程中的问题集锦与解答,自我检测与实践以及经典考试、面试问题分析。书中也提供了
MP3/MP4媒体播放器、远程实时监控系统、航空票务管理系统和即时通讯系统应用案例,用于提高实践编程
能力,也可作为高年级学生的毕业设计案例。
本书可作为大中院校、培训机构的Java 教材,也可作为Java 初学者的入门指南和Java 自学者和用其他
语言编程人员的参考用书。
书籍目录
目 录
第1 篇 Java 基础篇
第1 章 Java平台及开发环境的搭建························································································ 2
1.1 Windows 下Java 开发环境的配置···························································································· 2
1.1.1 相关软件介绍································································································································ 2
1.1.2 应用平台········································································································································ 3
1.1.3 解析JDK 结构······························································································································ 4
1.2 Eclipse安装和使用····················································································································· 4
1.2.1 Eclipse 的下载和安装··················································································································· 4
1.2.2 MyEclipse 下载和安装················································································································· 5
1.3 JBuilder 集成开发环境介绍······································································································· 5
1.4 NetBeans 集成开发环境介绍····································································································· 6
1.5 本章小结····································································································································· 6
第2 章 理解Java语言············································································································· 7
2.1 Java 的发展历程························································································································· 7
2.1.1 Java 的现状···································································································································· 7
2.1.2 Java 语言的应用领域···················································································································· 8
2.1.3 Java 编程语言的主要目标············································································································ 8
2.1.4 Java JVM 虚拟机··························································································································· 8
2.1.5 垃圾收集机制································································································································ 9
2.1.6 Coin项目······································································································································· 9
2.2 Java 语言的特性······················································································································· 10
2.3 Java 中的面向对象编程··········································································································· 12
2.3.1 对象的定义及操作······················································································································ 12
2.3.2 抽象·············································································································································· 13
2.3.3 如何定义对象类·························································································································· 13
2.3.4 类和对象的关系·························································································································· 14
2.3.5 对象操作······································································································································ 14
2.3.6 封装·············································································································································· 15
2.3.7 继承与子类·································································································································· 15
2.3.8 多态·············································································································································· 16
2.3.9 模板/泛型(template/generic)·································································································· 17
2.3.10 注解············································································································································ 17
2.4 Java 程序结构··························································································································· 18
2.4.1 学习Java 应用程序的编写········································································································· 18
2.4.2 解析FirstHelloWorldApp.java···································································································· 18
2.4.3 编译并运行FirstHelloWorldApp ······························································································· 18
2.4.4 使用package 管理类··················································································································· 20
2.4.5 包的引用······································································································································ 21
2.4.6 目录布局及CLASSPATH环境变量························································································· 21
2.4.7 编译查错······································································································································ 22
2.4.8 从JDK到IDE····························································································································· 23
2.5 Java 与C/C++、C#的比较······································································································· 28
2.5.1 全局变量······································································································································ 28
2.5.2 goto··············································································································································· 29
2.5.3 指针·············································································································································· 29
2.5.4 内存管理······································································································································ 30
2.5.5 数据类型的支持·························································································································· 31
2.5.6 类型转换······································································································································ 31
2.5.7 头文件·········································································································································· 31
2.5.8 结构和联合·································································································································· 32
2.5.9 预处理·········································································································································· 32
2.6 本章考试、面试问题分析······································································································· 32
2.7 实验:Java运行环境的安装、配置与运行··········································································· 33
2.8 问题集锦与解答······················································································································· 36
2.9 自我检测··································································································································· 37
2.10 本章小结································································································································· 37
第3 章 Java标识符、关键字和类型······················································································ 38
3.1 Java 基本语法··························································································································· 38
3.1.1 程序注释······································································································································ 38
3.1.2 分号、块和空白块······················································································································ 40
3.1.3 标识符·········································································································································· 40
3.1.4 Java 关键字·································································································································· 41
3.1.5 Java 编码约定······························································································································ 42
3.2 数据类型··································································································································· 43
3.2.1 简单数据类型······························································································································ 43
3.2.2 复合数据类型······························································································································ 44
3.2.3 常量与变量·································································································································· 44
3.2.4 整型数据······································································································································ 45
3.2.5 浮点型(实型)数据·················································································································· 45
3.2.6 字符型数据·································································································································· 46
3.2.7 布尔型数据·································································································································· 47
3.2.8 枚举类型······································································································································ 48
3.3 二进制字面值··························································································································· 49
3.4 在数值字面量中使用下划线··································································································· 50
3.5 本章程序设计案例··················································································································· 50
3.6 本章考试、面试问题分析······································································································· 51
3.7 实验:Java标识符、关键字和类型练习··············································································· 52
3.8 问题集锦与解答······················································································································· 53
3.9 自我检测··································································································································· 53
3.10 本章小结································································································································· 54
第4 章 表达式和流控制·········································································································· 55
4.1 变量··········································································································································· 55
4.1.1 变量的声明和作用域·················································································································· 55
4.1.2 变量初始化·································································································································· 56
4.2 运算符······································································································································· 57
4.3 算术运算··································································································································· 58
4.3.1 二元算术运算符·························································································································· 58
4.3.2 一元算术运算符·························································································································· 58
4.3.3 整数计算······································································································································ 59
4.3.4 整数除法和余数·························································································································· 59
4.3.5 其他算术运算······························································································································ 59
4.3.6 混合运算自动类型转换·············································································································· 60
4.3.7 混合运算强制类型转换·············································································································· 61
4.4 逻辑关系运算··························································································································· 61
4.4.1 关系运算符·································································································································· 61
4.4.2 布尔逻辑运算符·························································································································· 62
4.5 位运算······································································································································· 63
4.5.1 位运算符······································································································································ 63
4.5.2 位移运算······································································································································ 63
4.5.3 位逻辑运算符······························································································································ 64
4.6 顺序结构··································································································································· 64
4.7 分支结构··································································································································· 65
4.7.1 条件语句if-else··························································································································· 65
4.7.2 多分支语句switch ······················································································································ 65
4.7.3 Java 7 的switch 分支语句········································································································ 67
4.8 循环结构··································································································································· 68
4.8.1 while 循环语句··························································································································· 68
4.8.2 do-while 循环语句······················································································································ 68
4.8.3 for 语句········································································································································ 69
4.9 控制循环结构··························································································································· 69
4.9.1 return 语句··································································································································· 69
4.9.2 continue语句······························································································································· 70
4.9.3 break 语句···································································································································· 70
4.9.4 带标签的break···························································································································· 72
4.9.5 带标签的continue ······················································································································· 72
4.9.6 各种控制语句在实际编程中的应用·························································································· 73
4.10 本章程序设计案例················································································································· 75
4.11 本章考试、面试问题分析····································································································· 76
4.12 实验:Java表达式和流控制练习························································································· 77
4.13 自我检测································································································································· 79
4.14 本章小结································································································································· 80
第5 章 数组和字符串············································································································· 81
5.1 一维数组··································································································································· 81
5.1.1 一维数组的定义·························································································································· 81
5.1.2 一维数组元素的引用·················································································································· 82
5.1.3 一维数组的初始化······················································································································ 83
5.1.4 一维数组在实际编程中的应用方法·························································································· 83
5.2 多维数组··································································································································· 84
5.2.1 二维数组的定义·························································································································· 84
5.2.2 二维数组元素的引用·················································································································· 84
5.2.3 二维数组的初始化······················································································································ 84
5.2.4 二维数组在实际编程中的应用·································································································· 85
5.2.5 复制数组······································································································································ 86
5.3 字符串······································································································································· 86
5.3.1 字符串字面量······························································································································ 86
5.3.2 String 对象的创建······················································································································· 87
5.4 字符串操作······························································································································· 87
5.4.1 字符串基本方法·························································································································· 87
5.4.2 字符串的比较······························································································································ 88
5.4.3 从字符串中提取子串·················································································································· 88
5.5 可变字符串······························································································································· 89
5.5.1 创建StringBuffer 对象················································································································ 89
5.5.2 使用StringBuffer 对象················································································································ 90
5.5.3 删除StringBuffer 对象················································································································ 90
5.5.4 StringBuffer 对象的容量············································································································· 91
5.6 本章考试、面试问题分析······································································································· 91
5.7 实验数组和字符串··················································································································· 92
5.8 问题集锦与解答······················································································································· 94
5.9 自我检测··································································································································· 95
5.10 本章小结································································································································· 95
第6 章 类、对象、包和接口·································································································· 96
6.1 类··············································································································································· 96
6.1.1 类的声明······································································································································ 96
6.1.2 类体·············································································································································· 97
6.2 定义方法··································································································································· 97
6.2.1 方法的返回值······························································································································ 98
6.2.2 方法的参数列表·························································································································· 98
6.3 构造方法··································································································································· 99
6.3.1 构造方法······································································································································ 99
6.3.2 默认构造方法······························································································································ 99
6.4 类成员·····································································································································100
6.4.1 成员变量···································································································································· 100
6.4.2 显式成员初始化························································································································ 101
6.4.3 单根(Singleton)类················································································································ 101
6.5 方法重载·································································································································102
6.5.1 多个构造方法···························································································································· 102
6.5.2 调用重载构造方法···················································································································· 102
6.6 对象·········································································································································103
6.6.1 对象生成···································································································································· 103
6.6.2 对象的使用································································································································ 103
6.6.3 构造函数的特点························································································································ 105
6.7 继承·········································································································································106
6.7.1 继承的概念································································································································ 106
6.7.2 继承定义···································································································································· 106
6.7.3 扩展类········································································································································ 107
6.7.4 属性继承与隐藏························································································································ 109
6.7.5 方法继承、覆盖与重载············································································································ 109
6.7.6 在子类中使用构造方法············································································································ 110
6.7.7 @Override 标记························································································································· 110
6.8 多态与动态绑定·····················································································································111
6.8.1 多态············································································································································ 111
6.8.2 动态绑定···································································································································· 112
6.8.3 父类对象与子类对象的使用与转化························································································ 112
6.8.4 Instanceof 运算符······················································································································ 113
6.8.5 多态性在实际编程中的应用···································································································· 113
6.8.6 泛型············································································································································ 114
6.8.7 Java 7 泛型的“菱形”语法····································································································· 116
6.8.8 构造方法的继承与重载············································································································ 117
6.8.9 参数可变的方法························································································································ 118
6.8.10 Java 7 优化变长参数的方法调用··························································································· 120
6.9 抽象类与抽象方法·················································································································120
6.9.1 抽象类········································································································································ 120
6.9.2 抽象方法···································································································································· 121
6.9.3 访问控制符································································································································ 122
6.10 包···········································································································································123
6.10.1 包的作用·································································································································· 123
6.10.2 包的创建·································································································································· 123
6.10.3 包的引用·································································································································· 123
6.10.4 向包中添加类·························································································································· 124
6.10.5 包的作用域······························································································································ 124
6.10.6 静态引用·································································································································· 124
6.11 接口·······································································································································125
6.11.1 接口概念·································································································································· 126
6.11.2 接口声明·································································································································· 126
6.11.3 接口的实现······························································································································ 127
6.12 静态变量······························································································································· 129
6.12.1 类(static)变量····················································································································· 129
6.12.2 类(static)方法····················································································································· 129
6.13 关键字final ···························································································································130
6.13.1 final 类····································································································································· 130
6.13.2 final 方法································································································································· 130
6.13.3 final 变量································································································································· 131
6.14 内部类···································································································································131
6.14.1 内部类定义······························································································································ 131
6.14.2 内部类属性······························································································································ 132
6.15 包装类···································································································································132
6.16 反射API································································································································133
6.16.1 反射API 特征························································································································· 133
6.16.2 反射机制应用实例·················································································································· 134
6.17 本章考试、面试问题分析···································································································135
6.18 实验:面向对象编程练习···································································································137
6.19 问题集锦与解答···················································································································140
6.20 自我检测······························································································································· 140
6.21 本章小结······························································································································· 141
第2 篇 Java 标准类包篇
第7 章 Java集合与工具类··································································································· 143
7.1 Java 集合·································································································································143
7.1.1 Java 语言的util类···················································································································· 143
7.1.2 Collection 接口·························································································································· 143
7.1.3 Collection 的功能方法·············································································································· 144
7.2 List 集合··································································································································145
7.2.1 LinkedList类····························································································································· 145
7.2.2 ArrayList 类······························································································································· 147
7.2.3 Vector 类···································································································································· 148
7.2.4 Stack 类····································································································································· 148
7.3 Set 集合···································································································································149
7.3.1 HashSet 类································································································································· 151
7.3.2 TreeSet 类·································································································································· 152
7.3.3 Lin
图书封面
评论、评分、阅读与下载