高版本虚拟机,可以解释运行低版本字节码文件
Class文件是JVM的基石,常量池是Class文件的基石
常量池计数器与常量池表数量的关系相差1
;
当常量池计数器为1时,常量池表中没有常量项
16(十六进制)===>22(十进制) = = =>代表有22-1个常量项
字面量和符号引用:↓
常量类型和结构:↓
在class字节码文件中所表示的是指向某索引的符号有引用,不代表真正的内存地址;
当被类加载器加载到内存中,所存放到运行时数据区中,此时的符号引用就编译成了真正指向真实内存地址的直接引用
当前类叫什么、当前类的父类谁、当前类实现了几个接口
平时我们说的类中的属性
字段(类成员变量)的描述符为:参数类型
方法的描述符为:方法的入参列表、方法的返回值类型
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PFBbuXgU-1652250080401)(https://img-blog.csdnimg.cn 《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》无偿开源 威信搜索公众号【编程进阶路】 /5f0da650dec4438ca04c588190795ca6.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzMjg0NDY5,size_16,color_FFFFFF,t_70)]
方法中可以有属性,字段中也可以有属性
[](()四、使用javap指令解析Class文件
最全信息的写法:javap -v -p XXX.class
public class JavapTest {
private int num;
boolean flag;
protected char gender;
public String info;
public static final int COUNTS = 1;
static {
String url = “www.atguigu.com”;
}
{
info = “java”;
}
public JavapTest() {
}
private JavapTest(boolean falg) {
this.flag = flag;
}
private void methodPrivate() {
}
int getNum(int i) {
return num + i;
}
protected char showGender() {
return gender;
}
public void showInfo() {
int i = 100;
System.out.println(info + i);
}
}
javap -v -p JavapTest.class
Classfile /C:/Users/achang/Desktop/JavapTest.class // 字节码文件所属的路径
Last modified 2021-2-24; size 1393 bytes // 最后修改时间,字节码文件的大小
MD5 checksum 2c764244fa3a95bfb346c9e416a7a3f6 // MD5散列值
Compiled from “JavapTest.java” // 源文件的名称
public class io.renren.JavapTest
minor version: 0 // 副版本
major version: 52 // 主版本
flags: ACC_PUBLIC, ACC_SUPER // 访问标识
//*************************** 常量池↓********************************
Constant pool:
#1 = Methodref #16.#48 // java/lang/Object.“”)V
#2 = String #49 // java
#3 = Fieldref #15.#50 // io/renren/JavapTest.info:Ljava/lang/String;
#4 = Fieldref #15.#51 // io/renren/JavapTest.flag:Z
#5 = Fieldref #15.#52 // io/renren/JavapTest.num:I
#6 = Fieldref #15.#53 // io/renren/JavapTest.gender:C
#7 = Fieldref #54.#55 // java/lang/System.out:Ljava/io/PrintStream;
#8 = Class #56 // java/lang/StringBuilder
#9 = Methodref #8.#48 // java/lang/StringBuilder.“”)V
#10 = Methodref #8.#57 // java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
#11 = Methodref #8.#58 // java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
#12 = Methodref #8.#59 // java/lang/StringBuilder.toString:()Ljava/lang/String;
#13 = Methodref #60.#61 // java/io/PrintStream.println:(Ljava/lang/String;)V
#14 = String #62 // www.atguigu.com
#15 = Class #63 // io/renren/JavapTest
#16 = Class #64 // java/lang/Object
#17 = Utf8 num
#18 = Utf8 I
#19 = Utf8 flag
#20 = Utf8 Z
#21 = Utf8 gender
#22 = Utf8 C
#23 = Utf8 info
#24 = Utf8 Ljava/lang/String;
#25 = Utf8 COUNTS
#26 = Utf8 ConstantValue
#27 = Integer 1
#28 = Utf8
#29 = Utf8 ()V
#30 = Utf8 Code
#31 = Utf8 LineNumberTable
#32 = Utf8 LocalVariableTable
#33 = Utf8 this
#34 = Utf8 Lio/renren/JavapTest;
#35 = Utf8 (Z)V
#36 = Utf8 falg
#37 = Utf8 MethodParameters
#38 = Utf8 methodPrivate
#39 = Utf8 getNum
#40 = Utf8 (I)I
#41 = Utf8 i
#42 = Utf8 showGender
#43 = Utf8 ()C
#44 = Utf8 showInfo
#45 = Utf8
#46 = Utf8 SourceFile
#47 = Utf8 JavapTest.java
#48 = NameAndType #28:#29 // “”)V
#49 = Utf8 java
#50 = NameAndType #23:#24 // info:Ljava/lang/String;
#51 = NameAndType #19:#20 // flag:Z
#52 = NameAndType #17:#18 // num:I
#53 = NameAndType #21:#22 // gender:C
#54 = Class #65 // java/lang/System
#55 = NameAndType #66:#67 // out:Ljava/io/PrintStream;
#56 = Utf8 java/lang/StringBuilder
#57 = NameAndType #68:#69 // append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
#58 = NameAndType #68:#70 // append:(I)Ljava/lang/StringBuilder;
#59 = NameAndType #71:#72 // toString:()Ljava/lang/String;
#60 = Class #73 // java/io/PrintStream
#61 = NameAndType #74:#75 // println:(Ljava/lang/String;)V
#62 = Utf8 www.atguigu.com
#63 = Utf8 io/renren/JavapTest
#64 = Utf8 java/lang/Object
#65 = Utf8 java/lang/System
#66 = Utf8 out
#67 = Utf8 Ljava/io/PrintStream;
#68 = Utf8 append
#69 = Utf8 (Ljava/lang/String;)Ljava/lang/StringBuilder;
#70 = Utf8 (I)Ljava/lang/StringBuilder;
#71 = Utf8 toString
#72 = Utf8 ()Ljava/lang/String;
#73 = Utf8 java/io/PrintStream
#74 = Utf8 println
#75 = Utf8 (Ljava/lang/String;)V
//字段表集合的信息↓********
{
private int num; // 字段名
descriptor: I // 字段描述符,字段类型
flags: ACC_PRIVATE // 字段的访问标识
boolean flag;
descriptor: Z
flags:
protected char gender;
descriptor: C
flags: ACC_PROTECTED
public java.lang.String info;
va/io/PrintStream;
#68 = Utf8 append
#69 = Utf8 (Ljava/lang/String;)Ljava/lang/StringBuilder;
#70 = Utf8 (I)Ljava/lang/StringBuilder;
#71 = Utf8 toString
#72 = Utf8 ()Ljava/lang/String;
#73 = Utf8 java/io/PrintStream
#74 = Utf8 println
#75 = Utf8 (Ljava/lang/String;)V
//字段表集合的信息↓********
{
private int num; // 字段名
descriptor: I // 字段描述符,字段类型
flags: ACC_PRIVATE // 字段的访问标识
boolean flag;
descriptor: Z
flags:
protected char gender;
descriptor: C
flags: ACC_PROTECTED
public java.lang.String info;