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.

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 yellow notification panel above the editor informs you that you’re reading a decompiled file.

decomplier2

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.

decompiler-debugger2

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.

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

decompiler-bytecode

The decompiler works in both IntelliJ IDEA Ultimate and IntelliJ IDEA Community Edition. It 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 or stay tuned for more news, because very soon we’re releasing IntelliJ IDEA 2020.1, which features our Java bytecode decompiler together with a range of exciting features and updates.

Happy Developing!

This entry was posted in Tips & Tricks and tagged . Bookmark the permalink.

6 Responses to Look Inside Compiled Code with Java Bytecode Decompiler

  1. Ron Welch says:

    Thanks for the article. I have been using this feature of InteillJ for many years, and find it invaluable. There is one slight annoyance with it though, which might just be me not having things configured correctly. Sometimes when I stepping through code in the debugger, I will hit a class that I do not have the source code for, and the class will be seamlessly de-compiled and I will step into it. Many times this is not what I want. I would like to be able to flag a class or set of classes to be stepped over and not de-compiled so that I can step through just the classes I am actively working on. Is that possible? Thanks again

    • abc says:

      There’s feature just for that: Settings -> Build, execution, deployment -> Debugger -> Stepping where you can define which classes/packages should be skipped when debugging.

  2. yury says:

    “Java Bytecode Decompiler plugin” had a problem with it when viewing oracle jdbc driver code: looks like it fails to decompile very large methods

  3. Denny says:

    Sometimes I would like to see what the compiler does with my classes. So, is there a simple (sic!) way to jump from the class I am currently in, to the compiled -> decompiled .class file?
    Like, a shortcut which does exactly that.

    • There isn’t, but there is a better thing – View | Show Bytecode. The decompiler‘s goal is producing readable text, meaning it unwinds de-sugaring performed by the compiler.

Leave a Reply

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