556

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kip
  • 107,154
  • 87
  • 232
  • 265
  • 4
    The art of "decompiling" can also be thought upon as reverse engineering. Although sometimes when reverse engineering something you don't always have access to binaries. – Makach Jun 13 '09 at 10:53
  • No one mentioned https://bytecodeviewer.com/, which can decompile to java source and to bytecode (for java source is based on JAD). – Fernando Gonzalez Sanchez Jan 08 '18 at 16:32

19 Answers19

588

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:

screenshot

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 5
    +1 It's worth mentioning that it's also modularized, so the core (implemented in C++) can be leveraged elsewhere. – Quinn Taylor May 05 '10 at 04:02
  • 1
    jd-gui-0.3.3 also available [here](http://code.google.com/p/innlab/downloads/detail?name=jd-gui-0.3.3.windows.zip&can=2&q=) – amaidment Jul 03 '12 at 07:55
  • +1 for the info! If Java decompilers are so damn easy, how does one go about protecting his IP? Is there an obfuscation technique to work around these decompilers? – Rishi Aug 15 '12 at 16:56
  • @Rishi I suppose there is, when I look at http://stackoverflow.com/search?q=[java]+obfuscation – VonC Aug 15 '12 at 19:27
  • 1
    In case one installed the Eclipse java decompiler plugin on Eclipse Juno, and Eclipse started hanging on Marketplace DND Initialization forcing to kill the whole process: removing the jd.*.jar from Eclipse plugins directory just fixed it for me. – LSerni Feb 24 '13 at 12:12
  • If you don't like using the jd-gui, you can follow these instructions and generate the folder hierarchy for the code: http://stackoverflow.com/a/1384652/198348 – Ehtesh Choudhury Apr 28 '13 at 18:15
  • 4
    @Rishi the same way you protect your IP in any language or platform - good lawyers. DRM is only a bandaid. – Antimony Jun 15 '13 at 19:26
  • There are only some small shortages (e.g. some types are not recovered), but overall is this an excellent tool, VonC – CuongHuyTo Jul 10 '13 at 11:45
  • JD-GUI project is outdated and long dead. – Tomáš Zato Feb 09 '16 at 11:13
  • 1
    It now offers SaaS where you upload the .class file to the cloud and it returns you the decompiled code. Worked for a simple POJO. – Salvador Valencia Sep 15 '17 at 20:43
  • @SalvadorValencia Thank you. I have included your comment in the answer for more visibility. – VonC Sep 15 '17 at 21:45
  • @Salvador Valencia Please add sources. – davidxxx Mar 05 '18 at 10:58
101

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

  1. Procyon: open-source (Apache 2) and actively developed
  2. Krakatau: open-source (GPLv3) and actively developed
  3. CFR: open-source (MIT) and actively developed
  4. JAD
  5. DJ Java Decompiler
  6. Mocha

And many more.

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

billjamesdev
  • 14,554
  • 6
  • 53
  • 76
51

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.

Marko
  • 30,263
  • 18
  • 74
  • 108
  • 5
    I'd recommend one of the open-source decompilers instead, as they are actively developed. Use [Procyon](https://bitbucket.org/mstrobel/procyon/wiki/Java%20Decompiler), the [CFR decompiler](http://www.benf.org/other/cfr/) or [Krakatau](https://github.com/Storyyeller/Krakatau) (Python) instead. – Janus Troelsen Aug 22 '13 at 11:26
29

I tried several, and Procyon seemed to work the best for me. It's under active development and supports many features of the latest versions of Java.

These are the others I tried:

  • CFR
    • Promising, but often failed method decompilation. I'll be keeping my eye on this one. Also actively developed with support for the latest Java features.
  • Krakatau
    • Takes a different approach in that it tries to output equivalent Java code instead of trying to reconstruct the original source, which has the potential of making it better for obfuscated code. From my testing it was roughly on par with Procyon, but still nice to have something different. I did have to use the -skip command-line flag so it wouldn't stop on errors. Actively developed, and interestingly enough it's written in Python.
  • JD-GUI
  • JAD
    • Worked, but only supports Java 1.4 and below. Also available as an Eclipse plugin. No longer under development.
bmaupin
  • 14,427
  • 5
  • 89
  • 94
18

I use JAD Decompiler.

There is an Eclipse plugin for it, jadeclipse. It is pretty nice.

Paweł Albecki
  • 223
  • 3
  • 9
sakana
  • 4,251
  • 5
  • 25
  • 20
14

Procyon includes a decompiler. It is FOSS.

Janus Troelsen
  • 20,267
  • 14
  • 135
  • 196
13

Soot is an option for newer Java code. At least it has the advantage of still being recently maintained...

Also, Java Decompiler is a decompiler with both a stand-alone GUI and Eclipse integration.

Lastly, Jdec hasn't been mentioned, though it's not as polished as other options.

Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
12

JD-GUI is really good. You could just open a JAR file and browse through the code as if you are working on an IDE. Good stuff.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
G Kumar
  • 131
  • 1
  • 2
11

Here's a list of decompilers as of Feb 2015:

Procyon, open-source, https://bitbucket.org/mstrobel/procyon/wiki/Java%20Decompiler

CFR, free, no source-code available, http://www.benf.org/other/cfr/

JD, free for non-commercial use only, http://jd.benow.ca/

Fernflower, open-source, https://github.com/fesh0r/fernflower,

JAD – given here only for historical reason. Free, no source-code available, http://varaneckas.com/jad/ Outdated, unsupported and does not decompile correctly Java 5 and later.

You may test above-mentioned decompilers online, no installation required and make your own educated choice.

Java decompilers in the cloud: http://www.javadecompilers.com/

Cimbali
  • 11,012
  • 1
  • 39
  • 68
Andrew Rukin
  • 959
  • 11
  • 16
10

There are a few programs you can use. You will get the actual Java code, but sometimes the code will have been obfuscated so methods are named by one letter or number or a random mix of letters and numbers.

DJ Decompiler Mocha

Atanas
  • 9
  • 2
Mike Pone
  • 18,705
  • 13
  • 53
  • 68
9

Most decompilers for Java are based on JAD. It's a great tool, but unfortunately hasn't been updated for a while and does not handle Java 1.5+ classes very well. I have not seen any tools that will properly handle 1.5+ classes.

John Meagher
  • 22,808
  • 14
  • 54
  • 57
  • 3
    here you go: I just posted an answer to your answer ;) JDK1.5 and more supported! – VonC Nov 07 '08 at 16:19
  • "I have not seen any tools that will properly handle 1.5+ classes" - Procion,Fernflower,JDCore and CFR (this one handles Java 8!) – Andrew Rukin Aug 11 '15 at 15:56
