由於coursera課程中老師會透過javap來講解程式碼,所以這邊介紹怎麼讓Eclipse呼叫javap。
如何新增javap指令
- 工具列點選Run ->External Tools -> External Tools Configurations
- 右鍵點選左側欄位內的Program,選擇"New",操作畫面如下圖
- 參數設定如下:
到此就設定完成。
如何使用javap
使用javap指令時,點選工具列的Run ->External Tools -># javap (或是自定義的名稱)。
範例程式碼如下:
class JavaPConstructor
{
int a =2000;
JavaPConstructor(){
this.a =3000;
}
}
javap結果如下:
Classfile /D:/Dropbox/LunaJava/Java_week2/bin/JavaPConstructor.class
Last modified 2015/6/15; size 325 bytes
MD5 checksum cb4bbe5f2e1c238318c90a31ba79514a
Compiled from "JavaPConstructor.java"
class JavaPConstructor
minor version: 0
major version: 52
flags: ACC_SUPER
Constant pool:
#1 = Class #2 // JavaPConstructor
#2 = Utf8 JavaPConstructor
#3 = Class #4 // java/lang/Object
#4 = Utf8 java/lang/Object
#5 = Utf8 a
#6 = Utf8 I
#7 = Utf8 <init>
#8 = Utf8 ()V
#9 = Utf8 Code
#10 = Methodref #3.#11 // java/lang/Object."<init>":()V
#11 = NameAndType #7:#8 // "<init>":()V
#12 = Fieldref #1.#13 // JavaPConstructor.a:I
#13 = NameAndType #5:#6 // a:I
#14 = Utf8 LineNumberTable
#15 = Utf8 LocalVariableTable
#16 = Utf8 this
#17 = Utf8 LJavaPConstructor;
#18 = Utf8 SourceFile
#19 = Utf8 JavaPConstructor.java
{
int a;
descriptor: I
flags:
JavaPConstructor();
descriptor: ()V
flags:
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10 // Method java/lang/Object."<init>":()V
4: aload_0
5: sipush 2000
8: putfield #12 // Field a:I
11: aload_0
12: sipush 3000
15: putfield #12 // Field a:I
18: return
LineNumberTable:
line 4: 0
line 3: 4
line 5: 11
line 6: 18
LocalVariableTable:
Start Length Slot Name Signature
0 19 0 this LJavaPConstructor;
}
SourceFile: "JavaPConstructor.java"
Comments
Post a Comment