In Java programming world, ‘How to decompile java class file using decompiler‘ is an interesting topic. There are few decompilers available in the market to decompile a java class file (.class).

In this tutorial we will understand ‘How to decompile java class file using decompiler’ or ‘How to decompile java byte code in to java source code‘.

Tools & Technologies Required:

1. Java SE 7 – JDK/JRE

2. Eclipse Juno – Version 4.2 as of this tutorial writing

Before going into details of ‘How to decompile java class file using decompiler’, we will have a look at the process in coding, compiling, and running a simple java program.

To demonstrate an example, we will write a simple java program that prints a statement ‘Hello Java World‘ on the console.

To write this simple ‘HelloWorld’ java program, I have used the ‘Eclipse IDE‘ or you can use any plain text editor.

Java Hello World Program How to decompile java class file using decompiler

Whenever we compile the above code(.java), the java compiler (javac) converts the java source code (human readable) into java byte code(machine language of the java virtual machine)(.class).

The Java Runtime (“java“) run’s the compiled byte code, along with the input to produce the desired output.

Where is the Java Byte Code(.class) is stored after the Java Compiler (javac) compiles the Java Source Code(.java):

This is how the java source code and byte code structures looks on the local machine.

Java Process How to decompile java class file using decompiler

Java Byte Code is an input to Java Virtual Machine to produce the desired output.

Because the Java VM is available on many different operating systems, the same .class files are capable of running on Microsoft Windows, Linux, or Mac OS.

How to decompile java class file using decompiler:

So in the above steps we discussed how the to write, compile, and execute a Java Source Code.

Now we will see, how to decompile java class file that we have written earlier in the tutorial.

Byte Code generated by java compiler can again be converted back to java source code, using decompiler tools.

To decompile java class file (ex: HelloWorld.class), we will use one of the freely available decompilers on the web called JAD decompiler.

Where to download JAD decompiler:

The official JAD website is down (I downloaded it few years back).

You can download JAD from:

http://www.varaneckas.com/jad/

http://www.softpedia.com/get/Programming/Debuggers-Decompilers-Dissasemblers/JAD.shtml

You can use JAD decompiler in 2 ways:

1. Command Line to decompile java class file

2. Java Decompiler (JAD) Eclipse Plugin

1. Command Line

Download and extract zip file into your machine or place the jad.exe in your C dive.

Go to the JAD folder.

Copy our ‘HelloWorld.class’ file into JAD folder.

Decompile Java Class File How to decompile java class file using decompiler

Launch the command line (cmd.exe) from your windows start center, to go to the JAD folder.

Use this command on the command line:

C:\>jad HelloWorld

And this is my command line screenshot:

JAD Commandline How to decompile java class file using decompiler

And this is my JAD folder screenshot after the ‘jad HelloWorld’ command is run from command line:

JAD Folder How to decompile java class file using decompiler

The source file output generated by JAD is in file with .jad extension.
Let’s look at the source that you get after decompillng our HelloWorld.class file.

JAD Source Code How to decompile java class file using decompiler

2. Java Decompiler (JAD) Eclipse Plugin

Step 1: Download the JAD zip file and extract (you already have done this step for command line example).

Step 2: Download the JAD Eclipse Plugin from SourceForge Website - Download Link.

The plugin is - net.sf.jadclipse_3.3.0.jar

Step 3: Put the JadClipse JAR file(net.sf.jadclipse_3.3.0.jar) into the plugins folder of your Eclipse installation.

JAD Eclipse Plugin How to decompile java class file using decompiler

Step 4: Restart the eclipse

Step 5: In Eclipse > Go to Window > Preferences… > General > Editors > File Associations and make sure that the JadClipse Class File Viewer has the default file association for *.class files and click Apply button.

JAD Eclipse Class Checker How to decompile java class file using decompiler

Step 6: Configure the path to the Jad executable (jad.exe) – check Step 1 for the path of your jad.exe

In Eclipse > Go to Window > Preferences… >Java > JadEclipse > Type Jad’s path in “Path to Decompiler” field.

Java Decompiler JAD Eclipse Configuration How to decompile java class file using decompiler

Step 7: Test the JAD in Eclipse

In Eclipse IDE, navigate to any class which does not have the source code and press F3 key, JAD will decompile it automatically and opens in a editor on right panel of the Eclipse IDE.

JAD F3 How to decompile java class file using decompiler

Category:

Java

Tags:

, , ,

We appreciate for your comments and we will get back to your question as soon as possible.