Decompiling Java Class Files
Problem
You lost the source code.
Solution
If you still have the class files, decompile them.
Discussion
Have you ever looked at a class file by accident? Open it in a text editor, for example, and you might see this. You’ve never done this by accident, right? Sure, I believe you . . .
^H^@Z^C^@^@^@P^H^@[^H^@n^H^@o^H^@p^H^@q^H^@r^H^@s^H^@t^H^@v^H^@y^H
^@z^H^@{^H^@}^H^@Ç^H^@ä^H^@à^H^@á^H^@ª^H^@º^G^@ç^G^@Æ^G^@ô^G^@ö^G^@ò^G^@Û^G^@ù^G
^@ÿ^G^@...^G^@Ü^G^@¢^G^@£^G^@¥
^@^V^@@
^@^\^@@
^@!^@A
^@^Y^@B
^@^[^@CThere’s no resemblance to the Java source file that you wrote and spent so long fussing over the formatting of. What did it get you? Nothing here. The class file is a binary file that can’t be inspected easily. However, it is in a well-documented format, and there’s the rub. Once a format is known, files can be examined. One example of a Java program that examines other Java programs is javap, which gives you the external view of a class file. I’ll show you in Section 25.3 just how this part of javap works and how you can write your own tools that process other Java classes. Meanwhile, this discussion is about decompilation. Let’s suppose you have put some meat through a meat grinder. It’s been converted to zillions of little bits. It might, in fact, look a bit like the class file seen here. Now suppose that unbeknownst to you, your paycheck fell into the meat and went through the grinder. Ugh! But the real question is, can you put the paycheck back together ...