Java Decompiler

Decompiler is to reverse engineer source code from object code. A decompiler for java should get the respective source file from its Java binary class file.

Java decompiler world is in mess, yes it really looks like kid’s mud play. To our surprise, it is difficult to find a decent Java decompiler in the whole web world.

mud

JAva Decompiler (JAD – No longer maintained)

When we say decompiler for Java, it is almost synonymous to JAD. JAD was/is the popular Java decompiler we can find. Very long back, when I started learning Java, I remember using JAD, may be with JDK1.2 or so. It was very popular and almost the only tool for Java class decompilation.

We may find lots and lots of software tools claiming to be Java decompilers. But if we dig deep then we can find that 90% of them are just the user interface and the underlying engine will be JAD decompiler.

JAD is copright software by Pavel Kouznetsov. JAD was written in C++ and its first version was released before 1999 and its last stable release version was to provide support for JDK 1.4.

JAD does not support JDK 1.5 and later. It is no longer developed or maintained. If you still want to get a feel of JAD, download its last official stable version 1.5.8g using the below link. I have hosted it as a mirror. This is a copyrighted software by Pavel Kouznetsov and cannot be bundled with any commercial software.

Download JAD – jad158g.win – for Windows

DJ Java Decompiler (UI for JAD)

In that case, what is DJ Java decompiler? DJ Java decompiler is GUI for JAD and provided by Atanas Neshkov. Its last stable version was released on August 2011. Since JAD is no longer maintained, it does not make sense to use DJ Java decompiler either as it is just the UI for JAD.

Java Decompiler Options

I can hear you shouting. JAD cannot be used and DJ too is also just an UI for JAD, so what are the options we have for decompiler in Java? We couldn’t find anything other than these!

There are couple of options for decompiler for Java which looks promising,

  1. JD Java Decompiler
  2. Procyon

These are the two options that are alive and maintained as of now and promises support for latest versions of Java.

1. JD Java Decompiler

Let us first explore JD Java decompiler project and do some simple Java class decompilations. JD-gui is a light weight application with a sleek user interface.

I wrote a simple Java factorial program to test JD Java decompiler and that program is as follows:

Java Factorial Sample

package com.javapapers.java;

import java.util.Scanner;

public class JavaFactorial {
	public static void main(String args[]) {
		int n, factorial = 1;
		System.out.print("Factorial of: ");
		Scanner input = null;
		try {
			input = new Scanner(System.in);
			n = input.nextInt();
		} finally {
			input.close();
		}
		if (n < 0)
			System.out.println("Try greater than 0.");
		else {
			for (int i = 1; i <= n; i++)
				factorial = factorial * i;
			System.out.println("Factorial " + n + " = " + factorial);
		}
	}
}

Decompiled Java Source

Following is the screen shot of both the Java factorial source in Eclipse IDE and its decompiled source using JD-gui Java decompiler. It is simple and easy, just open the .class Java binary file using the gui and it works clean.

JD Decompiled Java Class

Decompile Java using Eclipse (JD-Eclipse plugin)

No Java tool is complete unless it provides a plugin for Eclipse IDE. Eclipse is the most popular Java IDE.

JD Java decompiler provides a plugin for Eclipse IDE, so that we can decompile a Java class file within the Eclipse IDE itself.

Install the JD-Eclipse plugin as shown in the next screen shot.

Install JD Decompile Eclipse

JD Java decompile Eclipse plugin will take some good time to install, may be you should have a big coffee during the time. On a side note, Eclipse should still refine its plugin installation process. Once installed a java class file can be just opened and decompiled on the go.

2. Procyon Decompiler for Java

Procyon Java Decompiler is by mstrobel and hosted in Bitbucket. Procyon is a suite of tools containing lot more than the Java decompiler. It is very actively under development (I noticed a commit in Bitbucket during writing this article). Procyon is early in its development, he is just started and not offers a complete version yet. Still why I chose to give a coverage is primarily for two reasons,

  1. almost no one is actively working in this Java world for decompilers (at least as far as I know) – Procyon is actively developed
  2. Procyon Java Decompiler is open source

Let us wish him success on this Java decompiler project.

This Core Java tutorial was added on 07/07/2013.

