“javap”中的“p”代表什么?

时间:2011-02-01 10:39:12

标签: javap

“javap”中的“p”代表什么? (“javac”中的“c”代表编译器)

7 个答案:

答案 0 :(得分:18)

默认情况下,javap 打印声明命令行中指定的每个类的非私有成员

参考:http://docstore.mik.ua/orelly/java/javanut/ch16_08.htm

答案 1 :(得分:3)

它代表java打印机......

答案 2 :(得分:0)

它打印了类中的方法声明,这是查看编译器的一种非常好的方法   已解释您的代码并将您的源文件转换为.class格式。

答案 3 :(得分:0)

javap命令反汇编一个或多个类文件。其输出取决于使用的选项。如果没有使用任何选项,javap将打印出传递给它的类的包,受保护和公共字段以及方法。 javap将其输出打印到stdout。

答案 4 :(得分:0)

javap是官方Java工具的一部分,可以反汇编一个或多个类文件。

在这种情况下,“ p”代表 print ,因为据official documentation报道:

  

... javap命令将打印程序包,受保护的字段和公共字段以及传递给它的类的方法。 javap命令将其输出打印到stdout。

答案 5 :(得分:0)

Official Documentation(Java 13)

除了已回答的内容外,让我们自省javap

如您所见,从选项 description 中,javap中的p最有可能代表 print (因为描述大部分由print组成,那,展示这个,展示那个...)。

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

用法和输出示例(在stdout上):

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是(如果您有兴趣):

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"

答案 6 :(得分:-1)

它列出了指定类包含的所有方法和变量。 您只需要在命令行中使用javap命令对类名称进行paas。 例如 C:\ JDK1.3 \ BIN&GT; javap java.lang.Object 它将列出Object类包含的所有方法。