Skip to content

Commit 59ce23b

Browse files
committed
feat: jdk17
1 parent 677e393 commit 59ce23b

File tree

9 files changed

+231
-13
lines changed

9 files changed

+231
-13
lines changed

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,23 @@
135135
- Remove the Solaris and SPARC Ports(删除 Solaris 和 SPARC 端口)
136136
- 外部存储器访问 API(允许Java 应用程序安全有效地访问 Java 堆之外的外部内存。)
137137
- Record类型二次预览(在Java 14就预览过啦)
138+
139+
140+
### [JDK 17](java-17)
141+
142+
---
143+
144+
- [306:Restore Always-Strict Floating-PointSemantics / 恢复始终严格的浮点语义](java-17/src/main/java/com/di1shuai/java17/strictfpcase/StrictfpCase.java)
145+
- [356:Enhanced Pseudo-Random Number Generators / 增强型伪随机数发生器](java-17/src/main/java/com/di1shuai/java17/random/RandomCase.java)
146+
- 382:New macOS Rendering Pipeline / 新的 macOS 渲染管道
147+
- 391:macOS/AArch64 Port / macOS/AArch64 平台支持
148+
- 398:Deprecate the Applet API for Removal / 弃用即将删除的Applet API
149+
- 403:Strongly Encapsulate JDK Internals / 强封装JDK的内部API
150+
- [406:Pattern Matching for switch(Preview) / Switch模式匹配(预览)](java-17/src/main/java/com/di1shuai/java17/instanceofcase/InstanceOfCase.java)
151+
- 407:Remove RMI Activation / 删除 RMI 激活机制
152+
- 409:Sealed Classes / 密封类
153+
- 410:Remove the Experimental AOT and JIT Compiler / 删除实验性 AOT 和 JIT 编译器
154+
- 411:Deprecate the Security Manager For Removal / 弃用即将删除的安全管理器
155+
- 412:Foreign Function & Memory API(Incubator) / 外部函数和内存 API(孵化器)
156+
- 414:Vector API (Second Incubator) / 矢量 API(二次孵化)
157+
- 415:Context-Specific Deserialization Filters / 特定于上下文的反序列化过滤器

java-17/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
### [JDK 17](java-17)
2+
3+
---
4+
5+
- [306:Restore Always-Strict Floating-PointSemantics / 恢复始终严格的浮点语义](src/main/java/com/di1shuai/java17/strictfpcase/StrictfpCase.java)
6+
- [356:Enhanced Pseudo-Random Number Generators / 增强型伪随机数发生器](src/main/java/com/di1shuai/java17/random/RandomCase.java)
7+
- 382:New macOS Rendering Pipeline / 新的 macOS 渲染管道
8+
- 391:macOS/AArch64 Port / macOS/AArch64 平台支持
9+
- 398:Deprecate the Applet API for Removal / 弃用即将删除的Applet API
10+
- 403:Strongly Encapsulate JDK Internals / 强封装JDK的内部API
11+
- [406:Pattern Matching for switch(Preview) / Switch模式匹配(预览)](src/main/java/com/di1shuai/java17/instanceofcase/InstanceOfCase.java)
12+
- 407:Remove RMI Activation / 删除 RMI 激活机制
13+
- 409:Sealed Classes / 密封类
14+
- 410:Remove the Experimental AOT and JIT Compiler / 删除实验性 AOT 和 JIT 编译器
15+
- 411:Deprecate the Security Manager For Removal / 弃用即将删除的安全管理器
16+
- 412:Foreign Function & Memory API(Incubator) / 外部函数和内存 API(孵化器)
17+
- 414:Vector API (Second Incubator) / 矢量 API(二次孵化)
18+
- 415:Context-Specific Deserialization Filters / 特定于上下文的反序列化过滤器

