Skip to content

Commit 5a2c497

Browse files
committed
Add Stage 2 Lesson 1
1 parent 89ad504 commit 5a2c497

File tree

10 files changed

+191
-0
lines changed

10 files changed

+191
-0
lines changed

「一入 Java 深似海 」/代码/segmentfault/deep-in-java/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<name>「一入 Java 深似海 」系列</name>
1212
<modules>
1313
<module>stage-1</module>
14+
<module>stage-2</module>
1415
</modules>
1516

1617
<build>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>stage-2</artifactId>
7+
<groupId>com.segmentfault</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>stage-2-lesson-1</artifactId>
14+
15+
<dependencies>
16+
17+
<dependency>
18+
<groupId>org.springframework</groupId>
19+
<artifactId>spring-context</artifactId>
20+
<version>5.1.3.RELEASE</version>
21+
</dependency>
22+
23+
<dependency>
24+
<groupId>commons-lang</groupId>
25+
<artifactId>commons-lang</artifactId>
26+
<version>2.6</version>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>commons-collections</groupId>
31+
<artifactId>commons-collections</artifactId>
32+
<version>3.2.2</version>
33+
</dependency>
34+
35+
</dependencies>
36+
37+
<build>
38+
<plugins>
39+
<plugin>
40+
<groupId>org.apache.maven.plugins</groupId>
41+
<artifactId>maven-compiler-plugin</artifactId>
42+
<version>3.8.0</version>
43+
<configuration>
44+
<source>11</source>
45+
<target>11</target>
46+
</configuration>
47+
</plugin>
48+
</plugins>
49+
</build>
50+
51+
52+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.segmentfault.deep.in.java.modular;
2+
3+
import java.lang.module.ModuleDescriptor;
4+
5+
public class ModuleReflectionDemo {
6+
7+
public static void main(String[] args) {
8+
9+
Class klass = ModuleReflectionDemo.class;
10+
11+
Module module = klass.getModule();
12+
13+
String moduleName = module.getName();
14+
15+
System.out.printf("类 %s 存在于模块 : %s 之中\n", klass.getName(), moduleName);
16+
17+
ModuleDescriptor moduleDescriptor = module.getDescriptor();
18+
19+
moduleDescriptor.requires().stream().forEach(requires -> {
20+
System.out.printf("requires 模块名称 %s,修饰符定义: %s \n", requires.name(), requires.modifiers());
21+
}
22+
);
23+
24+
moduleDescriptor.exports().stream().forEach(exports -> {
25+
System.out.printf("exports 包名称 %s,targets: %s \n", exports.source(), exports.targets());
26+
});
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.segmentfault.deep.in.java.modular;
2+
3+
import java.util.logging.Logger;
4+
5+
public class TransitiveRequiresDemo {
6+
7+
public static void main(String[] args) {
8+
Logger logger = Logger.getLogger("main");
9+
logger.info("Hello,World!");
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.segmentfault.deep.in.java.modular;
2+
3+
import org.apache.commons.collections.MapUtils;
4+
import org.apache.commons.lang.StringUtils;
5+
import org.springframework.context.ConfigurableApplicationContext;
6+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
7+
8+
import java.util.Collections;
9+
10+
public class UnnamedModuleDemo {
11+
12+
public static void main(String[] args) {
13+
MapUtils.isEmpty(Collections.emptyMap());
14+
StringUtils.isBlank("OK");
15+
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
16+
context.close();
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module lesson1 {
2+
// requires 内部依赖
3+
// 命名模块
4+
// artifact 资源根 package 存有 module-info.class(包含模块名称)
5+
requires java.base; // 默认依赖
6+
requires java.sql; // 传递依赖 requires transitive
7+
requires java.compiler; // exports 控制可访问的 API 包
8+
9+
// 非命名模块
10+
requires transitive spring.context;
11+
requires transitive commons.lang; // 规律:
12+
// Maven artifactId(jar或者war文件)中横划(画)线 "-"
13+
// 在模块化名称使用 "."
14+
requires transitive commons.collections;
15+
16+
// exports 供外部访问
17+
exports com.segmentfault.deep.in.java.modular;
18+
}

「一入 Java 深似海 」/代码/segmentfault/deep-in-java/stage-2/lesson-1/src/main/resources/META-INF/services/java.sql.Driver

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>deep-in-java</artifactId>
7+
<groupId>com.segmentfault</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>stage-2</artifactId>
14+
<packaging>pom</packaging>
15+
<modules>
16+
<module>lesson-1</module>
17+
</modules>
18+
19+
</project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# [「一入 Java 深似海 」系列课程](https://segmentfault.com/n/1330000017785588)
2+
3+
4+
## 第二期:Java 集合框架
5+
6+
### [第一节 Java 模块化设计](https://segmentfault.com/l/1500000018003647)
7+
8+
- 主要内容
9+
- 模块化构建:Java、Maven、IDE 等构建方式
10+
11+
- 模块化迁移:类库迁移、依赖管理分析、迁移案例等)
12+
13+
- 模块化设计:模块解析、模块API 设计
14+
15+
- 模块化反射:模块内省、模块运行时调整、模块注解
16+
17+
- 课程总结
18+
19+
20+
21+
### [第二节 Java 集合(Collections)框架基础运用](https://segmentfault.com/l/1500000018003713)
22+
23+
- 主要内容
24+
- 语义接口:包括 `Collection``Set``List``Queue``Map` 等核心接口
25+
- 内建实现:讨论 JDK 中内建的集合接口实现,并且说明同类实现中的使用场景,如 `Vector``ArrayList` 以及 `LinkedList` 场景
26+
- 抽象实现:介绍 Java 集合框架的骨架实现,如 `AbstractCollection``AbstractSet`以及 `AbstractList` 等抽象类
27+
28+
29+
30+
### [第三节 Java 集合(Collections)框架高级运用](https://segmentfault.com/l/1500000018003765)
31+
32+
- 主要内容
33+
- Wrapper 实现:unmodifiable、synchronized 集合接口的使用场景
34+
- 适配实现:讨论`Set` 转变为 `Map`,以及 `Deque` 实现 LIFO 的 `Queue` 实现
35+
- 特殊实现:如 `WeakHashMap``IdentityHashMap` 等特殊实现的使用场景
36+
- 工厂方法:`List``Set` 以及 `Map` 的便利工厂方法运用,以及单体和副本的操作方法
37+
38+
39+
40+
### [第四节 Java 集合(Collections)框架算法运用](https://segmentfault.com/l/1500000018003874)
41+
42+
- 主要内容
43+
- 排序算法:主要讨论 JDK 中出现过的排序算法,如 Insertion Sort、Merge Sort 、以及 TimSort,包括基本思路、时间和空间复杂度
44+
- 搜索算法:讨论二进制搜索算法,如 `Collections#binarySearch` 方法

0 commit comments

Comments
 (0)