What is the magic number at the start of a Java class file?

The story behind the answer

The magic number at the start of a Java class file is `0xCAFEBABE`. It occupies the first four bytes of the binary file, appearing in hexadecimal as `CA FE BA BE`, and identifies the file as conforming to the Java class-file format.

The Java Virtual Machine checks this header before interpreting the rest of the file. After the magic number come the class-file version fields, followed by the constant pool, access flags, class references, interfaces, fields, methods, and attributes. The format uses big-endian values, so the header is read consistently across hardware platforms.

`CAFEBABE` is also famous for its playful origin. James Gosling recalled that Java developers ate lunch at a Palo Alto restaurant associated with the Grateful Dead, which they nicknamed “Cafe Dead.” The hexadecimal words `CAFE` and `BABE` inspired the class-file marker. An abandoned persistent-object format reportedly used `0xCAFEDEAD`, but that design disappeared while `CAFEBABE` remained.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: