I am working on a bytecode manipulation/generation in Java and I was just wondering if there is an easy way I could check the bytecode. I do not want to decompile the file, I would like to actually look at the compiled bytecode. I do not need to edit it. Any links or programs for doing this would be acceptable answers.
Asked
Active
Viewed 1.5k times
18
-
You can normally do it directly from within your IDE. Maybe with a little help from a plugin. – maba May 27 '13 at 13:54
-
2I think `javap` is what you are looking for. A command that comes with the JDK. – Marko Topolnik May 27 '13 at 13:54
-
try javap -c classfile – Satya May 27 '13 at 13:55
-
no that doesnt show all bytecode only field and methods – Popgalop May 27 '13 at 13:57
-
@Popgalop `javap -v` shows the bytecode - see my answer below. – Oak May 27 '13 at 14:01
4 Answers
48
Since you wanted to be guided to some program that can easily show you the byte code then my suggestion is to use IntelliJ IDEA since it has built-in support for viewing byte code.
Here's an example how to do it (it can also be mapped to some keys of your choice):
It is very easy, and it can surely be done in eclipse or NetBeans as well.
![](../../users/profiles/1350762.webp)
maba
- 43,790
- 10
- 103
- 113
-
-
Is this also available in Android studio? At least for classes compield for the JVM (like local Unit Tests etc). – Igor Čordaš Sep 16 '16 at 12:03
-
-
1
-
1@voipp `LINENUMBER 10 L2` means that the code on line number 10 is located at label `L2`. So `L0`, `L1` etc are labels, i.e. jump points in your program. In bytecode there are no functions or loops, there are only jumps (which can be conditional). So the whole program is a bunch of `IF this GO there_1; IF that GO there_2` – Ciprian Tomoiagă May 12 '17 at 15:39
-
`javap -c` outputs something completely different, something much simpler. Is there a way to view that as well? – Nearoo Mar 08 '18 at 17:16
2
The javap
command-line tool, which is bundled with Oracle's JDK, gives a detailed textual dump of .class files along with the constant pool and all functions' bytecode content. Just run it with -v
to get a full dump.
![](../../users/profiles/242762.webp)
Oak
- 24,536
- 5
- 83
- 146
-
but i want to see what the compiler reads when it reads the file so that i can create my own synthetic classes. – Popgalop May 27 '13 at 22:23
-
@Popgalop what the compiler reads in is the actual bytecode, which is not a textual format. I guess you could open it in a hex editor and use [this reference](http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html) to parse it by yourself, but if you want a human-readable dump, `javap -v` is the answer. – Oak May 28 '13 at 07:15
2
I've been working on a decompiler that has a color-coded bytecode output mode (which I find far more readable than javap). It can also output Java code or an intermediate 'bytecode AST'.
![](../../users/profiles/175070.webp)
Mike Strobel
- 23,622
- 51
- 65