forked from JAVA-000/JAVA-000
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commited week 01 homeworks about jvm
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Mac OS | ||
.DS_Store | ||
|
||
# Maven | ||
target | ||
|
||
# IDEA | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5EA���������������������������������Ö��������֩��������������������������������������������������ѕ������������������췚����ߜ�������������������������������Г���а���������Г���Ь�������������곕���Ж�Я�������������앞��Ж�Я�����������������������׳����Г���Ь������֩�����������������������������������H��N��������������������������������������M����I��N������������������������������ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
0cbb4e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
图画的很清晰点赞,其他题目也可以尝试做做加油