What is CA FE BA BE 00 00 00 3D in Java Class Bytecode


If you read a Java .class file using a hex editor you will see that the first 4 hex codes are CA FE BA BE followed by something like 00 00 00 3D

Example:

public class MyClass {
 
 //Some Java code...

}

Let's compile the class file,

javac MyClass.java

    Using xxd command to display the .class file as HEX

    xxd MyClass.class
    
    00000000: cafe babe 0000 003d 000d 0a00 0200 0307  .......=........
    00000010: 0004 0c00 0500 0601 0010 6a61 7661 2f6c  ..........java/l
    00000020: 616e 672f 4f62 6a65 6374 0100 063c 696e  ang/Object...<in
    00000030: 6974 3e01 0003 2829 5607 0008 0100 0653  it>...()V......S
    00000040: 616d 706c 6501 0004 436f 6465 0100 0f4c  ample...Code...L
    00000050: 696e 654e 756d 6265 7254 6162 6c65 0100  ineNumberTable..
    00000060: 0a53 6f75 7263 6546 696c 6501 000b 5361  .SourceFile...Sa
    00000070: 6d70 6c65 2e6a 6176 6100 2100 0700 0200  mple.java.!.....
    00000080: 0000 0000 0100 0100 0500 0600 0100 0900  ................
    00000090: 0000 1d00 0100 0100 0000 052a b700 01b1  ...........*....
    000000a0: 0000 0001 000a 0000 0006 0001 0000 0001  ................
    000000b0: 0001 000b 0000 0002 000c                 ..........

CAFE BABE - This is called the Magic Number - A java class file is identified by these first 4 byte headers

00 00 00 3D - The next first 2 bytes (00 00) signify the Minor Version of Java, and the next two (00 3D) when converted to decimal you get 61 - which implies the Java Major version - which is Java 17, so this class was built using Java-17 version

Java Version = Decimal (Hex)
Java SE 20 = 64 (40)
Java SE 19 = 63 (3F)
Java SE 18 = 62 (3E)
Java SE 17 = 61 (3D)
Java SE 16 = 60 (3C)
Java SE 15 = 59 (3B)
Java SE 14 = 58 (3A)
Java SE 13 = 57 (39)
Java SE 12 = 56 (38)
Java SE 11 = 55 (37)
Java SE 10 = 54 (36)
Java SE 9  = 53 (35)
Java SE 8  = 52 (34)
Java SE 7  = 51 (33)
Java SE 6  = 50 (32)
Java SE 5  = 49 (31)
JDK 1.4    = 48 (30)
JDK 1.3    = 47 (2F)
JDK 1.2    = 46 (2E)
JDK 1.1    = 45 (2D)
Java Cafe Babe Bytecode

Some interesting articles:

This post was last reviewed and updated on 30th July 2023.

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright ยฉ Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap