Why is it so easy to decompile Java Code?

user818502 picture user818502 · Sep 16, 2012 · Viewed 7k times · Source

So I've just realized how easy it is to decompile my Java code. I've been searching around the net and I can't seem to figure out WHY its so easy. Every time I google something like "Why can I decomilple .class files?" or "Why does Java decompile so easily", all I get is links to software that can easily deompile my code. So I turn to you StackOverflow: why is it that Java can be converted back to easlily readable source code while C++ and other languages aren't very friendly to decompiling?

Thanks

Answer

SLaks picture SLaks · Sep 16, 2012

Because Java byte-code is closer (more similar) to the source than assembly.

In particular, .class files include metadata for classnames, method names, field & parameter types, etc...
All a Java (or .Net) decompiler needs to do is look at the instructions in each method body, and turn them into the appropriate syntactic constructs.

By contrast, native languages like C++ do not include any metadata at all, so the decompiler needs to reconstruct everything.