Java Bytecode

Last Updated : 6 Oct 2026

Java bytecode is a set of instructions generated when Java source code is compiled. It is stored in a .class file and is executed by the Java Virtual Machine (JVM).

In this chapter, you will learn about Java bytecode, how it works, and how the JVM executes bytecode on different platforms.

What is Java Bytecode?

Java bytecode is a set of instructions generated by the Java compiler from Java source code. The JVM understands and executes this bytecode, which makes Java programs platform-independent.

When Java code is compiled, the compiler generates a .class file containing bytecode. This bytecode can run on different computer architectures as long as a compatible Java Virtual Machine is available.

Java bytecode acts as an intermediate form between high-level Java source code and low-level machine instructions. The Java source code is written in a high-level programming language, compiled into bytecode, and then executed by the JVM.

How Does Java Bytecode Work?

When a Java program is compiled, the Java compiler converts the source code into bytecode and stores it in a .class file. The JVM then loads and executes this bytecode on the target platform.

The bytecode is executed by the Java Virtual Machine rather than directly by the processor. Therefore, the same .class file can be executed on different platforms that have a compatible JVM.

The JVM provides the runtime environment required to execute the bytecode and interacts with the underlying processor and operating system to perform the required operations.

The JVM uses a stack-based execution model, in which it maintains an operand stack and other runtime data structures while executing bytecode instructions.

Java Bytecode

Example of Java Bytecode

Consider the following Java program that adds two numbers.

Example

Compile and Run

Output:

15

Compile the above program using the command javap -c Main. After compilation, we get the following bytecode.

We observe that the Java code gets converted into bytecode (an unreadable form).

  • iconst_5 and bipush 10 load constants 5 and 10.
  • iadd adds the two integers.
  • getstatic and invokevirtual handle the System.out.println call.
  • new, dup, and invokespecial create and initialize a StringBuilder.