Skip to content

How to Decompile Java Class Files with JADX

Purpose

I had a compiled Java .class file and needed to see the original source code. The source was lost, but I had the bytecode. I needed a way to reverse engineer the class file back to readable Java code.

What is JADX?

JADX is a command-line and GUI tool for decompiling Java bytecode. It converts .class files and .jar files back to Java source code. It’s one of the most popular decompilers because it handles modern Java features well and produces clean, readable output.

How to Decompile a Class File

Step 1: Install JADX

On macOS with Homebrew:

install-jadx.sh
brew install jadx

On Linux, you can download the release directly from GitHub:

download-jadx.sh
wget https://github.com/skylot/jadx/releases/download/v1.5.0/jadx-1.5.0.zip
unzip jadx-1.5.0.zip

Step 2: Run JADX on Your Class File

The basic command is straightforward:

decompile-class.sh
jadx ExampleForJadx.class

That’s it. JADX processes the file and creates output in the current directory.

What JADX Produces

After running the command, JADX creates two folders:

output-structure.txt
output/
├── resources/
│ └── (non-class files like properties, xml, etc.)
└── sources/
└── com/
└── baeldung/
└── exampleforjadx/
└── ExampleForJadx.java

The sources folder contains the decompiled Java source code. The package structure is preserved, so a class with package com.baeldung.exampleforjadx; will appear at sources/com/baeldung/exampleforjadx/ClassName.java.

Example: Decompiling a Real Class File

Let me show you what happens with a concrete example. I have a class file at build/classes/java/main/com/example/MyApp.class:

decompile-with-path.sh
jadx build/classes/java/main/com/example/MyApp.class

Output:

jadx-output.txt
INFO - loading ...
INFO - processing ...
INFO - writing sources to ./sources
INFO - finished

Then I can view the decompiled source:

view-source.sh
cat sources/com/example/MyApp.java

The decompiled code looks like this:

MyApp.java
package com.example;
public class MyApp {
private String name;
private int count;
public MyApp(String name, int count) {
this.name = name;
this.count = count;
}
public String getName() {
return this.name;
}
public int getCount() {
return this.count;
}
}

Useful JADX Options

Decompile a JAR File

JADX also works with JAR files:

decompile-jar.sh
jadx myapp.jar

Specify Output Directory

Use -d to set where JADX writes the output:

custom-output.sh
jadx -d /path/to/output ExampleForJadx.class

Show Bytecode

If you want to see the raw bytecode alongside the decompiled code:

show-bytecode.sh
jadx --show-bad-code ExampleForJadx.class

The --show-bad-code flag includes code that JADX couldn’t fully decompile, which helps when analyzing obfuscated or unusual bytecode.

Export as Gradle Project

JADX can export the decompiled code as a Gradle project:

export-gradle.sh
jadx --export-gradle myapp.jar

This creates a buildable Gradle project with proper directory structure.

Why JADX Works Well

JADX uses several decompilation engines internally. It tries different approaches when one fails, which gives it better success rates on obfuscated or unusual bytecode.

Key features:

  • Handles Java 8+ features like lambdas and method references
  • Supports APK, DEX, and AAR files (for Android)
  • Produces readable variable names when possible
  • Preserves generic type information from signatures

Limitations to Keep in Mind

Decompilation isn’t perfect. Some things get lost:

  • Comments - Original comments are stripped during compilation
  • Local variable names - Sometimes replaced with generic names like i, j
  • Formatting - Code style differs from original
  • Some complex constructs - Lambdas and method references may not decompile cleanly

Also, decompiled code may not compile back exactly. It’s useful for understanding logic, not for recovering exact source.

Other Java Decompilers

JADX isn’t the only option:

  • JD-GUI - Older, GUI-focused decompiler
  • Procyon - Handles modern Java features well
  • CFR - Another active decompiler with good Java 8+ support

I prefer JADX because it’s actively maintained and has good Android support.

Decompiling code has legal implications. Only decompile code you own or have permission to analyze. Using decompiled code in your own projects may violate licenses or copyright.

Summary

In this post, I showed how to use JADX to decompile Java class files. The key command is jadx filename.class, which produces a sources folder with the decompiled Java code. JADX preserves the package structure and handles modern Java features well. Remember that decompilation is for understanding code, not recovering exact source files.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments