What is Bytecode

suggest change

Bytecode is the set of instructions used by the JVM. To illustrate this let’s take this Hello World program.

public static void main(String[] args){
    System.out.println("Hello World");
}

This is what it turns into when compiled into bytecode.

public static main([Ljava/lang/String; args)V    
    getstatic java/lang/System out Ljava/io/PrintStream;
    ldc "Hello World"
    invokevirtual java/io/PrintStream print(Ljava/lang/String;)V

What’s the logic behind this?

getstatic - Retreives the value of a static field of a class. In this case, the PrintStream “Out” of System.

ldc - Push a constant onto the stack. In this case, the String “Hello World”

invokevirtual - Invokes a method on a loaded reference on the stack and puts the result on the stack. Parameters of the method are also taken from the stack.

Well, there has to be more right?

There are 255 opcodes, but not all of them are implemented yet. A table with all of the current opcodes can be found here: Java bytecode instruction listings.

How can I write / edit bytecode?

There’s multiple ways to write and edit bytecode. You can use a compiler, use a library, or use a program.

For writing:

For editing:

I’d like to learn more about bytecode!

There’s probably a specific documentation page specificially for bytecode. This page focuses on the modification of bytecode using different libraries and tools.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Bytecode Modification:
* What is Bytecode

Table Of Contents
8 Arrays
10 Maps
11 Strings
25 JAXB
29 Enums
32 Audio
41 Scanner
63 Logging
75 Lists
78 Sets
85 Bytecode Modification
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap