Question

Actually, the question is a bit broader. I know that javac compiles java file into a bytecode, a class file. So, class file should contain jvm instructions and all that. On the other hand, the only way to see those instructions is to decompile class file with javap -c. But it isn't decompiling, right? Because if it was decompiling, it would produce java file. So, my guess here is that javac compiles java file like 2 times (which isn't actually true, but let's assume that for simplicity), first to jvm instruction, then to bytecode, so javap -c decompiles from bytecode to jvm instructions. Jvm supposed to understand bytecode, thus it can't understand instructions. I'm a bit confused here. Could someone explain what's going on here?

Was it helpful?

Solution

Javap doesn't decompile the bytecode, it disassembles it. To explain the difference, we can switch the terms the other way around: compilation is translating human readable code to bytecode whereas assembly is translating assembly instructions to bytecode.

OTHER TIPS

javap displays human readable form of JVM instructions. JVM instructions are codes for JVM. What javap shows is assembler language.

If you want to see the byte code in more readable form use java decompiler, e.g. jad. There are several UI wrappers for jad including plug-in for Eclipse.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top