Skip to content

Instantly share code, notes, and snippets.

@tlehman
Created March 30, 2018 21:11
Show Gist options
  • Save tlehman/63939315d6a2bd459fbc2f1848a620d0 to your computer and use it in GitHub Desktop.
Save tlehman/63939315d6a2bd459fbc2f1848a620d0 to your computer and use it in GitHub Desktop.
Java bytecode example
public class AddTwo {
public static void main(String args[]) {
int c = add(2,3);
}
public static int add(int a, int b) {
return a + b;
}
}
@tlehman
Copy link
Author

tlehman commented Mar 30, 2018

Compile this with javac AddTwo.java

Then decompile the bytecode with javap -c AddTwo.class to get:

Compiled from "AddTwo.java"
public class AddTwo {
  public AddTwo();
    Code:
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: return

  public static void main(java.lang.String[]);
    Code:
       0: iconst_2
       1: iconst_3
       2: invokestatic  #2                  // Method add:(II)I
       5: istore_1
       6: return

  public static int add(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: iadd
       3: ireturn
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment