“javap”中的“p”代表什么?(“javac”中的“c”代表编译器)
7 回答
默认情况下,javap
打印命令行上指定的每个类的非私有成员的声明
p
= 打印
javap
是官方 Java 工具的一部分,允许反汇编一个或多个类文件。
在这种情况下,“p”代表print,据报道官方文档:
...该
javap
命令打印传递给它的类的包、受保护和公共字段以及方法。该javap
命令将其输出打印到标准输出。
它代表java打印机....
很可能 p 意味着打印
正如您所看到的,从选项description中,pjavap
很可能代表print(因为描述主要包括 print this、print that、show this、show that...)。
javap -help
Usage: javap <options> <classes>
where possible options include:
-help --help -? Print this usage message
-version Version information
-v -verbose Print additional information
-l Print line number and local variable tables
-public Show only public classes and members
-protected Show protected/public classes and members
-package Show package/protected/public classes
and members (default)
-p -private Show all classes and members
-c Disassemble the code
-s Print internal type signatures
-sysinfo Show system info (path, size, date, MD5 hash)
of class being processed
-constants Show final constants
-classpath <path> Specify where to find user class files
-cp <path> Specify where to find user class files
-bootclasspath <path> Override location of bootstrap class files
用法
public class CheckoutJavaP{
private static int i = 1;
protected static String s = "string";
public static void main(String[] args){
InnerClass iC = new InnerClass();
iC.show();
System.out.println(s + i);
}
}
class InnerClass{
protected int count;
public InnerClass(){ System.out.println("In InnerClass Constructor");}
public void show(){ System.out.println("In InnerClass.show()");}
public int getCount(){ return this.count;}
}
(注意:根据它的定义,下面的输出没有提到 InnerClass,只有它正在自省的类,没有提到private
属性):
javap 命令反汇编一个或多个类文件。输出取决于使用的选项。如果没有使用任何选项,那么 javap 命令会打印包、受保护和公共字段以及传递给它的类的方法。javap 命令将其输出打印到标准输出。
javap CheckoutJavaP.class
Compiled from "CheckoutJavaP.java"
public class CheckoutJavaP {
protected static java.lang.String s;
public CheckoutJavaP();
public static void main(java.lang.String[]);
static {};
}
用法 - 详细
javap -v CheckoutJavaP.class
Classfile /C:/Users/jumping_monkey/CheckoutJavaP.class
Last modified 9 Feb, 2020; size 822 bytes
MD5 checksum fb7f219851715ef4489ebf7a47800d47
Compiled from "CheckoutJavaP.java"
public class CheckoutJavaP
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Methodref #16.#30 // java/lang/Object."<init>":()V
#2 = Class #31 // InnerClass
#3 = Methodref #2.#30 // InnerClass."<init>":()V
#4 = Methodref #2.#32 // InnerClass.show:()V
#5 = Fieldref #33.#34 // java/lang/System.out:Ljava/io/PrintStream;
#6 = Class #35 // java/lang/StringBuilder
#7 = Methodref #6.#30 // java/lang/StringBuilder."<init>":()V
#8 = Fieldref #15.#36 // CheckoutJavaP.s:Ljava/lang/String;
#9 = Methodref #6.#37 // java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
#10 = Fieldref #15.#38 // CheckoutJavaP.i:I
#11 = Methodref #6.#39 // java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
#12 = Methodref #6.#40 // java/lang/StringBuilder.toString:()Ljava/lang/String;
#13 = Methodref #41.#42 // java/io/PrintStream.println:(Ljava/lang/String;)V
#14 = String #43 // string
#15 = Class #44 // CheckoutJavaP
#16 = Class #45 // java/lang/Object
#17 = Utf8 i
#18 = Utf8 I
#19 = Utf8 s
#20 = Utf8 Ljava/lang/String;
#21 = Utf8 <init>
#22 = Utf8 ()V
#23 = Utf8 Code
#24 = Utf8 LineNumberTable
#25 = Utf8 main
#26 = Utf8 ([Ljava/lang/String;)V
#27 = Utf8 <clinit>
#28 = Utf8 SourceFile
#29 = Utf8 CheckoutJavaP.java
#30 = NameAndType #21:#22 // "<init>":()V
#31 = Utf8 InnerClass
#32 = NameAndType #46:#22 // show:()V
#33 = Class #47 // java/lang/System
#34 = NameAndType #48:#49 // out:Ljava/io/PrintStream;
#35 = Utf8 java/lang/StringBuilder
#36 = NameAndType #19:#20 // s:Ljava/lang/String;
#37 = NameAndType #50:#51 // append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
#38 = NameAndType #17:#18 // i:I
#39 = NameAndType #50:#52 // append:(I)Ljava/lang/StringBuilder;
#40 = NameAndType #53:#54 // toString:()Ljava/lang/String;
#41 = Class #55 // java/io/PrintStream
#42 = NameAndType #56:#57 // println:(Ljava/lang/String;)V
#43 = Utf8 string
#44 = Utf8 CheckoutJavaP
#45 = Utf8 java/lang/Object
#46 = Utf8 show
#47 = Utf8 java/lang/System
#48 = Utf8 out
#49 = Utf8 Ljava/io/PrintStream;
#50 = Utf8 append
#51 = Utf8 (Ljava/lang/String;)Ljava/lang/StringBuilder;
#52 = Utf8 (I)Ljava/lang/StringBuilder;
#53 = Utf8 toString
#54 = Utf8 ()Ljava/lang/String;
#55 = Utf8 java/io/PrintStream
#56 = Utf8 println
#57 = Utf8 (Ljava/lang/String;)V
{
protected static java.lang.String s;
descriptor: Ljava/lang/String;
flags: ACC_PROTECTED, ACC_STATIC
public CheckoutJavaP();
descriptor: ()V
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
LineNumberTable:
line 1: 0
public static void main(java.lang.String[]);
descriptor: ([Ljava/lang/String;)V
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=3, locals=2, args_size=1
0: new #2 // class InnerClass
3: dup
4: invokespecial #3 // Method InnerClass."<init>":()V
7: astore_1
8: aload_1
9: invokevirtual #4 // Method InnerClass.show:()V
12: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream;
15: new #6 // class java/lang/StringBuilder
18: dup
19: invokespecial #7 // Method java/lang/StringBuilder."<init>":()V
22: getstatic #8 // Field s:Ljava/lang/String;
25: invokevirtual #9 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
28: getstatic #10 // Field i:I
31: invokevirtual #11 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
34: invokevirtual #12 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
37: invokevirtual #13 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
40: return
LineNumberTable:
line 5: 0
line 6: 8
line 7: 12
line 8: 40
static {};
descriptor: ()V
flags: ACC_STATIC
Code:
stack=1, locals=0, args_size=0
0: iconst_1
1: putstatic #10 // Field i:I
4: ldc #14 // String string
6: putstatic #8 // Field s:Ljava/lang/String;
9: return
LineNumberTable:
line 2: 0
line 3: 4
}
SourceFile: "CheckoutJavaP.java"
对,现在你可以看到InnerClass
私有财产了i
。要对您的课程进行高级自省,请使用javap
,但如果您想深入了解,请使用javap -v
它打印类中的方法声明,这是查看编译器如何解释代码并将源文件转换为 .class 格式的好方法。
javap 命令反汇编一个或多个类文件。它的输出取决于使用的选项。如果没有使用任何选项,javap 会打印出传递给它的类的包、受保护和公共字段和方法。javap 将其输出打印到标准输出。
它列出了指定类包含的所有方法和变量。您只需要在命令行上使用 javap 命令将类名命名为 paas 即可。例如 C:\jdk1.3\bin> javap java.lang.Object 它将列出 Object 类包含的所有方法。