javap和java反編譯有何區別?
1.創建一個Test.java文件,并輸入內容
public class Test{ private int m; public int inc(){ return m + 1; } }
2.使用javac命令編譯Test.java文件,得到Test.class文件
cafe babe 0000 0034 0013 0a00 0400 0f09
0010 0700 1107 0012 0100 016d 0100
0100 063c 696e 6974 3e01 0003 2829
0004 436f 6465 0100 0f4c 696e 654e
756d 6265 7254 6162 6c65 0100 0369 6e63
0328 2949 0100 0a53 6f75 7263 6546
696c 6501 0009 5465 7374 2e6a 6176 610c
0008 0c00 0500 0601 0004 5465 7374
106a 6176 612f 6c61 6e67 2f4f 626a
7400 2100 0300 0400 0000 0100 0200
0600 0000 0200 0100 0700 0800 0100
0000 1d00 0100 0100 0000 052a b700
01b1 0000 0001 000a 0000 0006 0001 0000
0001 000b 000c 0001 0009 0000 001f
0001 0000 0007 2ab4 0002 0460 ac00
0100 0a00 0000 0600 0100 0000 0400
0d00 0000 0200 0e
3.使用javap命令,反編譯Test.class文件
javap -v TestClassfile /Users/soldier/Desktop/Test.class
Last modified 2018-9-19; size 265 bytes
MD5 checksum 551399dd9890a81e8f8c079c6c1f364d
Compiled from "Test.java"
public class Test
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Methodref #4.#15 // java/lang/Object."<init>":()V
#2 = Fieldref #3.#16 // Test.m:I
#3 = Class #17 // Test
#4 = Class #18 // java/lang/Object
#5 = Utf8 m
#6 = Utf8 I
#7 = Utf8 <init>
#8 = Utf8 ()V
#9 = Utf8 Code
#10 = Utf8 LineNumberTable
#11 = Utf8 inc
#12 = Utf8 ()I
#13 = Utf8 SourceFile
#14 = Utf8 Test.java
#15 = NameAndType #7:#8 // "<init>":()V
#16 = NameAndType #5:#6 // m:I
#17 = Utf8 Test
#18 = Utf8 java/lang/Object
{
public Test();
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 int inc();
descriptor: ()I
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: getfield #2 // Field m:I
4: iconst_1
5: iadd
6: ireturn
LineNumberTable:
line 4: 0
}
SourceFile: "Test.java"
用法摘要:
-help 幫助-l 輸出行和變量的表-public 只輸出public方法和域-protected 只輸出public和protected類和成員-package 只輸出包,public和protected類和成員,這是默認的-p -private 輸出所有類和成員-s 輸出內部類型簽名-c 輸出分解后的代碼,例如,類中每一個方法內,包含java字節碼的指令,-v 輸出棧大小,方法參數的個數-constants 輸出靜態final常量