Skip to content

Commit b8fcc7e

Browse files
committed
重构目录结构,增加源码目录
1 parent 41ff05e commit b8fcc7e

26 files changed

+223
-152
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
*.html
22
*.pdf
3+
.classpath
4+
.project
5+
.settings/
6+
.vscode/
7+
target
8+
*.iml
9+

README.adoc

Lines changed: 132 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,132 @@
1-
= JDK 源码分析
2-
3-
为了督促小组成员学习,也为了他们更好地成长,“强制”安排给他们阅读 JDK 常用类的源代码。
4-
5-
也欢迎感兴趣的小伙伴加入。或者提交PR。
6-
7-
WARNING: 本文档基于 *JDK 1.8.0_112* 的代码开展分析,请 PR 的小伙伴使用相同的 JDK。谢谢!
8-
9-
== 学习计划
10-
11-
大概列了一下,该计划后续还会慢慢更新。
12-
13-
=== 集合类
14-
15-
. `Collection`
16-
. `AbstractCollection`
17-
. `AbstractList`
18-
. `ArrayList`
19-
. `LinkedList`
20-
. `Map`
21-
. `AbstractMap`
22-
. `HashMap`
23-
. `LinkedHashMap`
24-
. `TreeMap`
25-
. `Queue`
26-
. `AbstractQueue`
27-
. `BlockingQueue`
28-
. `LinkedTransferQueue`
29-
. `SynchronousQueue`
30-
. `PriorityQueue`
31-
. `LinkedBlockingQueue`
32-
. `ArrayBlockingQueue`
33-
. `ConcurrentLinkedQueue`
34-
. `DelayQueue`
35-
. `Deque`
36-
. `BlockingDeque`
37-
. `LinkedBlockingDeque`
38-
. `ArrayDeque`
39-
. `ConcurrentLinkedDeque`
40-
41-
=== 并发类
42-
43-
. `AbstractQueuedSynchronizer`
44-
. `AbstractQueuedLongSynchronizer`
45-
46-
== 参考书籍
47-
48-
. https://book.douban.com/subject/26745780/[数据结构与算法分析]
49-
. https://book.douban.com/subject/10432347/[算法]
50-
. https://book.douban.com/subject/10484692/[Java并发编程实战]
1+
= JDK & STL 源码分析计划
2+
3+
为了学好数据结构以及相关算法,同时也为了更好地理解 JDK 的底层实现,计划对 JDK 集合类的源码做一个系统的阅读分析。
4+
5+
欢迎感兴趣的小伙伴提交 PR 或 Issue。
6+
7+
WARNING: 本文档基于 *JDK 1.8.0_201* 的代码开展分析,请 PR 的小伙伴使用相同的 JDK。谢谢!
8+
9+
== 总体思路
10+
11+
. 学习基本的数据结构认识。兵马未动粮草先行。先把基础理论搞清楚。
12+
.. 学Java的,可以从下面两本书中选一本:
13+
... https://book.douban.com/subject/26745780/[数据结构与算法分析] -- 这本书的优点在于和 Java JDK 的集合类很贴近。
14+
... https://book.douban.com/subject/19952400/[算法(第4版)] -- 这本书胜在图很多。
15+
.. 学 C/C++ 的,可以看下面这套书:
16+
... https://book.douban.com/subject/4065258/[算法:C语言实现 (第1~4部分)]
17+
... https://book.douban.com/subject/4191525/[算法:C语言实现 (第5部分)]
18+
. 自己实现一遍基本的数据结构;
19+
. 阅读 JDK 或 STL 源码,做学习笔记。
20+
+
21+
TIP: 对比一下自己的实现和这些经典代码的实现,总结自己差距,提高自己的编码能力。
22+
+
23+
.. https://book.douban.com/subject/1110934/[STL源码剖析 ] -- 阅读源码时,建议参考一下本书的内容。
24+
.. 建议把网上的源码分析笔记都看一看,取长补短,补充自己的分析。
25+
.. 建议把网上相关面试题也看一看,检验自己的学习成果。
26+
. 相关联的 LeetCode 上的题都刷掉。
27+
28+
[NOTE]
29+
====
30+
还有两个想法:
31+
32+
. 可以把 Redis 的实现也过一下,Redis 实现也有很多不错的思路。毕竟 Redis 是目前最常用的缓存解决方案。
33+
. Java 中有很多针对集合类做扩展的库,可以一并学了,这样就能更清楚了解 Java JDK 实现的不足,开阔自己的眼界:
34+
.. https://github.com/google/guava[google/guava: Google core libraries for Java]
35+
.. https://commons.apache.org/proper/commons-collections/[Apache Commons Collections]
36+
.. https://www.eclipse.org/collections/[Eclipse Collections - Features you want with the collections you need.]
37+
====
38+
39+
== JDK 集合类
40+
41+
*Base*::
42+
代码总行数: 103 + 604 + 469 = 1176 行,预计 2 个小时。
43+
. `java.lang.Iterable`
44+
. `java.util.Collection`
45+
. `java.util.AbstractCollection`
46+
47+
*List*::
48+
代码总行数: 734 + 781 + 253 + 1262 + 1456 + 141 + 1468 = 6095 行,预计 12 个小时。
49+
. `java.util.List`
50+
. `java.util.AbstractList`
51+
. `java.util.AbstractSequentialList`
52+
. `java.util.LinkedList`
53+
. `java.util.Vector`
54+
. `java.util.Stack`
55+
. `java.util.ArrayList`
56+
57+
*Queue*::
58+
代码总行数: 218 + 584 + 192 + 992 + 907 = 2893 行,预计 6 个小时。
59+
. `java.util.Queue`
60+
. `java.util.Deque`
61+
. `java.util.AbstractQueue`
62+
. `java.util.ArrayDeque`
63+
. `java.util.PriorityQueue`
64+
65+
*Set*::
66+
代码总行数: 413 + 186 + 264 + 464 + 319 + 361 + 560 + 195 + 1248 = 4010 行,预计 8 个小时。
67+
. `java.util.Set`
68+
. `java.util.AbstractSet`
69+
. `java.util.SortedSet`
70+
. `java.util.EnumSet`
71+
. `java.util.NavigableSet`
72+
. `java.util.HashSet`
73+
. `java.util.TreeSet`
74+
. `java.util.LinkedHashSet`
75+
. `java.util.BitSet`
76+
77+
78+
image::docs/java.util.Collection.png[]
79+
80+
*Map*::
81+
代码总行数: 1183 + 284 + 424 + 860 + 3019 + 1339 + 812 + 1600 + 756 + 2397 + 155 + 1422 = 14251 行,预计 28 个小时。
82+
. `java.util.Map`
83+
. `java.util.SortedMap`
84+
. `java.util.NavigableMap`
85+
. `java.util.AbstractMap`
86+
. `java.util.TreeMap`
87+
. `java.util.WeakHashMap`
88+
. `java.util.EnumMap`
89+
. `java.util.IdentityHashMap`
90+
. `java.util.LinkedHashMap`
91+
. `java.util.HashMap`
92+
. `java.util.Dictionary`
93+
. `java.util.Hashtable`
94+
95+
image::docs/java.util.Map.png[]
96+
97+
*Iterator*::
98+
代码总行数: 118 + 302 + 195 = 615 行,预计 2 个小时。
99+
. `java.util.Iterator`
100+
. `java.util.PrimitiveIterator`
101+
. `java.util.ListIterator`
102+
103+
来张总体结构图:
104+
105+
image::docs/jdk-collection-classes.png[]
106+
107+
TIP: 这里没有包含并发相关的集合类。这块内容放到并发中一起搞。
108+
109+
== 目录结构介绍
110+
111+
[source]
112+
----
113+
.
114+
├── LICENSE
115+
├── README.adoc
116+
├── pom.xml
117+
├── docs -- 这里存放阅读源码的文档。
118+
│   └── images -- 这里存放相关图片
119+
└── src
120+
├── main
121+
│   └── java
122+
│   └── com
123+
│   └── diguage
124+
│   └── truman
125+
│   └── App.java
126+
└── test
127+
└── java
128+
└── com
129+
└── diguage
130+
└── truman -- 这个目录存放相关测试代码。
131+
└── AppTest.java
132+
----
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

