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,
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)
Facing issues? Have Questions? Post them here! I am happy to answer!
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
- Get the current timestamp in Java
- Java Stream with Multiple Filters Example
- Java SE JDBC with Prepared Statement Parameterized Select Example
- Fix: UnsupportedClassVersionError: Unsupported major.minor version 63.0
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- 7 deadly java.lang.OutOfMemoryError in Java Programming
- How to Calculate the SHA Hash Value of a File in Java
- Java JDBC Connection with Database using SSL (https) URL
- How to Add/Subtract Days to the Current Date in Java
- Create Nested Directories using Java Code
- Spring Boot: JDBCTemplate BatchUpdate Update Query Example
- What is CA FE BA BE 00 00 00 3D in Java Class Bytecode
- Save Java Object as JSON file using Jackson Library
- Adding Custom ASCII Text Banner in Spring Boot Application
- [Fix] Java: Type argument cannot be of primitive type generics
- List of New Features in Java 11 (JEPs)
- Java: How to Add two Maps with example
- Java JDBC Transition Management using PreparedStatement Examples
- Understanding and Handling NullPointerException in Java: Tips and Tricks for Effective Debugging
- Steps of working with Stored Procedures using JDBCTemplate Spring Boot
- Java 8 java.util.Function and BiFunction Examples
- The Motivation Behind Generics in Java Programming
- Get Current Local Date and Time using Java 8 DateTime API
- Java: Convert Char to ASCII
- Deep Dive: Why avoid java.util.Date and Calendar Classes
- How to quit or exit SFTP Prompt on Terminal - Linux
- Steps to Delete or Deactivate Instagram Account - HowTos
- Ways to Convert Integer or int to Long in Java - Java
- Java StringJoiner Class With Examples - Java
- How to Cut Copy and Paste in Nano Text Editor - Linux
- Hide Bluetooth icon on Mac Menu Bar macOS Ventura 13 - MacOS
- How to show SSL Certificate details using cURL Command - cURL
- PowerShell on Mac: The term get-service is not recognized as a name of a cmdlet, function, script file, or executable program - Powershell