Format:Java class file
| Developer | Sun / Oracle (JVM Specification, chapter 4) |
|---|---|
| Versions | major 45 (1.0) ... 69 (Java 25), 70-72 (26-28 in current JDK sources) |
| Magic | CA FE BA BE |
| Extensions | .class (inside .jar, .jmod, jimage, .apk before dexing) |
| Endianness | big |
| License | spec; OpenJDK sources GPL-2.0 with Classpath exception |
| On this wiki | Facts · Code · Notes · Topics |
The compiled form of a Java (or Kotlin, Scala, Groovy) class: big-endian, starts with magic CA FE BA BE, a minor/major version pair that names the Java release that produced it (major 45 = Java 1.0/1.1, 52 = Java 8, 61 = Java 17), a constant pool of tagged entries, then access flags, class and member tables and attributes (Code, Signature, RuntimeVisibleAnnotations ...).
Identification
- The first four bytes are
CA FE BA BE. A Mach-O fat (universal) header uses the same four bytes: tell them apart by the next u32, which is a small architecture count (< 20) in a fat file andminor<<16|major(e.g. 00 00 00 34 for Java 8) in a class file. See Format:Mach-O. - Then
u2 minor_version,u2 major_version,u2 constant_pool_count. The major version names the oldest Java release that can run the file (see the table). HotSpot rejects majors below 45 and above the newest it knows; minor 65535 marks a preview-feature class (only valid for the newest major). - Everything is big-endian, unlike most formats on x86.
Version numbers
| Major | Java release | New in the class file |
|---|---|---|
| 45 | 1.0, 1.1 | original |
| 46 / 47 / 48 | 1.2 / 1.3 / 1.4 | |
| 49 | 5 | annotations, Signature (generics), EnclosingMethod |
| 50 | 6 | StackMapTable (type-checking verifier) |
| 51 | 7 | invokedynamic, MethodHandle/MethodType constants, BootstrapMethods; jsr/ret gone |
| 52 | 8 | default and static interface methods, type annotations, MethodParameters |
| 53 | 9 | modules (Module, ModulePackages, ModuleMainClass), CONSTANT_Module/Package, ACC_MODULE |
| 55 | 11 | NestHost/NestMembers, CONSTANT_Dynamic |
| 56 | 12 | preview features (minor 0 or 65535) |
| 60 | 16 | Record attribute |
| 61 | 17 | PermittedSubclasses (sealed classes) |
| 62-69 | 18-25 | no class-file changes in the OpenJDK table up to 24 |
Major = Java feature release + 44 from Java 5 (49) on. The table follows ClassFileFormatVersion in the OpenJDK sources.
OpenJDK master (commit 3104115c2a) defines ClassFileFormatVersion up to RELEASE_28 = 72 (26 = 70, 27 = 71, 28 = 72), and ClassFile.PREVIEW_MINOR_VERSION = 65535 (Fact:Java class file/enum/Class file versions 62 to 72). A class compiled with --enable-preview carries minor 65535 and only loads on the exact JVM release of its major.
Constant pool
Entries are numbered from 1 (index 0 is unused). Each starts with a u1 tag (Fact:Java class file/enum/Constant pool tags): Utf8 (1, u2 length + modified UTF-8), Integer 3, Float 4, Long 5, Double 6, Class 7, String 8, Fieldref 9, Methodref 10, InterfaceMethodref 11, NameAndType 12, MethodHandle 15, MethodType 16, Dynamic 17, InvokeDynamic 18, Module 19, Package 20. Tags 2, 13 and 14 do not exist. Long and Double occupy two slots: the next index is skipped, which trips up naive parsers.
After the constant pool
u2 access_flags (Fact:Java class file/enum/Class access flags), u2 this_class, u2 super_class (0 only for java/lang/Object), interfaces (u2 count + indexes), fields, methods (each: access flags, name index, descriptor index, attributes), class attributes. Method bodies are in the Code attribute (max_stack, max_locals, bytecode, exception table, sub-attributes such as LineNumberTable, LocalVariableTable, StackMapTable).
Descriptors use the JVM type language: (ILjava/lang/String;)V; names use / as package separator (internal names). Unverified: attribute-level layouts beyond what is listed here were not re-read in a source for this page; use the JVM Specification chapter 4.
The attributes that matter most: Code (with StackMapTable, LineNumberTable, LocalVariableTable inside), BootstrapMethods (class-level table used by invokedynamic and CONSTANT_Dynamic), Module (in module-info.class, with ModulePackages, ModuleMainClass), Record, PermittedSubclasses, NestHost/NestMembers. The JDK also writes non-JVMS attributes (ModuleHashes, ModuleTarget, ModuleResolution; javac adds CompilationID, SourceID). Full name list: Fact:Java class file/enum/Attribute names known to the JDK ClassFile API (source: java/lang/classfile/Attributes.java).
Tooling and decompilation
Because constant pool names, line numbers and local variable names usually survive, Java decompilers work well unless an obfuscator renamed symbols or encrypted strings (see Technique:Recognizing code obfuscation). Kotlin classes carry extra information in the Format:Kotlin metadata annotation. Android converts classes to Format:DEX. Classes are packaged in Format:JAR files or in the Java 9+ runtime image Format:jimage / Format:JMOD.
Decompilers
See Technique:Choosing a decompiler: Tool:CFR, Tool:Vineflower, Tool:Procyon, Tool:JADX.
Code & repositories
- https://github.com/openjdk/jdk @
3104115c2a0587895997965c9e88a1181f52ee47· license: GPL-2.0-only WITH Classpath-exception-2.0 (declared by the contributor for the files used; GitHub reports GPL-2.0 for the repository)
OpenJDK: classFileParser.cpp (class parsing), classfile_constants.h.template (tags, access flags), ClassFileFormatVersion.java (major versions), libjimage/imageFile.hpp (jimage layout), JmodFile.java, JarFile.java and Attributes.java (manifest names).
Tested on: source read, not run: Read at this commit (October 2026); files fetched, not built. · checked 2026-10-18; last activity 2026-10-18 - https://github.com/leibnitz27/cfr @
c4145259dfcd8ad3e99004e4d9ecb0aed55dcc5a· license: MIT (read from LICENSE; GitHub's API was busy)
CFR Java decompiler
Tested on: source read, not run: not run; README read · checked 2026-10-18 - https://github.com/Vineflower/vineflower @
b8273988af850e8cfb234ca08d129058502b032f· license: Apache-2.0 (read from LICENSE.md; GitHub's API was busy)
Vineflower Java decompiler (Fernflower fork)
Tested on: source read, not run: not run; README read · checked 2026-10-18 - https://github.com/mstrobel/procyon @
88a95fa93c58322393174f84543edc7a0a2ca44d· license: unknown
Procyon Java toolset with decompiler
Tested on: source read, not run: not run; README read · checked 2026-10-18
Pitfalls
- Modified UTF-8: NUL is C0 80 and supplementary characters are surrogate pairs, so strict UTF-8 decoders fail on some strings.
- A multi-release JAR can hold several versions of one class under
META-INF/versions/N/. - Obfuscators may produce invalid-but-accepted structures (junk attributes, unusual access flags); the JVM verifier is stricter than many decompilers.