Transcript javap
javap
26-Jul-16
Bytecode
Java is compiled into bytecode, which is intermediate
between Java and a “real” assembly language
Because Java is now so widespread, many other
languages now can be compiled to bytecode
To implement Java, it is only necessary to implement
bytecode, and this is a lot simpler
Ada, Smalltalk, Lisp, Python (Jython), Ruby (JRuby),
undoubtedly others
Java’s javap command shows the generated bytecode
Example
% javac JavapDemoApplication.java
% javap -c JavapDemoApplication
Compiled from JavapDemoApplication.java
public class JavapDemoApplication extends java.lang.Object {
public JavapDemoApplication();
public static void main(java.lang.String[]);
}
Method JavapDemoApplication()
0 aload_0
1 invokespecial #1 <Method java.lang.Object()>
4 return
Method void main(java.lang.String[])
0 getstatic #2 <Field java.io.PrintStream out>
3 ldc #3 <String "javap Demo Application">
5 invokevirtual #4 <Method void println(java.lang.String)>
8 return
Source: http://www.idevelopment.info/data/Programming/java/miscellaneous_java/Using_javap.html
Writing in bytecode
Unfortunately, javap doesn’t show you the complete
bytecode, only the “interesting” bits
It is possible to write and run bytecode programs, using
a bytecode assembler called Jasmin
Unfortunately, Jasmin is old, not maintained, and hard
to find
I have a Jasmin plugin for Eclipse, written by a pair of former
students, but it’s not “ready for prime time”
The End