Signup/Sign In
LAST UPDATED: SEPTEMBER 6, 2021

How to decompile Java class files?

    Every Java developer during their career comes across a common situation where he/she has to work with existing 3rd party .jar files. You might have already been through this and if you are reading this article then chances are that you are facing this problem right now.

    Let's elaborate on the problem for newbies. Suppose you are working with any third party JAR file and you need to check the code written in it or let's say you have created a JAR file that you have to share with someone and later you want to check the code in it. So the question here is, as we know JAR file will have .class files which we can't see directly, then, how are we going to check the code written in it?

    Here comes the role of Java Decompiler. Let's check below what Decompiler is and how to use it.


    What is Decompiler?

    The art of "decompiling" can also be thought upon as reverse engineering. Decompilation involves transforming the bytecode back into Java source.

    How to do it?

    We have various ways and tools to achieve it. The tool that I prefer is "Java Decompiler" which can be found at http://java-decompiler.github.io/. In this tool, I prefer Java Decompiler's UI version which is known as "JD-GUI".

    JD-GUI is a standalone application that is used to display Java source codes of .class files. You can browse any .class file and the source code can be seen in the tool directly.

    Note:

    As we are using decompiler we need to be very cautious as a lot of low-level information(like comments etc) will get lost in the converted Java source code.

    For example, let's say we have a code which prints a message "Hello World" and it also has a comment section as shown below:

    using Java decompiler

    Now, when you compile your .java file you will have .class file with you. When you try to decompile this .class file using "JD-GUI" the java source code will look as below:

    Using java decompiler

    Here, you can see the difference. We don't have the comments in the decompiled version. Additionally, the string parameter present in the main method has also been changed along with the formatting of the code.


    Conclusion:

    To see the code that is present in .class format file we will need one of the many Java decompilers that are available. In this blog we saw how to use "Java Compiler: JD-GUI" to convert our byte code to the Java source code. I hope the blog makes sense about what decompiler is used for and how to use it. For any questions/comments you can always connect us.

    You may also like:

    Howdy, I’m Rohit. I’m a software engineer living in Indore, Madhya Pradesh, India. I am a fan of technology, reading, and programming. I’m also interested in fitness and innovation. Sincere By Nature. Cricket Fan By Birth....! :)
    IF YOU LIKE IT, THEN SHARE IT
    Advertisement

    RELATED POSTS