6

All of the JAD links listed so far far seem to be broken, so I found this site. Works great (for Linux, at least)! On Ubuntu 11.10 I had to download the static one for whatever reason.

http://www.varaneckas.com/jad

kdazzle
  • 4,190
  • 3
  • 24
  • 27
6

Take a look at cavaj.

Paulo Guedes
  • 7,189
  • 5
  • 40
  • 60
5

If you want to see how the Java compiler does certain things, you don't want decompilation, you want disassembly. Decompilation involves transforming the bytecode into Java source, meaning that a lot of low level information is lost, and if you're wondering about compiler optimization, this is probably the very information you're interested in.

Anyway, I happen to have written an open source Java disassembler. Unlike Javap, this works even on highly pathological classes, so you can see what obfuscation tools are doing to your classes as well. It can also do decompilation, though I wouldn't recommend it.

Antimony
  • 37,781
  • 10
  • 100
  • 107
5
  • JAD is one that works and is simple.

  • Also, if you just want to see the methods, use javap.

Berlin Brown
  • 11,504
  • 37
  • 135
  • 203
4

JAD doesn't work for me (Ubuntu 11.10 issue) so I've moved forward and sopped on JODO. At least it has Open Java source code and been able to decompile my .class properly.

I recommend to check out 'branches/generic' branch first. The trunks is not stable.

  • 1
    JODO is [sporadically maintained](http://sourceforge.net/p/jode/code/1418/tree/trunk/jode/) while CFR and Procyon are actively developed and have JDK 8 support. – Janus Troelsen Aug 22 '13 at 11:30
4

On IntelliJ IDEA platform you can use Java Decompiler IntelliJ Plugin. It allows you to display all the Java sources during your debugging process, even if you do not have them all. It is based on the famous tools JD-GUI.

enter image description here

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
1

For OSX I recommend: jarzilla or JD-GUI

They both allow you to view jar,war,etc. file content and decompiles any class files inside of them.

Jarzilla: https://code.google.com/p/jarzilla/
JD-GUI: http://jd.benow.ca/

cjackson
  • 1,637
  • 1
  • 13
  • 25
1

With AndroChef Java Decompiler you can decompile apk, dex, jar and java class-files. It's simple and easy. AndroChef JD is based on FernFlower. You can evaluate it in 10 free uses.

AndroChef supports Java language features like generics, enums and annotations. According to some studies, AndroChef Java Decompiler is able to decompile 98.04% of Java applications generated with traditional Java compilers - a very high recovery rate. It is simple but powerful tool that allows you to decompile Java and Dalvik bytecode (DEX, APK) into readable Java source.

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259