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:
brew install jadxOn Linux, you can download the release directly from GitHub:
wget https://github.com/skylot/jadx/releases/download/v1.5.0/jadx-1.5.0.zipunzip jadx-1.5.0.zipStep 2: Run JADX on Your Class File
The basic command is straightforward:
jadx ExampleForJadx.classThat’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/├── resources/│ └── (non-class files like properties, xml, etc.)└── sources/ └── com/ └── baeldung/ └── exampleforjadx/ └── ExampleForJadx.javaThe 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:
jadx build/classes/java/main/com/example/MyApp.classOutput:
INFO - loading ...INFO - processing ...INFO - writing sources to ./sourcesINFO - finishedThen I can view the decompiled source:
cat sources/com/example/MyApp.javaThe decompiled code looks like this:
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:
jadx myapp.jarSpecify Output Directory
Use -d to set where JADX writes the output:
jadx -d /path/to/output ExampleForJadx.classShow Bytecode
If you want to see the raw bytecode alongside the decompiled code:
jadx --show-bad-code ExampleForJadx.classThe --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:
jadx --export-gradle myapp.jarThis 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.
Related Knowledge
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.
Legal Considerations
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