命令:
javap -verbose xxx.class
样例源码
package hello;
public class TestJava{
private int a=0;
private String str="hello,world";
public TestJava(){
}
}
步骤:
1:新建TestJava.java
文件内容如上。
2:在工作目录下使用命令行javac TestJava.java
3 :使用命令javap -verbose TestJava.class
命令查看class文件
输出结果:
F:\JavaTest>javap -verbose TestJava.class
Classfile /F:/JavaTest/TestJava.class
Last modified 2017年11月7日; size 307 bytes
MD5 checksum e539338263497deca6b52f686299e12c
Compiled from "TestJava.java"
public class hello.TestJava
minor version: 0
major version: 53
flags: (0x0021) ACC_PUBLIC, ACC_SUPER
this_class: #5 // hello/TestJava
super_class: #6 // java/lang/Object
interfaces: 0, fields: 2, methods: 1, attributes: 1
Constant pool:
#1 = Methodref #6.#17 // java/lang/Object."<init>":()V
#2 = Fieldref #5.#18 // hello/TestJava.a:I
#3 = String #19 // hello,world
#4 = Fieldref #5.#20 // hello/TestJava.str:Ljava/lang/String;
#5 = Class #21 // hello/TestJava
#6 = Class #22 // java/lang/Object
#7 = Utf8 a
#8 = Utf8 I
#9 = Utf8 str
#10 = Utf8 Ljava/lang/String;
#11 = Utf8 <init>
#12 = Utf8 ()V
#13 = Utf8 Code
#14 = Utf8 LineNumberTable
#15 = Utf8 SourceFile
#16 = Utf8 TestJava.java
#17 = NameAndType #11:#12 // "<init>":()V
#18 = NameAndType #7:#8 // a:I
#19 = Utf8 hello,world
#20 = NameAndType #9:#10 // str:Ljava/lang/String;
#21 = Utf8 hello/TestJava
#22 = Utf8 java/lang/Object
{
public hello.TestJava();
descriptor: ()V
flags: (0x0001) ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: aload_0
5: iconst_0
6: putfield #2 // Field a:I
9: aload_0
10: ldc #3 // String hello,world
12: putfield #4 // Field str:Ljava/lang/String;
15: return
LineNumberTable:
line 5: 0
line 3: 4
line 4: 9
line 7: 15
}
SourceFile: "TestJava.java"
输出结果的含义:
minor version: 0
次版本号
major version: 53
主版本号
flags: (0x0021) ACC_PUBLIC, ACC_SUPER
访问标志
标志 | 名称 |
---|---|
ACC_PUBLIC | 0x0001 |
ACC_PRIVATE | 0x0002 |
ACC_PROTECTED | 0x0004 |
ACC_STATIC | 0x0008 |
ACC_FINAL | 0x0010 |
ACC_SUPER ACC_SYNCHRONIZED | 0x0020 |
ACC_VOLATILE ACC_BRIDGE | 0x0040 |
ACC_TRANSIENT | 0x0080 |
ACC_NATIVE | 0x0100 |
ACC_INTERFACE | 0x0200 |
ACC_ABSTRACT | 0x0400 |
ACC_STRICTFP | 0x0800 |
ACC_SYNTHETIC | 0x1000 |
ACC_ANNOTATION | 0x2000 |
ACC_ENUM | 0x4000 |
minor version: 0
major version: 53
flags: (0x0021) ACC_PUBLIC, ACC_SUPER
this_class: #5 // hello/TestJava
super_class: #6 // java/lang/Object
interfaces: 0, fields: 2, methods: 1, attributes: 1
注:ACC_SUPER在JDK1.0.2之后都是真
可以看到次版本号是0,主版本号是53
类:
flags访问标识是public
this_class和super_class可以对应下面的代码:
#5 = Class #21 // hello/TestJava
#6 = Class #22 // java/lang/Object
#21 = Utf8 hello/TestJava
#22 = Utf8 java/lang/Object
此处接口(interface)是0个,字段(fields)是2个,methods(方法)是1个,attributes(属性)是1个
常量池:
描述符:
标识字符 | 含义 |
---|---|
B | 基本类型byte |
C | 基本类型char |
D | 基本类型double |
F | 基本类型float |
I | 基本类型int |
J | 基本类型long |
S | 基本类型short |
Z | 基本类型boolean |
V | 特殊类型void |
L | 对象类型 |
数组类型:
一个维度使用一个“[”,比如一个String[][],标识为“[[java/lang/String”。