Tips & Tricks

Look Inside Compiled Code with Java Bytecode Decompiler

When something is there for us day after day, we tend to take it for granted. In IntelliJ IDEA, there are several features that many people don’t even notice, even as they use them all the time. One of these features is the Java bytecode decompiler.

IntelliJ IDEA: how2pro banner

The Java bytecode decompiler in IntelliJ IDEA is a built-in tool that allows you to read compiled bytecode as if it were human-readable Java code.

Download IntelliJ IDEA

Let’s say you have a library packed in a .jar file. You just downloaded it from the Internet and don’t have the source code for it. How do you look inside and make sure it actually has what you need?

If you open a .class file in a text editor, you’ll only see the bytecode that sometimes makes little sense. However, if you open the same file in IntelliJ IDEA, the IDE shows you the human-readable Java code from your .jar, without actually converting .class files into .java files. The notification panel above the editor informs you that you’re reading a decompiled .class file.

The decompiler can not only convert bytecode to Java code, but it can also debug it. This means you can use breakpoints anywhere in the decompiled code with almost the same experience that you’d normally have when you debug your source code.

Of course, you can always open the bytecode viewer for any compiled class. Open the necessary .class file in the editor in IntelliJ IDEA and then select View | Show Bytecode from the main menu. If you’re not seeing this option, make sure that the bundled Bytecode Viewer plugin is enabled in Settings/Preferences | Plugins.

The Bytecode Viewer provides basic syntax highlighting, and it shows the information in a way that is comfortable for reading.

The decompiler is powered by the Java Bytecode Decompiler plugin, which is bundled and enabled by default.

This tool has been a part of IntelliJ IDEA for ages. So if you already have the IDE, give it a try and let us know what you think in the comment section. If you don’t have IntelliJ IDEA yet, grab a build and stay tuned for more news.

Happy Developing!

image description