Best Java Decompilers You Must Know

Have you ever wondered if there is magic to convert the compiled class file back to the source code in Java. Decompilation in Java is just the reverse process of compilation. Till now, we have been compiling our Java program into the executable class file. But in this article, we will learn to decompile the class file into the Java source code. To serve the same purpose, there are many Java decompilers on the internet that we can download and install in our machine and use them to decompile the code. So let’s dive into this interesting and uncommon concept of Java.

Java Decompilers

Keeping you updated with latest technology trends, Join TechVidvan on Telegram

What are Java Decompilers?

Java Decompiler is a special kind of compiler that performs the reverse process of the Java compiler. It returns the source code in Java corresponding to the Object code in the form of a class file which is in binary form. Simply put, the decompiler in Java takes the class file as input and produces the source code in Java as the output. But the decompiler never creates the exact copy of the original source code. The reason is that there is some kind of information loss from the source code while compiling the Java program.

There are a number of Java decompilers available but choosing the best of them is a very difficult task. However, we will discuss some most popular and widely used decompilers in Java.

There are many Java decompilers available. Some of them are:

1. JAD Decompiler

The JAD(Java Decompiler) is an unmaintained decompiler for Java. JAD provides a command-line interface to the users. This command-line application converts the .class files into the java file. It will decompile the class files or compiled code into the java source code. The JAD application is basically written in the C++ language. It helps the developers to beautify the lines of their java code to enhance the readability of the generated source code.

2. DJ Java Decompiler(UI for JAD)

The DJ Java decompiler is a windows based decompiler that constructs a Java source code from the compiled binary class file. It acts as a GUI(Graphical User Interface) for JAD decompilers. It was developed by Atanas Nehskov. Its last release came in August 2011.
This DJ decompiler can decompile the compiled files into the original source code in the form of a test or other formats. This decompiler is very simple and easy to use. The interesting thing is that even if you don’t have Java installed in your machine, then also you can work with this Java decompiler. Also, you can decompile more than one class file at a time.

3. JDProject(Java Decompiler Project)

The Java Decompiler Project(JDProject) is a set of tools developed to extract the source code from the given compiled binary class file. It is one of the most widely used offline Java decompilers. It is developed for decompiling Java code written in Java 5 and later versions. This decompiler can be used for all platforms-

It includes three tools: JD-GUI, JD-Core, and JD-Eclipse, JD-Intellij. JD-GUI is a graphical interface for displaying the source code corresponding to the class files. JD-Eclipse is a plug-in platform for the Eclipse IDE. JD-Intellij is a plug-in for Intellij IDEA.

4. Procyon

Procyon is another java decompiler. It was developed by Mike Strobel. Using Procyon, it is very comfortable to work with annotations, enum, Local classes, Method references and Lambdas of Java 8.

This decompiler offers three types of output modes:

  • Java(default)
  • Raw Bytecode
  • An intermediate representation- Bytecode AST

5. JBVD

JBVD stands for Java Bytecode Viewer and Decompiler. It works on the basis of javassist open source libraries. It can only use for Windows Operating Systems. But if we want to work with this decompiler, we need to install Java in our system.

6. Cavaj Java Decompiler

The Cavaj decompiler is best for users using the Windows operating system. This decompiler is very easy to use and can decompile almost every Java compiled code or bytecode. The main disadvantage of this decompiler is that it is not available for Linux and MacOS users and also lacks syntax highlighting.

7. AndroChef

AndroChef is another decompiler that you can use if you are a Windows user. This Java decompiler can decompile all types of files such as apk, dex, jar and class files of Java.It is very simple and easy to use and supports all Windows platforms such as Windows XP, Windows Vista, Windows 2003, Windows 7, Windows 8, 8.1 and 10. AndroChef successfully decompiles all the class files that support java versions- java6, java 7 and java 8 .jar and .class files.

8. CFR Decompiler

The full form of CFR Class File Reader. This decomiler is written purely in Java6. However, this decompiler still supports the latest functionalities of java 8 such as lambdas. There is only drawback of using this decompiler is that it is not an open source program.

Steps to decompile a class file to a Java file using JAD decompiler

To decompile a class file, we are going to use the JAD decompiler.

Firstly, we have to download it from http://www.javadecompilers.com/jad.

After opening this link, you will see the following page, then click the link to download jad for windows:

Step 1: Download the file and extract the zip file and get the jad.exe file.

Step 2: Now, create a Java program that just prints something:

The file name is MyProgram.java:

public class MyProgram {
  public static void main(String args[]) {
    System.out.println("Hello World”);
    System.out.println("
    Welcome to TechVidvan Tutorial of Java”);
  }
}

Step 3: Firstly move this Java file into the same folder where you have extracted the jad application as shown below:

Jad decompiler

Step 4: Now compile and run this java file. It will generate a class file:

decompile java program

We will get the class file in the respective folder:

Step 5: Now move the .class file and jad application to another folder named Decompiler.

Step 6: Now open the command prompt window and Type the command: jad MyProgram

The above command generates a .jad file in the respective folder.

Java decompilers

Step 7: Type the command: jad -s java MyProgram

Step 8: It generates the .java file in the same folder.

decompile java program

// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   MyProgram.java

import java.io.PrintStream;

public class MyProgram {

  public MyProgram() {}

  public static void main(String args[]) {
    System.out.println("Hello World");
    System.out.println("Welcome to TechVidvan Tutorial of Java");
  }
}

We can observe that the written .java file is different from the generated .java file but gives the same output.

Advantages of Java Decompilers

There are many advantages that encourage us to use the decompiler:

  • Decompilers can save our time when we have lost the corresponding source code of a binary byte code. If we have the compiled code, then we can easily get the source code with the help of the decompiler.
  • Decompilers are the prized component of any software piracy kit.
  • Decompilers also help us to clarify or improve the poor documentation. After generating a source code from the bytecode, we get a proper documentation for each line of code that was not written by us actually in the code.

Disadvantages of Java Decompilers

But there are many complexities, for example, Java code is structured, and byte code is not structured. Moreover, the transformation is not one to one: two different Java programs may yield identical byte code.

Conclusion

Decompiling a Java class file is possible using the decompilers in Java. But it is illegal to decompile someone’s class file without his/her permission. Because it can reveal the real java source code that is not wanted by the Java developers. The JAD decompiler is very old but it is still widely useful to many Java developers. We could see how the class was easily converted back to the source file in some easy steps.

We hope you have understood how to decompile a java class file or compiled code back to the original source code.

Do not forget to rate TechVidvan at Google if you liked the article.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.