Programming the JVM in bytecode is a low-level approach to Java programming. It involves writing bytecode instructions directly instead of using a high-level programming language such as Java. Bytecode is a low-level representation of Java code that can be executed by the Java Virtual Machine (JVM). In this tutorial, we will walk you through the steps required to program the JVM in bytecode.
Step 1: Choose a Bytecode Editor
To write bytecode, you will need a bytecode editor. There are several editors available, including :-
For this tutorial, we will use the JBE editor and Jasmin assembler, both of which are free and easy to use.
Step 2: Write Java Code
Before we can write bytecode, we need to write Java code that we want to compile into bytecode. For this tutorial, we will use a simple Java class called “HelloWorld”.
1 2 3 4 5 | public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } |
Step 3: Compile the Java Code
Compile the Java code using the “javac” command in your command prompt or terminal.
1 | javac HelloWorld.java |
This will create a “HelloWorld.class” file, which contains the bytecode representation of the Java class.
Step 4: Open the Bytecode Editor
Open the JBE bytecode editor and load the “HelloWorld.class” file.
Step 5: Write Bytecode Instructions
In the bytecode editor, you can view the bytecode instructions for the “HelloWorld” class. You can also modify these instructions or add new ones to the bytecode.
For example, if you want to modify the “main” method to print “Hello, Bytecode!” instead of “Hello, World!”, you can modify the bytecode instructions as follows:

Step 6: Save the Bytecode
After making changes to the bytecode instructions, save the modified “HelloWorld.class” file.
1 | java HelloWorld |
Step 7: Run the Bytecode
Run the modified bytecode using the “java” command in your command prompt or terminal.

We have now successfully programmed the JVM in bytecode using a bytecode editor. While this approach to Java programming is not commonly used, it can be useful in certain situations where performance optimization is required.
Using Jasmin to Write Bytecode Assembler
Install Jasmin
Download the latest version of Jasmin from Sourceforge. Unzip the file and save to a local directory. Add the directory to your Java classpath
Hello World
Add the following code to a file called HelloWord.j
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | .class public HelloWorld .super java/lang/Object ; ; standard initializer (calls java.lang.Object's initializer) ; .method public <init>()V aload_0 invokenonvirtual java/lang/Object/<init>()V return .end method ; ; main() - prints out Hello World ; .method public static main([Ljava/lang/String;)V .limit stack 2 ; up to two items can be pushed ; push System.out onto the stack getstatic java/lang/System/out Ljava/io/PrintStream; ; push a string onto the stack ldc "Hello World!" ; call the PrintStream.println() method. invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V ; done return .end method |
To compile the code run the following command
1 2 3 4 5 6 | $ java -jar jasmin.jar HelloWorld.j # or $ java Jasmin HellowWord.j Generated: HelloWorld.class $ java HelloWorld Hello World! |
We can now use JBE to view the byte code and Jasmin to write byte code assembler
More to follow in this tutorial as we explore the entire JVM instruction set and patterns for coding at the byte code level…