Skip to content

Commit

Permalink
commited week 01 homeworks about jvm
Browse files Browse the repository at this point in the history
  • Loading branch information
listart committed Oct 19, 2020
1 parent 76e78de commit 0cbb4e4
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Mac OS
.DS_Store

# Maven
target

# IDEA
.idea
15 changes: 15 additions & 0 deletions Week_01/subject2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>me.listart</groupId>
<artifactId>jvm</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
</project>
40 changes: 40 additions & 0 deletions Week_01/subject2/src/main/java/jvm/XlassLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package jvm;

import java.io.InputStream;
import java.lang.reflect.Method;

public class XlassLoader extends ClassLoader {
public static void main(String[] args) {
try {
Class<?> cls = new XlassLoader().findClass("Hello");
Method hello = cls.getDeclaredMethod("hello");

hello.invoke(cls.newInstance());
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
System.out.println("name = " + name);

InputStream is = XlassLoader.class.getResourceAsStream(name + ".xlass");

if (is == null)
return super.findClass(name);

try {
byte[] bytes = new byte[is.available()];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) (255 - is.read());
}

return defineClass(name, bytes, 0, bytes.length);
} catch (Exception e) {
e.printStackTrace();
}

return super.findClass(name);
}
}
1 change: 1 addition & 0 deletions Week_01/subject2/src/main/resources/jvm/Hello.xlass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5EA���������������������������������Ö��������֩���������𳖑�����������������������������������������ѕ������������������췚����ߜ�������������������������������Г���а���������Г���Ь�������������곕���Ж�Я�������������앞��Ж�Я�����������������������׳����Г���Ь������֩�����������������������������������H��N��������������������������������������M����I��N������������������������������
Binary file added Week_01/subject3/java-cmd-memory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit 0cbb4e4

@likkas1027
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

图画的很清晰点赞,其他题目也可以尝试做做加油

Please sign in to comment.