What is the CLASS file format?
A .class file contains compiled source code written in the Java programming language. .class files are generated by the Java compiler from .java source files that define one or more classes. Each .class file is the result of a successful compilation and holds bytecode - a binary representation of a class that is executed by the Java Virtual Machine (JVM).
.class files are generated automatically during the compilation of .java source files. Because bytecode is platform-independent, the same .class file runs on any operating system that has a compatible JVM installed. A single .java source file can hold one or more classes, and each class gets its own .class file during the compilation process.
Compilation of .java files into .class files is performed using the javac command included with the Java Development Kit (JDK). Most Java programming environments - including IDEs such as IntelliJ IDEA and Eclipse - compile .class files automatically as programmers write code.
The Java Runtime Environment (JRE) supports execution of .class files via the java command, but does not allow compilation since the JRE does not include the javac compiler.
Every .class file begins with the 4-byte magic number 0xCAFEBABE, followed by minor and major version fields that identify the Java release used to compile it. Multiple .class files are commonly packaged together into a JAR archive for distribution and deployment.
Because the JVM is available in many versions, one must keep in mind that not all .class files are compatible with all versions of the runtime. A file compiled targeting a newer Java major version cannot be loaded by an older JVM.
Security & safety
RISK: MEDIUMA .class is compiled code: if you run it ('java MyClass') with a JVM, it executes with your user's permissions, so an unknown class - like an unknown JAR or EXE - can carry malware. Treat downloaded compiled Java as untrusted: only run classes from a source you trust. Merely decompiling or disassembling a .class (JD-GUI, javap) does not execute it and is safe. Be aware that bytecode reveals a program's logic, so anything you compile can be decompiled by others unless obfuscated.
Format details
in a nutshellPrograms that open CLASS files
Technical details
deep spec| Format type | Compiled Java bytecode (binary) |
| MIME type | application/java-vm |
| Magic bytes | 0xCAFEBABE (4 bytes at file offset 0) - present in every valid .class file |
| Version encoding | Bytes 6-7 (major version) identify the target Java release; e.g., 52 = Java 8, 61 = Java 17, 65 = Java 21 |
| Execution environment | Java Virtual Machine (JVM) via the `java` command |
| Compilation tool | `javac` compiler, included in the Java Development Kit (JDK) |
| Platform independence | Bytecode is CPU-architecture-neutral and runs on any OS with a compatible JVM |
| One class per file | Each top-level or static nested class compiles to its own separate `.class` file |
| Inner class naming | Inner and anonymous classes produce additional files with `$` in the name (e.g., `Outer$Inner.class`) |
| Constant pool | Each file embeds a structured constant pool table holding string literals, class names, and field/method descriptors |
| Instruction set | Uses the JVM bytecode instruction set (~200 opcodes), independent of any native CPU instruction set |
| Bytecode verifier | The JVM verifies `.class` file structure and type safety before execution, rejecting malformed or tampered files |
| Decompilation | Can be disassembled with `javap -c` (JDK built-in) or decompiled back to Java source with tools such as JD-GUI or CFR |
| Packaging | Typically distributed bundled inside `.jar` archives (ZIP-based containers holding multiple `.class` files and a manifest) |
| Android incompatibility | Android does not execute `.class` files directly; the `d8` tool converts them to `.dex` bytecode for the Android Runtime (ART) |
| Released | 1995-1996 (Java 1.0) |
| Open standard | Yes · royalty-free |
| Specification | docs.oracle.com |
CLASS conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about CLASS files.