内容介绍
本书是Java语言的经典教材,多年来畅销不衰。本书全面整合了Java 8的特性,采用“基础优先,问题驱动”的教学方式,循序渐进地介绍了程序设计基础、解决问题的方法、面向对象程序设计、图形用户界面设计、异常处理、I/O和递归等内容。此外,本书还全面且深入地覆盖了一些GJ主题,包括算法和数据结构、多线程、网络、GJ化、GJGUI等内容。
目录
D19章 泛型 1
19.1 引言 2
19.2 动机和优点 2
19.3 定义泛型类和接口 4
19.4 泛型方法 6
19.5 示例学习:对一个对象数组进行排序 8
19.6 原生类型和向后兼容 10
19.7 通配泛型 11
19.8 泛型的擦除和限制 14
19.9 示例学习:泛型矩阵类 16
D20章 线性表、栈、队列和优先队列 25
20.1 引言 26
20.2 集合 26
20.3 迭代器 30
20.4 使用forEach方法 31
20.5 线性表 32
20.6 Comparator接口 37
20.7 线性表和集合的静态方法 41
20.8 示例学习:弹球 44
20.9 向量类和栈类 48
20.10 队列和优先队列 49
20.11 示例学习:表达式求值 53
D21章 规则集和映射 65
21.1 引言 66
21.2 规则集 66
21.3 比较规则集和线性表的性能 74
21.4 示例学习:关键字计数 77
21.5 映射 78
21.6 示例学习:单词的出现次数 83
21.7 单元素与不可变的集合和映射 85
D22章 开发高效算法 89
22.1 引言 90
22.2 使用大O标记来衡量算法效率 90
22.3 示例:确定大O 92
22.4 分析算法的时间复杂度 96
22.5 使用动态编程寻找斐波那契数 99
22.6 使用欧几里得算法求Z大公约数 101
22.7 寻找素数的高效算法 105
22.8 使用分而治之法寻找Z近点对 111
22.9 使用回溯法解决八皇后问题 114
22.10 计算几何:寻找凸包 117
D23章 排序 131
23.1 引言 132
23.2 插入排序 132
23.3 冒泡排序 134
23.4 归并排序 137
23.5 快速排序 140
23.6 堆排序 144
23.7 桶排序和基数排序 151
23.8 外部排序 153
D24章 实现线性表、栈、队列和优先队列 167
24.1 引言 168
24.2 线性表的通用操作 168
24.3 数组线性表 172
24.4 链表 179
24.5 栈和队列 193
24.6 优先队列 197
D25章 二叉搜索树 203
25.1 引言 204
25.2 二叉搜索树 204
25.3 删除BST中的一个元素 217
25.4 树的可视化和MVC 223
25.5 迭代器 226
25.6 示例学习:数据压缩 228
D26章 AVL树 239
26.1 引言 240
26.2 重新平衡树 240
26.3 为AVL树设计类 243
26.4 重写insert方法 244
26.5 实现旋转 245
26.6 实现delete方法 246
26.7 AVLTree类 246
26.8 测试 AVLTree类 252
26.9 AVL树的时间复杂度分析 255
D27章 散列 259
27.1 引言 260
27.2 什么是散列 260
27.3 散列函数和散列码 261
27.4 使用开放地址法处理冲突 263
27.5 使用分离链接法处理冲突 267
27.6 装填因子和再散列 267
27.7 使用散列实现映射 269
27.8 使用散列实现规则集 278
D28章 图及其应用 289
28.1 引言 290
28.2 基本的图术语 291
28.3 表示图 292
28.4 图的建模 298
28.5 图的可视化 308
28.6 图的遍历 311
28.7 深度优先搜索 312
28.8 示例学习:连通圆问题 316
28.9 广度优先搜索 318
28.10 示例学习:9枚硬币反面问题 321
D29章 加权图及其应用 335
29.1 引言 336
29.2 加权图的表示 337
29.3 WeightedGraph类 339
29.4 Z小生成树 347
29.5 寻找Z短路径 353
29.6 示例学习:加权的9枚硬币反面问题 362
D30章 集合流的聚合操作 373
30.1 引言 374
30.2 流管道 374
30.3 IntStream、LongStream和DoubleStream 380
30.4 并行流 383
30.5 使用reduce方法进行流的归约 385
30.6 使用collect方法进行流的归约 388
30.7 使用groupingBy收集器进行元素分组 391
30.8 示例学习 394
附录A Java关键字 405
附录B ASCII字符集 406
附录C 操作符优先级表 408
附录D Java修饰符 410
附录E 特殊浮点值 412
附录F 数系 413
附录G 位操作符 417
附录H 正则表达式 418
附录I 枚举类型 423
Contents
chapter 19 generics 1
19.1 Introduction 2
19.2 Motivations and Benefits 2
19.3 Defining Generic Classes and Interfaces 4
19.4 Generic Methods 6
19.5 Case Study: Sorting an Array of Objects 8
19.6 Raw Types and Backward Compatibility 10
19.7 Wildcard Generic Types 11
19.8 Erasure and Restrictions on Generics 14
19.9 Case Study: Generic Matrix Class 16
chapter 20 Lists, Stacks, Queues, and Priority Queues 25
20.1 Introduction 26
20.2 Collections 26
20.3 Iterators 30
20.4 Using the forEach Method 31
20.5 Lists 32
20.6 The Comparator Interface 37
20.7 Static Methods for Lists and Collections 41
20.8 Case Study: Bouncing Balls 44
20.9 Vector and Stack Classes 48
20.10 Queues and Priority Queues 49
20.11 Case Study: Evaluating Expressions 53
chapter 21 Sets and maps 65
21.1 Introduction 66
21.2 Sets 66
21.3 Comparing the Performance of Sets and Lists 74
21.4 Case Study: Counting Keywords 77
21.5 Maps 78
21.6 Case Study: Occurrences of Words 83
21.7 Singleton and Unmodifiable Collections and Maps 85
chapter 22 developing efficient algorithms 89
22.1 Introduction 90
22.2 Measuring Algorithm Efficiency Using Big O Notation 90
22.3 Examples: Determining Big O 92
22.4 Analyzing Algorithm Time Complexity 96
22.5 Finding Fibonacci Numbers Using Dynamic Programming 99
22.6 Finding Greatest Common Divisors Using Euclid’s Algorithm 101
22.7 Efficient Algorithms for Finding Prime Numbers 105
22.8 Finding the Closest Pair of Points Using Divide-and-Conquer 111
22.9 Solving the Eight Queens Problem Using Backtracking 114
22.10 Computational Geometry: Finding a Convex Hull 117
chapter 23 Sorting 131
23.1 Introduction 132
23.2 Insertion Sort 132
23.3 Bubble Sort 134
23.4 Merge Sort 137
23.5 Quick Sort 140
23.6 Heap Sort 144
23.7 Bucket and Radix Sorts 151
23.8 External Sort 153
chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues 167
24.1 Introduction 168
24.2 Common Operations for Lists 168
24.3 Array Lists 172
24.4 Linked Lists 179
24.5 Stacks and Queues 193
24.6 Priority Queues 197
chapter 25 Binary Search trees 203
25.1 Introduction 204
25.2 Binary Search Trees 204
25.3 Deleting Elements from a BST 217
25.4 Tree Visualization and MVC 223
25.5 Iterators 226
25.6 Case Study: Data Compression 228
chapter 26 avL trees 239
26.1 Introduction 240
26.2 Rebalancing Trees 240
26.3 Designing Classes for AVL Trees 243
26.4 Overriding the insert Method 244
26.5 Implementing Rotations 245
26.6 Implementing the delete Method 246
26.7 The AVLTree Class 246
26.8 Testing the AVLTree Class 252
26.9 AVL Tree Time Complexity Analysis 255
chapter 27 hashing 259
27.1 Introduction 260
27.2 What Is Hashing? 260
27.3 Hash Functions and Hash Codes 261
27.4 Handling Collisions Using Open Addressing 263
27.5 Handling Collisions Using Separate Chaining 267
27.6 Load Factor and Rehashing 267
27.7 Implementing a Map Using Hashing 269
27.8 Implementing Set Using Hashing 278
chapter 28 graphs and applications 289
28.1 Introduction 290
28.2 Basic Graph TermiDlogies 291
28.3 Representing Graphs 292
28.4 Modeling Graphs 298
28.5 Graph Visualization 308
28.6 Graph Traversals 311
28.7 Depth-First Search (DFS) 312
28.8 Case Study: The Connected Circles Problem 316
28.9 Breadth-First Search (BFS) 318
28.10 Case Study: The Nine Tails Problem 321
chapter 29 Weighted graphs and applications
29.1 Introduction
29.2 Representing Weighted Graphs
29.3 The WeightedGraph Class
29.4 Minimum Spanning Trees
29.5 Finding Shortest Paths
29.6 Case Study: The Weighted Nine Tails Problem
chapter 30 Aggregate operations for collection Streams
30.1 Introduction
30.2 Stream Pipelines
30.3 IntStream, LongStream, and DoubleStream
30.4 Parallel Streams
30.5 Stream Reduction Using the reduce Method
30.6 Stream Reduction Using the collect Method
30.7 Grouping Elements Using the groupingby Collector
30.8 Case Studies
Appendix A Java Keywords 405
Appendix B The aScII character Set 406
Appendix C Operator Precedence chart 408
Appendix D Java modifiers 410
Appendix E Special floating-Point values 412
Appendix F Number Systems 413
Appendix G Bitwise operations 417
Appendix H Regular expressions 418
Appendix I Enumerated types 423