javap 命令( javap -c -verbose)
java 代码
public class Client {
//简单折扣计算
public void calPrice(int price,int discount){
float knockdownPrice =price * discount / 100.0F;
System.out.println("简单折扣后的价格是:"+formateCurrency(knockdownPrice));
}
//复杂多折扣计算
public void calPrice(int price,int... discounts){
float knockdownPrice = price;
for(int discount:discounts){
knockdownPrice = knockdownPrice * discount / 100;
}
System.out.println("复杂折扣后的价格是:" +formateCurrency(knockdownPrice));
}
//格式化成本的货币形式
private String formateCurrency(float price){
return NumberFormat.getCurrencyInstance().format(price/100);
}
public static void main(String[] args) {
Client client = new Client();
//499元的货物,打75折
client.calPrice(49900, 75);
}
}
javap -c -verbose Client.class
控制台输出结果
C:\project_service\system\test\target\classes\com\huan\web\controller\service\impl>javap -c -verbose Client.class
Classfile /C:/project_service/system/test/target/classes/com/huan/web/controller/service/impl/Client.class
Last modified 2023-1-5; size 1578 bytes
MD5 checksum 0d928c9b2d92c5a16b6ed543a4057f26
Compiled from "Client.java"
public class com.huan.web.controller.service.impl.Client
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Methodref #18.#48 // java/lang/Object."<init>":()V
#2 = Float 100.0f
#3 = Fieldref #49.#50 // java/lang/System.out:Ljava/io/PrintStream;
#4 = Class #51 // java/lang/StringBuilder
#5 = Methodref #4.#48 // java/lang/StringBuilder."<init>":()V
#6 = String #52 // 简单折扣后的价格是:
#7 = Methodref #4.#53 // java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
#8 = Methodref #14.#54 // com/huan/web/controller/service/impl/Client.formateCurrency:(F)Ljava/lang/String;
#9 = Methodref #4.#55 // java/lang/StringBuilder.toString:()Ljava/lang/String;
#10 = Methodref #56.#57 // java/io/PrintStream.println:(Ljava/lang/String;)V
#11 = String #58 // 复杂折扣后的价格是:
#12 = Methodref #59.#60 // java/text/NumberFormat.getCurrencyInstance:()Ljava/text/NumberFormat;
#13 = Methodref #59.#61 // java/text/NumberFormat.format:(D)Ljava/lang/String;
#14 = Class #62 // com/huan/web/controller/service/impl/Client
#15 = Methodref #14.#48 // com/huan/web/controller/service/impl/Client."<init>":()V
#16 = Integer 49900
#17 = Methodref #14.#63 // com/huan/web/controller/service/impl/Client.calPrice:(II)V
#18 = Class #64 // java/lang/Object
#19 = Utf8 <init>
#20 = Utf8 ()V
#21 = Utf8 Code
#22 = Utf8 LineNumberTable
#23 = Utf8 LocalVariableTable
#24 = Utf8 this
#25 = Utf8 Lcom/huan/web/controller/service/impl/Client;
#26 = Utf8 calPrice
#27 = Utf8 (II)V
#28 = Utf8 price
#29 = Utf8 I
#30 = Utf8 discount
#31 = Utf8 knockdownPrice
#32 = Utf8 F
#33 = Utf8 (I[I)V
#34 = Utf8 discounts
#35 = Utf8 [I
#36 = Utf8 StackMapTable
#37 = Class #62 // com/huan/web/controller/service/impl/Client
#38 = Class #35 // "[I"
#39 = Utf8 formateCurrency
#40 = Utf8 (F)Ljava/lang/String;
#41 = Utf8 main
#42 = Utf8 ([Ljava/lang/String;)V
#43 = Utf8 args
#44 = Utf8 [Ljava/lang/String;
#45 = Utf8 client
#46 = Utf8 SourceFile
#47 = Utf8 Client.java
#48 = NameAndType #19:#20 // "<init>":()V
#49 = Class #65 // java/lang/System
#50 = NameAndType #66:#67 // out:Ljava/io/PrintStream;
#51 = Utf8 java/lang/StringBuilder
#52 = Utf8 简单折扣后的价格是:
#53 = NameAndType #68:#69 // append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
#54 = NameAndType #39:#40 // formateCurrency:(F)Ljava/lang/String;
#55 = NameAndType #70:#71 // toString:()Ljava/lang/String;
#56 = Class #72 // java/io/PrintStream
#57 = NameAndType #73:#74 // println:(Ljava/lang/String;)V
#58 = Utf8 复杂折扣后的价格是:
#59 = Class #75 // java/text/NumberFormat
#60 = NameAndType #76:#77 // getCurrencyInstance:()Ljava/text/NumberFormat;
#61 = NameAndType #78:#79 // format:(D)Ljava/lang/String;
#62 = Utf8 com/huan/web/controller/service/impl/Client
#63 = NameAndType #26:#27 // calPrice:(II)V
#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 toString
#71 = Utf8 ()Ljava/lang/String;
#72 = Utf8 java/io/PrintStream
#73 = Utf8 println
#74 = Utf8 (Ljava/lang/String;)V
#75 = Utf8 java/text/NumberFormat
#76 = Utf8 getCurrencyInstance
#77 = Utf8 ()Ljava/text/NumberFormat;
#78 = Utf8 format
#79 = Utf8 (D)Ljava/lang/String;
{
public com.huan.web.controller.service.impl.Client();
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 11: 0
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this Lcom/huan/web/controller/service/impl/Client;
public void calPrice(int, int);
descriptor: (II)V
flags: ACC_PUBLIC
Code:
stack=4, locals=4, args_size=3
0: iload_1
1: iload_2
2: imul
3: i2f
4: ldc #2 // float 100.0f
6: fdiv
7: fstore_3
8: getstatic #3 // Field java/lang/System.out:Ljava/io/PrintStream;
11: new #4 // class java/lang/StringBuilder
14: dup
15: invokespecial #5 // Method java/lang/StringBuilder."<init>":()V
18: ldc #6 // String 简单折扣后的价格是:
20: invokevirtual #7 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
23: aload_0
24: fload_3
25: invokespecial #8 // Method formateCurrency:(F)Ljava/lang/String;
28: invokevirtual #7 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
31: invokevirtual #9 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
34: invokevirtual #10 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
37: return
LineNumberTable:
line 14: 0
line 15: 8
line 16: 37
LocalVariableTable:
Start Length Slot Name Signature
0 38 0 this Lcom/huan/web/controller/service/impl/Client;
0 38 1 price I
0 38 2 discount I
8 30 3 knockdownPrice F
public void calPrice(int, int...);
descriptor: (I[I)V
flags: ACC_PUBLIC, ACC_VARARGS
Code:
stack=4, locals=8, args_size=3
0: iload_1
1: i2f
2: fstore_3
3: aload_2
4: astore 4
6: aload 4
8: arraylength
9: istore 5
11: iconst_0
12: istore 6
14: iload 6
16: iload 5
18: if_icmpge 43
21: aload 4
23: iload 6
25: iaload
26: istore 7
28: fload_3
29: iload 7
31: i2f
32: fmul
33: ldc #2 // float 100.0f
35: fdiv
36: fstore_3
37: iinc 6, 1
40: goto 14
43: getstatic #3 // Field java/lang/System.out:Ljava/io/PrintStream;
46: new #4 // class java/lang/StringBuilder
49: dup
50: invokespecial #5 // Method java/lang/StringBuilder."<init>":()V
53: ldc #11 // String 复杂折扣后的价格是:
55: invokevirtual #7 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
58: aload_0
59: fload_3
60: invokespecial #8 // Method formateCurrency:(F)Ljava/lang/String;
63: invokevirtual #7 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
66: invokevirtual #9 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
69: invokevirtual #10 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
72: return
LineNumberTable:
line 19: 0
line 20: 3
line 21: 28
line 20: 37
line 23: 43
line 24: 72
LocalVariableTable:
Start Length Slot Name Signature
28 9 7 discount I
0 73 0 this Lcom/huan/web/controller/service/impl/Client;
0 73 1 price I
0 73 2 discounts [I
3 70 3 knockdownPrice F
StackMapTable: number_of_entries = 2
frame_type = 255 /* full_frame */
offset_delta = 14
locals = [ class com/huan/web/controller/service/impl/Client, int, class "[I", float, class "[I", int, int ]
stack = []
frame_type = 248 /* chop */
offset_delta = 28
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 #14 // class com/huan/web/controller/service/impl/Client
3: dup
4: invokespecial #15 // Method "<init>":()V
7: astore_1
8: aload_1
9: ldc #16 // int 49900
11: bipush 75
13: invokevirtual #17 // Method calPrice:(II)V
16: return
LineNumberTable:
line 30: 0
line 32: 8
line 33: 16
LocalVariableTable:
Start Length Slot Name Signature
0 17 0 args [Ljava/lang/String;
8 9 1 client Lcom/huan/web/controller/service/impl/Client;
}
SourceFile: "Client.java"