java-17/pom.xml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.di1shuai</groupId>
8+
<artifactId>java-17</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>17</maven.compiler.source>
13+
<maven.compiler.target>17</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>org.apache.maven.plugins</groupId>
20+
<artifactId>maven-compiler-plugin</artifactId>
21+
<configuration>
22+
<source>17</source>
23+
<target>17</target>
24+
<compilerArgs>--enable-preview</compilerArgs>
25+
</configuration>
26+
</plugin>
27+
</plugins>
28+
</build>
29+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.di1shuai.java17;
2+
3+
4+
/**
5+
* @author shea
6+
* @since 2022/11/21
7+
*/
8+
public class Main {
9+
10+
public static void main(String[] args) {
11+
12+
}
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package com.di1shuai.java17.instanceofcase;
2+
3+
/**
4+
* @author shea
5+
* @since 2022/11/21
6+
*/
7+
public class InstanceOfCase {
8+
9+
public static void main(String[] args) {
10+
JDK17_instanceof_switch(1);
11+
}
12+
13+
public static void JDK17_instanceof_switch(Object o) {
14+
switch (o) {
15+
case Integer i -> System.out.println(i);
16+
case Long l -> System.out.println(l);
17+
case Double d -> System.out.println(d);
18+
case String s -> System.out.println(s);
19+
default -> System.out.println("UNKNOWN");
20+
}
21+
}
22+
public static void JDK17_before_instanceof_switch(Object o) {
23+
//o instanceof Integer i 为JDK16新特性
24+
if (o instanceof Integer i) {
25+
System.out.println(i);
26+
} else if (o instanceof Long l) {
27+
System.out.println(l);
28+
} else if (o instanceof Double d) {
29+
System.out.println(d);
30+
} else if (o instanceof String s) {
31+
System.out.println(s);
32+
} else {
33+
System.out.println("UNKNOWN");
34+
}
35+
}
36+
37+
public static void JDK13_switch() {
38+
String day = "MONDAY";
39+
int i = switch (day) {
40+
case "MONDAY" -> 1;
41+
case "TUESDAY" -> 2;
42+
case "WEDNESDAY" -> 3;
43+
case "THURSDAY" -> 4;
44+
case "FRIDAY" -> 5;
45+
case "SATURDAY" -> 6;
46+
case "SUNDAY" -> 7;
47+
default -> 0;
48+
};
49+
System.out.println(i);
50+
}
51+
public static void JDK12_switch() {
52+
String day = "MONDAY";
53+
switch (day) {
54+
case "MONDAY" -> System.out.println(1);
55+
case "TUESDAY" -> System.out.println(2);
56+
case "WEDNESDAY" -> System.out.println(3);
57+
case "THURSDAY" -> System.out.println(4);
58+
case "FRIDAY" -> System.out.println(5);
59+
case "SATURDAY" -> System.out.println(6);
60+
case "SUNDAY" -> System.out.println(7);
61+
default -> System.out.println(0);
62+
}
63+
}
64+
public static void JDK11_switch() {
65+
String day = "MONDAY";
66+
switch (day) {
67+
case "MONDAY":
68+
System.out.println(1);
69+
break;
70+
case "TUESDAY":
71+
System.out.println(2);
72+
break;
73+
case "WEDNESDAY":
74+
System.out.println(3);
75+
break;
76+
case "THURSDAY":
77+
System.out.println(4);
78+
break;
79+
case "FRIDAY":
80+
System.out.println(5);
81+
break;
82+
case "SATURDAY":
83+
System.out.println(6);
84+
break;
85+
case "SUNDAY":
86+
System.out.println(7);
87+
break;
88+
default:
89+
System.out.println(0);
90+
break;
91+
}
92+
}
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.di1shuai.java17.random;
2+
3+
import java.util.random.RandomGenerator;
4+
import java.util.random.RandomGeneratorFactory;
5+
6+
/**
7+
* @author shea
8+
* @since 2022/11/21
9+
*/
10+
public class RandomCase {
11+
12+
13+
public static void main(String[] args){
14+
RandomGeneratorFactory.all().forEach(e -> System.out.println(e.group() + "-" + e.name()));
15+
//生成10个10以内的随机数
16+
RandomGeneratorFactory<RandomGenerator> L128X1024MixRandom = RandomGeneratorFactory.of("L128X1024MixRandom");
17+
RandomGenerator randomGenerator = L128X1024MixRandom.create(System.currentTimeMillis());
18+
for (int i = 0; i < 10; i++) {
19+
System.out.println(randomGenerator.nextInt(10));
20+
}
21+
}
22+
23+
24+
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.di1shuai.java17.strictfpcase;
2+
3+
/**
4+
* @author shea
5+
* @since 2022/11/21
6+
* 严格的浮点数学计算 strictfp
7+
*
8+
*/
9+
public strictfp class StrictfpCase {
10+
11+
12+
public strictfp double calculate() {
13+
// ......
14+
return 0.0;
15+
}
16+
17+
18+
}

java-base/src/main/java/com/di1shuai/base/jvm/classloader/JVMClassLoader.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ public class JVMClassLoader {
1010
public static void main(String[] args) {
1111
// null -> Bootstrap
1212
// 为什么为Null,因为Bootstrap使用C++写的,在Java中没有与之相对应的类,所以返回了空值
13-
System.out.println(String.class.getClassLoader());
14-
13+
System.out.println(String.class.getClassLoader());
14+
1515
//sun.misc.Launcher$ExtClassLoader@3d4eac69 -> Extention
16-
System.out.println(sun.net.spi.nameservice.dns.DNSNameService.class.getClassLoader());
17-
16+
// System.out.println(sun.net.spi.nameservice.dns.DNSNameService.class.getClassLoader());
17+
1818
//sun.misc.Launcher$AppClassLoader@6d06d69c -> App
1919
System.out.println(JVMClassLoader.class.getClassLoader());
20-
21-
22-
20+
21+
22+
2323
//双亲委派
2424
System.out.println("===================");
2525
// null -> Bootstrap
26-
System.out.println(sun.net.spi.nameservice.dns.DNSNameService.class.getClassLoader().getClass().getClassLoader());
26+
// System.out.println(sun.net.spi.nameservice.dns.DNSNameService.class.getClassLoader().getClass().getClassLoader());
2727
// null -> Bootstrap
2828
System.out.println(JVMClassLoader.class.getClassLoader().getClass().getClassLoader());
29-
29+
3030
// app -> extention -> bootstrap
3131
System.out.println(JVMClassLoader.class.getClassLoader().getParent());
3232
System.out.println(JVMClassLoader.class.getClassLoader().getParent().getParent());

pom.xml

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
<version>1.0-SNAPSHOT</version>
1111
<modules>
1212
<module>java-base</module>
13+
<module>java-7</module>
1314
<module>java-8</module>
14-
<module>java-11</module>
15-
<module>java-15</module>
1615
<module>java-9</module>
17-
<module>java-7</module>
1816
<module>java-10</module>
17+
<module>java-11</module>
1918
<module>java-12</module>
2019
<module>java-13</module>
2120
<module>java-14</module>
21+
<module>java-15</module>
22+
<module>java-17</module>
2223
</modules>
2324

2425
<dependencyManagement>
@@ -32,4 +33,4 @@
3233
</dependencies>
3334
</dependencyManagement>
3435

35-
</project>
36+
</project>

0 commit comments

Comments
 (0)