首頁 Java java教程 java .class檔案怎麼看?

java .class檔案怎麼看?

May 22, 2019 pm 02:16 PM
class java

有時候為了研究Javac的原理,要去看看class檔案的內容是如何組織的,這時候很有必要查看class檔案。

java .class檔案怎麼看?

java class檔案怎麼看?

查看class檔案方法有很多種,這裡推薦使用JDK自帶的javap工具。

先建立如下原始碼:

public class HelloWorld{
    public static void main(String[] args){
        System.out.println("hello world!");
    }
}

使用javac編譯器把原始檔編譯好,再接著使用javap工具查看class文件,指令如下 

javap -verbose HelloWorld

這是DOS窗口的運行結果複製出來如下圖:

F:\>javac HelloWorld.java
F:\>javap -verbose HelloWorld
Classfile /F:/HelloWorld.class
  Last modified 2017-12-24; size 426 bytes
  MD5 checksum 4efac412ef483c8a3fe7489c87d15c8c
  Compiled from "HelloWorld.java"
public class HelloWorld
  minor version: 0
  major version: 52
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
   #1 = Methodref          #6.#15         // java/lang/Object."<init>":()V
   #2 = Fieldref           #16.#17        // java/lang/System.out:Ljava/io/Print
Stream;
   #3 = String             #18            // hello world!
   #4 = Methodref          #19.#20        // java/io/PrintStream.println:(Ljava/
lang/String;)V
   #5 = Class              #21            // HelloWorld
   #6 = Class              #22            // java/lang/Object
   #7 = Utf8               <init>
   #8 = Utf8               ()V
   #9 = Utf8               Code
  #10 = Utf8               LineNumberTable
  #11 = Utf8               main
  #12 = Utf8               ([Ljava/lang/String;)V
  #13 = Utf8               SourceFile
  #14 = Utf8               HelloWorld.java
  #15 = NameAndType        #7:#8          // "<init>":()V
  #16 = Class              #23            // java/lang/System
  #17 = NameAndType        #24:#25        // out:Ljava/io/PrintStream;
  #18 = Utf8               hello world!
  #19 = Class              #26            // java/io/PrintStream
  #20 = NameAndType        #27:#28        // println:(Ljava/lang/String;)V
  #21 = Utf8               HelloWorld
  #22 = Utf8               java/lang/Object
  #23 = Utf8               java/lang/System
  #24 = Utf8               out
  #25 = Utf8               Ljava/io/PrintStream;
  #26 = Utf8               java/io/PrintStream
  #27 = Utf8               println
  #28 = Utf8               (Ljava/lang/String;)V
{
  public HelloWorld();
    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=2, locals=1, args_size=1
         0: getstatic     #2                  // Field java/lang/System.out:Ljav
a/io/PrintStream;
         3: ldc           #3                  // String hello world!
         5: invokevirtual #4                  // Method java/io/PrintStream.prin
tln:(Ljava/lang/String;)V
         8: return
      LineNumberTable:
        line 3: 0
        line 4: 8
}
SourceFile: "HelloWorld.java"
F:\>

相關學習推薦:java基礎教學

以上是java .class檔案怎麼看?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

PHP教程
1594
276
使用XSLT參數創建動態轉換 使用XSLT參數創建動態轉換 Aug 17, 2025 am 09:16 AM

XSLT參數是通過外部傳遞值來實現動態轉換的關鍵機制,1.使用聲明參數並可設置默認值;2.從應用程序代碼(如C#)通過XsltArgumentList等接口傳入實際值;3.在模板中通過$paramName引用參數控制條件處理、本地化、數據過濾或輸出格式;4.最佳實踐包括使用有意義的名稱、提供默認值、分組相關參數並進行值驗證。合理使用參數可使XSLT樣式表具備高複用性和可維護性,相同樣式表能根據不同輸入產生多樣化輸出結果。

您目前尚未使用附上的顯示器[固定] 您目前尚未使用附上的顯示器[固定] Aug 19, 2025 am 12:12 AM

Ifyousee"YouarenotusingadisplayattachedtoanNVIDIAGPU,"ensureyourmonitorisconnectedtotheNVIDIAGPUport,configuredisplaysettingsinNVIDIAControlPanel,updatedriversusingDDUandcleaninstall,andsettheprimaryGPUtodiscreteinBIOS/UEFI.Restartaftereach

如何在Java中使用可選的? 如何在Java中使用可選的? Aug 22, 2025 am 10:27 AM

useoptional.empty(),可選of(),andoptional.ofnullable()

Java的僵局是什麼,您如何防止它? Java的僵局是什麼,您如何防止它? Aug 23, 2025 pm 12:55 PM

AdeadlockinJavaoccurswhentwoormorethreadsareblockedforever,eachwaitingforaresourceheldbytheother,typicallyduetocircularwaitcausedbyinconsistentlockordering;thiscanbepreventedbybreakingoneofthefournecessaryconditions—mutualexclusion,holdandwait,nopree

探索常見的Java設計模式與示例 探索常見的Java設計模式與示例 Aug 17, 2025 am 11:54 AM

Java設計模式是解決常見軟件設計問題的可複用方案。 1.Singleton模式確保一個類只有一個實例,適用於數據庫連接池或配置管理;2.Factory模式解耦對象創建,通過工廠類統一生成對像如支付方式;3.Observer模式實現自動通知依賴對象,適合事件驅動系統如天氣更新;4.Strategy模式動態切換算法如排序策略,提升代碼靈活性。這些模式提高代碼可維護性與擴展性但應避免過度使用。

未找到操作系統[固定] 未找到操作系統[固定] Aug 17, 2025 am 09:10 AM

ifyourcomputershows“ operatingsystemnotfound”,turtheSesteps:1.checkbios/uefibootorder.2.verifydiskconnections.3.repairbootlootloaderusingerusiseWindowsRecovery.4.reassignDriveletterterterterterveletterviadiskmanagement.5.ReinStallTheStalTheStallTheStallTheStallTheStallateSyStememementemecyemectemecorefnectersifnecters。

PS油漆濾清器灰色固定 PS油漆濾清器灰色固定 Aug 18, 2025 am 01:25 AM

TheOilPaintfilterinPhotoshopisgreyedoutusuallybecauseofincompatibledocumentmodeorlayertype;ensureyou'reusingPhotoshopCS6orlaterinthefulldesktopversion,confirmtheimageisin8-bitperchannelandRGBcolormodebycheckingImage>Mode,andmakesureapixel-basedlay

使用Micronaut構建雲原生爪哇應用 使用Micronaut構建雲原生爪哇應用 Aug 20, 2025 am 01:53 AM

Micronautisidealforbuildingcloud-nativeJavaapplicationsduetoitslowmemoryfootprint,faststartuptimes,andcompile-timedependencyinjection,makingitsuperiortotraditionalframeworkslikeSpringBootformicroservices,containers,andserverlessenvironments.1.Microna

See all articles