Comments on "Java Decompiler" Tutorial:

  1. Swetha says:

    Joe, this is a cool article. Till now, I am confused about Java decompilers available. Tried once and got frustrated. Thanks for summarizing about the decompilers available in a simple manner.

    Man, only you can write technology in such a lively way. Thanks, keep writing.

  2. srikanth says:

    java Decompiler is virus software are not? because i am installing in my system my avast antivirus software was blocked that software.

    • Joe says:

      Srikanth, decompilers in Java are surely not a virus software. Looks like Avast is too much sincere. You can add a ignore flag in its settings-option for the Java decompiler you are trying to use.

  3. ajith says:

    i was using jad and had an issue in eclipse i could not set up debug pointer in the class file. do any of the other decompilers you are pointing to allow that?

    thanks for your time

    • Joe says:

      Ajith, JD-Eclipse decompiler which I have given in the article helps in debugging front. Please refer the comment below by David. ‘realign’ version of this decompiler should be used for debugging purposes as it the lines in source will match in it.

  4. Abhishek says:

    Hi Joe,

    Thanks for sharing this article. I was unaware of the fact of decompilers till today untill I read this article.

    I had a question; I’m not sure if this is a viable question. I believe decompilers are disadvantages to the developers, as the .class files embedded in the jar files of any project can be re-constructed with its source code with the help of decompilers, without the knowledge of the developer. This can lead to breach of Intellectual Property rights?

    Please let me know the intention behind developing such a tool of decompilers.
    Thank in advance.

    • Joe says:

      Yes and No!

      Java decompilers do not help us in our daily development activity. But, it will be of good use in a corner case. Occasionally when we have a jar and do not have access to the source files, it will help us debug a critical issue.

      Re-constructing a class file to Java source and then modify it and include in our application is not legal and should never be done.

      • Anonymous says:

        Sadly, I have run into the real case at my current job where a project was written many years ago by a contractor as work-for-hire but the source had actually been lost. In this case I ended up decompiling the source, running Eclipse reformat commands, and then updating it to run without warnings on Java 1.7 so there are some edge cases where decompliation is both useful and legal. I have also run into the issue of it sometimes being very useful to see the code that was causing an issue when it was binary and had no documentaion other than some auto-generated javadocs.

        • Joe says:

          Thanks for sharing and this is a real good case for the need of decompilers for Java.

          Also, uneventful disk crashes resulting in loss of source and no backups available can be another situation.

          Decompilers might be rarely required, but when the necessity arises we will become desperate for it.

  5. Ganesh Bhosale says:

    Thanks Joe! I follow every article of java papers and love reading your articles mainly because you explain it with real world examples.

    I would like to add that – Decompiled code will never be identical with original code by source code. It will be functionally same but not by source code. In Java 5, Types elements like List will be compiled to List but type String will never be stored in .class file, hence we can’t decompile it back to original source format.

    • Joe says:

      Yes thats right. It is because the Java compiler applies its own optimization while doing the transformation from source to binary.

  6. Navneet Sharma says:

    Dear Joe,

    I have been reading your articles since long back and I really enjoyed all of them. Joe, I have an enterprise java application. I can remotely debug it’s APP-INF/lib components(*.jar) but I don’t have any idea to debug it’s WEB component(*.jsp, *.js,etc,). Please suggest how can i debug these components remotely in eclipse.

    Thanks in advance !

    Hoping your prompt response !

  7. Suyog says:

    Good one!

  8. David M. Karr says:

    If you use JD-Eclipse, the Eclipse plugin associated with JD-GUI, you should also be aware of the “realign” version of this, of which I believe there are two forks. The following page describes one of the forks, and references the other:

    http://mchr3k.github.io/jdeclipse-realign/

    The point of the “realign” edition is apparent if you’ve ever tried to set a breakpoint in a decompiled view from the original JD-Eclipse. The original version produces Java line numbers that don’t match the original source code. For instance, if you set a breakpoint on line 89 in the decompiled view, that might correspond to line 225 in the original source. It can sometimes be challenging or even impossible to set a breakpoint at a specific line of decompiled code. The “realign” edition simply emits blank lines so that the line in the decompiled view comes out at the same line number as in the original source code.

  9. Sandeep says:

    Very nicely summarized Joe. You have a natural flair for writing technical stuff in a layman’s way :-)

    That said, JAD CAN be used with JDK 1.5 and above too. In fact, I still use the humble ol’ JAD with JDK 1.7.

    And even the old eclipse plugin – net.sf.jadclipse_3.3.0.jar still works if you point it to JAD

    • Joe says:

      Sandeep,

      As you have rightly told, my writing is ‘natural’ and in a layman style. Why it is natural is, that is all I know :-)

      Yes those facts you have given about JAD decompiler is right. It is better we identify and move to other decompilers, since JAD is not maintained/developed.

  10. ganapathisundaram says:

    This is a wonderful explanations about Java Decompiler. I appreciate your content with lucid style and thank you to share these information to the forum. I love to read your post every time.

    Is there any possible to create our own decompiler rathar than third party?

    Thanks,
    Ganapathi

  11. Bhaskar says:

    Hi Joe,

    I have used “JD Java Decompiler” in both GUI and in eclipse plugin.Its is cool thing for a guys who are much eager to know about how the java inbuilt classes are written and also we can broke any java framework’s classes and understand the various methods,varaibles,etc present in the framework.

  12. Mike Strobel says:

    Thanks for mentioning my Procyon project in your article. You may be interested in the GUI front-end developed by SecureTeam: http://www.secureteam.net/Java-Decompiler.aspx

  13. grails cookbook says:

    I seldom need a decompiler. They seem not very popular now. But nice to know they are still alive. Will definitely check out Procyon

  14. MaxWeber says:

    Java Decompiler was the best I found in a quick search. Its still not 100% like the good old days with jad. One has to fix up the errors. Still, its much better than guessing what the underlying libs are doing… at least you can read through the code to try to track down the bugs. Been on this one over two days now…a working decompiler is missing from Android Studio – it just days “Compiled Code”. Wonderful.

  15. Sagar says:

    Thanks for sharing such a nice and knowledge improving article.

  16. EW says:

    Does anyone have an opinion on DJ Java Decompiler.

    http://www.neshkov.com/

    I’m trying to find one we can use at corporate to decompile our own java files. Apparently the source code for this particular file was lost and the developer needs to find a decompiler. CAVAJ decomplier also had restrictions on commercial use.

    Thanks for the article sums up what i have been seeing while trying to find a current product.

  17. soubhagini says:

    Dear joe,i could nt understand java decompiler ,plz help me

  18. Amol says:

    Hi joe,

    I want to use a decompiler in my java code(a method call or anything similar), the scenario is that I will be accepting 2 class files as inputs to my program, and I have to generate a report that lists the differences between the two(which I will be doing using eclipse compare plugin).

    I am currently stuck with decompiling the class files, tried using jad but it doesn’t work as well with file involving annotations. Is there any alternative you can suggest.

    Thank you in advance
    Amol.

  19. S Gupta says:

    I want to protect my .class from decomplie tools, how can i protect? is there any way in eclipse? can you give an example?

    Thanks in advance

  20. vipul says:

    what is the code for using javap tool in command prompt and saving the code directly into a text file ?

  21. Lakhpat says:

    Does anyone know of a plugin or third-party tool for decompiling a jar file? We’re using this really old version of SOAP for which the source no longer seems to exist on the ‘net (SOAP 1.0 from Apache) and we seem to have some issues that I can’t resolve unless I can set breakpoints inside that code. Any recommendations are much appreciated,

  22. sreedhar says:

    Thanks sir,
    But when we open that classes,I am unable to do
    debugging in those classes. How to debug in those classes.

  23. baskar says:

    I extract the file using decompiler but i cant undersatnd the coding, it was huge… can u help me to understand how to read the codes…

  24. Type Erasure says:

    […] Then de-compile that generated class file and inspect what type erasure has done. You may use any Java decompiler of your choice. For now the javap utility is sufficient for this inspection purpose. First compile […]

  25. hari says:

    I am decompiling the .apk file source code in that i am getting code with numbers instated of the layout names and R.id names please give me solution

  26. […] Java Decompiler Decompiler is to reverse engineer source code from object code. A decompiler for java should get the respective source file from its Java binary class file. […]

Your Comment

↑ Go to top