Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Byte code to Java source code

Tags:

Is it possible to convert a .class file to .java file?

How can this be done?

What about the correctness of the code extracted from this option?

like image 666
Sachin Chourasiya Avatar asked Dec 02 '09 10:12

Sachin Chourasiya


People also ask

Can we convert Java bytecode to source code?

It is possible. You need a Java Decompiler to do this. You'll find mostly it'll do a surprisingly good job.

What is Java source code and byte code?

Source code is written by a human or programmer. Byte code is not written by humans or programmers. 02. It is written by using some high-level programming language.

Who converts bytecode to machine code in Java?

Java Virtual Machine (JVM) is a engine that provides runtime environment to drive the Java Code or applications. It converts Java bytecode into machines language. JVM is a part of Java Run Environment (JRE).

Can Java bytecode be decompiled?

Abstract. Java virtual machines execute Java bytecode instructions. Since this bytecode is a higher level representation than traditional ob- ject code, it is possible to decompile it back to Java source.


2 Answers

It is possible. You need a Java Decompiler to do this.

You'll find mostly it'll do a surprisingly good job. What you'll get is a valid .java file which will compile to the .class file but this .java file won't necessarily be the same as the original source code. Things like looping constructs might come out differently, and anything that's compile time only such as generics and annotations won't be re-created.

You might have a problem if the code has been obfuscated. This is a process which alters the class files to make them hard to decompile. For example, class and variable names are changed to all be similar so you'll end up with code like aa.a(ab) instead of employee.setName(name) and it's very hard to work out what's going on.

I remember using JAD to do this but I don't think this is actively maintained so it may not work with never versions of Java. A Google search for java decompiler will give you plenty of options.

like image 122
Dave Webb Avatar answered Oct 07 '22 18:10

Dave Webb


This is possible using one of the available Java decompilers. Since you are working from byte-code which may have been optimised by the compiler (inlining static variables, restructing control flow etc) what you get out may not be exactly the same as the code that was originally compiled but it will be functionally equivalent.

like image 31
Tendayi Mawushe Avatar answered Oct 07 '22 17:10

Tendayi Mawushe