语言无关性
u1 表示一个byte整数
u4 表示4个byte整数
文件结构
类型 |
名称 |
数量 |
u4 |
magic(表示是否class 文件) |
1 |
u2 |
minor_version(java的版本号) |
1 |
u2 |
major_version |
1 |
u2 |
constant_pool_count |
1 |
cp_info |
constant_pool(常量池) |
constant_pool_count - 1 |
u2 |
access_flags(private pulic,protected ) |
1 |
u2 |
this_class |
1 |
u2 |
super_class(单继承,只有一个超类) |
1 |
u2 |
interfaces_count |
1 |
u2 |
interfaces(接口) |
interfaces_count |
u2 |
fields_count |
1 |
field_info |
fields(字段) |
fields_count |
u2 |
methods_count |
1 |
method_info |
methods(方法) |
methods_count |
u2 |
attribute_count |
1 |
attribute_info |
attributes(属性) |
attributes_count |
常量池 ,应该是class 最为重要的一部分
public static final int sid=99;
public static final String sname="geym";
------------------
Flag Name |
Value |
Interpretation |
ACC_PUBLIC |
0x0001 |
public |
ACC_FINAL |
0x0010 |
final,不能被继承. |
ACC_SUPER |
0x0020 |
是否允许使用invokespecial指令,JDK1.2后,该值为true |
ACC_INTERFACE |
0x0200 |
是否是接口 |
ACC_ABSTRACT |
0x0400 |
抽象类 |
ACC_SYNTHETIC |
0x1000 |
该类不是由用户代码生成,运行时生成的,没有源码 |
ACC_ANNOTATION |
0x2000 |
是否为注解 |
ACC_ENUM |
0x4000 |
是否是枚举 |
Flag Name |
Value |
Interpretation |
ACC_PUBLIC |
0x0001 |
public |
ACC_PRIVATE |
0x0002 |
private |
ACC_PROTECTED |
0x0004 |
protected |
ACC_STATIC |
0x0008 |
static. |
ACC_FINAL |
0x0010 |
final |
ACC_VOLATILE |
0x0040 |
volatile |
ACC_TRANSIENT |
0x0080 |
transient |
ACC_SYNTHETIC |
0x1000 |
synthetic; 没有源码,编译器生成 |
ACC_ENUM |
0x4000 |
枚举类型 |
descriptor_index的字符串存放位置在哪里?
文件结构- method
Flag Name |
Value |
Interpretation |
ACC_PUBLIC |
0x0001 |
public |
ACC_PRIVATE |
0x0002 |
private |
ACC_PROTECTED |
0x0004 |
protected |
ACC_STATIC |
0x0008 |
static |
ACC_FINAL |
0x0010 |
final |
ACC_SYNCHRONIZED |
0x0020 |
synchronized |
ACC_BRIDGE |
0x0040 |
编译器产生 桥接方法 |
ACC_VARARGS |
0x0080 |
可变参数 |
ACC_NATIVE |
0x0100 |
native |
ACC_ABSTRACT |
0x0400 |
abstract |
ACC_STRICT |
0x0800 |
strictfp |
ACC_SYNTHETIC |
0x1000 |
不在源码中,由编译器产生 |
文件结构- attribute
名称 |
使用者 |
描述 |
Deprecated(废弃) |
field method |
字段、方法、类被废弃 |
ConstantValue |
field |
final常量 |
Code |
method |
方法的字节码和其他数据 |
Exceptions |
method |
方法的异常 |
LineNumberTable |
Code_Attribute |
方法行号和字节码映射 |
LocalVaribleTable |
Code_Attribute |
方法局部变量表描述 |
SourceFile |
Class file |
源文件名 |
Synthetic |
field method |
编译器产生的方法或字段 |