How do I "decompile" Java class files?

What program can I use to decompile a class file? Will I actually get Java code, or is it just JVM assembly code?

On Java performance questions on this site I often see responses from people who have "decompiled" the Java class file to see how the compiler optimizes certain things.


Update February 2016:

www.javadecompilers.com lists JAD as being:

the most popular Java decompiler, but primarily of this age only. Written in C++, so very fast.
Outdated, unsupported and does not decompile correctly Java 5 and later

So your mileage may vary with recent jdk (7, 8).

The same site list other tools.

And javadecompiler, as noted by Salvador Valencia in the comments (Sept 2017), offers a SaaS where you upload the .class file to the cloud and it returns you the decompiled code.


Original answer: Oct. 2008

  • The final release of JSR 176, defining the major features of J2SE 5.0 (Java SE 5), has been published on September 30, 2004.
  • The lastest Java version supported by JAD, the famous Java decompiler written by Mr. Pavel Kouznetsov, is JDK 1.3 .
  • Most of the Java decompilers downloadable today from the Internet, such as “DJ Java Decompiler” or “Cavaj Java Decompiler”, are powered by JAD: they can not display Java 5 sources.
  • Java Decompiler (Yet another Fast Java decompiler) has:

  • Explicit support for decompiling and analyzing Java 5+ “.class” files.
  • A nice GUI:
  • 截图

    It works with compilers from JDK 1.1.8 up to JDK 1.7.0, and others (Jikes, JRockit, etc.).

    It features an online live demo version that is actually fully functional! You can just drop a jar file on the page and see the decompiled source code without installing anything.


    There are a few decompilers out there... A quick search yields:

  • Procyon: open-source (Apache 2) and actively developed
  • Krakatau: open-source (GPLv3) and actively developed
  • CFR: open-source (MIT) and actively developed
  • JAD
  • DJ Java Decompiler
  • Mocha
  • And many more.

    These produce Java code. Java comes with something that lets you see JVM byte code (javap).


    To see Java source code check some decompiler. Go search for jad .

    If you want to see bytecodes, just use javap which comes with the JDK.

    链接地址: http://www.djcxy.com/p/15188.html

    上一篇: Java JIT在运行JDK代码时是否会作弊?

    下一篇: 如何“反编译”Java类文件?