Search code examples
javabytecode

Understanding Java Byte Code


Often I am stuck with a java class file with no source and I am trying to understand the problem I have at hand.

Note a decompiler is useful but not sufficient in all situation...

I have two question

  1. What tools are available to view java byte code (preferably available from the linux command line )
  2. What are good references to get familiar with java byte code syntax

Solution

  • Rather than looking directly at the Java bytecode, which will require familiarity with the Java virtual machine and its operations, one could try to use a Java decompiling utility. A decompiler will attempt to create a java source file from the specified class file.

    The How do I “decompile” Java class files? is a related question which would be informative for finding out how to decompile Java class files.

    That said, one could use the javap command which is part of the JDK in order to disassemble Java class files. The output of javap will be the Java bytecode contained in the class files. But do be warned that the bytecode does not resemble the Java source code at all.

    The definite source for learning about the Java bytecode and the Java Virtual Machine itself would be The Java Virtual Machine Specification, Second Edition. In particular, Chapter 6: The Java Virtual Machine Instruction Set has an index of all the bytecode instructions.