编译: javac -g:vars Person.java ---> Person.class
2.1.2 前期编译
Person.java -> 词法分析器 -> tokens流 -> 语法分析器 -> 语法树/抽象语法树
-> 语义分析器 -> 注解抽象语法树 -> 字节码生成器 -> Person.class文件
2.1.3 类文件(Class文件)
2.1.3.1 16进制
2.1.3.2 The ClassFile Structure
官网 : https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html
class Person{
private String name="carl";
private int age;
private final double salary=100;
private static String address;
private final static String hobby="Programming";
private static Object obj=new Object();
public void say(){
System.out.println("person say...");
}
public static int calc(int op1,int op2){
op1=3;
int result=op1+op2;
Object obj=new Object();
return result;
}
public static void main(String[] args){
calc(1,2);
}
}
cafe babe 0000 0034 003f 0a00 0a00 2b08
002c 0900 0d00 2d06 4059 0000 0000 0000
0900 0d00 2e09 002f 0030 0800 310a 0032
0033 0700 340a 000d 0035 0900 0d00 3607
0037 0100 046e 616d 6501 0012 4c6a 6176
612f 6c61 6e67 2f53 7472 696e 673b 0100
0361 6765 0100 0149 0100 0673 616c 6172
7901 0001 4401 000d 436f 6e73 7461 6e74
......
ClassFile {
u4 magic;
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info constant_pool[constant_pool_count-1];
u2 access_flags;
u2 this_class;
u2 super_class;