plan.adoc

Lines changed: 0 additions & 102 deletions
This file was deleted.

pom.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>com.diguage</groupId>
9+
<artifactId>truman</artifactId>
10+
<version>0.0.1-SNAPSHOT</version>
11+
12+
<name>JDK Source Analysis</name>
13+
<!-- <url>http://www.example.com</url>-->
14+
15+
<properties>
16+
<jmh.version>1.21</jmh.version>
17+
<junit.version>4.12</junit.version>
18+
<assertj.version>3.13.2</assertj.version>
19+
20+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21+
<maven.compiler.source>1.8</maven.compiler.source>
22+
<maven.compiler.target>1.8</maven.compiler.target>
23+
</properties>
24+
25+
<dependencies>
26+
<dependency>
27+
<groupId>org.openjdk.jmh</groupId>
28+
<artifactId>jmh-core</artifactId>
29+
<version>${jmh.version}</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.openjdk.jmh</groupId>
33+
<artifactId>jmh-generator-annprocess</artifactId>
34+
<version>${jmh.version}</version>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>junit</groupId>
39+
<artifactId>junit</artifactId>
40+
<version>${junit.version}</version>
41+
<scope>test</scope>
42+
</dependency>
43+
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
44+
<dependency>
45+
<groupId>org.assertj</groupId>
46+
<artifactId>assertj-core</artifactId>
47+
<version>${assertj.version}</version>
48+
<scope>test</scope>
49+
</dependency>
50+
</dependencies>
51+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.diguage.truman;
2+
3+
/**
4+
* Hello world!
5+
*
6+
*/
7+
public class App
8+
{
9+
public static void main( String[] args )
10+
{
11+
System.out.println( "Hello World!" );
12+
}
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.diguage.truman;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import org.junit.Test;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
{
12+
/**
13+
* Rigorous Test :-)
14+
*/
15+
@Test
16+
public void shouldAnswerWithTrue()
17+
{
18+
assertTrue( true );
19+
}
20+
}

0 commit comments

Comments
 (0)