Skip to content

Commit 45cf133

Browse files
committed
update
1 parent 962bd12 commit 45cf133

File tree

8 files changed

+138
-0
lines changed

8 files changed

+138
-0
lines changed

01jvm/out/production/01jvm/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,36 @@ java -Xmx2g -Xms2g -XX:+UseG1GC -verbose:gc -XX:+PrintGCDateStamps -XX:+PrintGCD
113113

114114
其中 [GCLogAnalysis.java](./GCLogAnalysis.java) 文件也可以从课件资料zip中找到.
115115

116+
## 几个命令用法
117+
### 1、十六进制方式查看文件
118+
`hexdump -C Hello.class`
119+
输出:`00000000 ca fe ba be 00 00 00 34 00 1c 0a 00 06 00 0e 09`
120+
121+
可以看到magic number: `cafe babe`
122+
以及`00 00 00 34`,十六进制34=十进制3*16+4=52,这是jdk8,如果是jdk11则是55,十六进制37.
123+
124+
### 2、Base64方式编码文件
125+
`base64 Hello.class`
126+
### 3、显示JVM默认参数
127+
```
128+
java -XX:+PrintFlagsFinal -version
129+
130+
java -XX:+PrintFlagsFinal -version | grep -F " Use" | grep -F "GC "
131+
132+
java -XX:+PrintFlagsFinal -version | grep MaxNewSize
133+
134+
```
135+
136+
### 4、切换不同jdk
137+
```
138+
jenv shell 1.8
139+
jenv shell 11
140+
```
141+
显示所有jdk
142+
```
143+
jenv versions
144+
```
145+
116146
## 更多资料
117147

118148
更多中英文的技术文章和参考资料: <https://github.com/cncounter/translation>

01jvm/subinterface/Mapper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package subinterface;
2+
3+
public interface Mapper<T> {
4+
5+
void insert(T t);
6+
7+
}

01jvm/subinterface/User.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package subinterface;
2+
3+
public class User {
4+
private int id;
5+
6+
public User(int id) {
7+
this.id = id;
8+
}
9+
10+
public int getId() {
11+
return id;
12+
}
13+
14+
public void setId(int id) {
15+
this.id = id;
16+
}
17+
}

01jvm/subinterface/UserDAO.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package subinterface;
2+
3+
public class UserDAO implements UserMapper {
4+
5+
@Override
6+
public void insert(User user) {
7+
System.out.println("Insert user id: " + user.getId());
8+
}
9+
}

01jvm/subinterface/UserMain.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package subinterface;
2+
3+
public class UserMain {
4+
5+
public static void main(String[] args) {
6+
UserDAO dao = new UserDAO();
7+
dao.insert(new User(123));
8+
}
9+
10+
}

01jvm/subinterface/UserMapper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package subinterface;
2+
3+
public interface UserMapper extends Mapper<User> {
4+
5+
@Override
6+
void insert(User user);
7+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package io.kimmking.java8;
2+
3+
import lombok.SneakyThrows;
4+
5+
import java.io.BufferedReader;
6+
import java.io.InputStream;
7+
import java.io.InputStreamReader;
8+
9+
public class ResourceLoader {
10+
11+
static String file = "conf/a.properties";
12+
13+
public static void main(String[] args) {
14+
15+
// testClassLoaderRootPath(); // classloader方式不能加根路径,否则文件路径会直接被替换掉最终成了 /conf/a.properties
16+
testClassLoader(); // 从当前的classpath,不管是 文件夹,还是jar里去找 资源
17+
testClassRootPath(); // 判断第一个字符是根路径,去掉根,转成 testClassLoader 调用
18+
// testClass(); // class 方式必须加根路径,不加根会根据类路径io.kimmking.java8.ResourceLoader 去拼成 io/kimmking/java8/conf/a.properties
19+
20+
21+
}
22+
23+
private static void testClassLoader() {
24+
System.out.println("====> testClassLoader");
25+
loadStream(ResourceLoader.class.getClassLoader().getResourceAsStream(file));
26+
}
27+
28+
private static void testClassLoaderRootPath() {
29+
System.out.println("====> testClassLoader");
30+
loadStream(ResourceLoader.class.getClassLoader().getResourceAsStream("/"+file));
31+
}
32+
33+
private static void testClass() {
34+
System.out.println("====> testClass");
35+
loadStream(ResourceLoader.class.getResourceAsStream(file));
36+
}
37+
38+
private static void testClassRootPath() {
39+
System.out.println("====> testClassRootPath");
40+
loadStream(ResourceLoader.class.getResourceAsStream("/"+file));
41+
}
42+
43+
@SneakyThrows
44+
private static void loadStream(InputStream in) {
45+
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
46+
StringBuffer buffer = new StringBuffer();
47+
String line = null;
48+
while ((line = reader.readLine()) != null) {
49+
buffer.append(line);
50+
}
51+
System.out.println(buffer.toString());
52+
reader.close();
53+
in.close();
54+
}
55+
56+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a=1
2+
b=2

0 commit comments

Comments
 (0)