Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you get a .java file from a .class file in Java

Tags:

java

Was given a couple of .class files but the .java files weren't sent with and I was hoping to find a way to get the .java files using the .class files. Thanks

like image 291
Cole G Avatar asked Feb 26 '16 04:02

Cole G


1 Answers

You can use a decompiler to do so. One of the most major ones is JD-GUI.

JD-Core is a library that reconstructs Java source code from one or more “.class” files. JD-Core may be used to recover lost source code and explore the source of Java runtime libraries. New features of Java 5, such as annotations, generics or type “enum”, are supported. JD-GUI and JD-Eclipse include JD-Core library.

EDIT (2018-02-23): It seems that JD-GUI is incapable of decompiling bytecode compatible with Java 8+ JREs. This, obviously, changes the utility of my answer.

EDIT (2018-05-24): For replacing JD-GUI, I would recommend Luyten, which can be found here. It's very similar to JD-GUI, but supports Java 8 byte code, itself being based on Procyon.

like image 151
ifly6 Avatar answered Nov 14 '22 23:11

ifly6