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!
More Posts related to Java,
- Java equals method - Tutorial
- Unbound classpath container: JRE System Library [JavaSE-1.7]
- Spring Boot: @RequestBody not applicable to method
- Java 8: Steam map with Code Examples
- Java Program: Random Number Generator
- Java java.time.Clock class code examples [Java Date Time API]
- Fix: type argument is not within bounds of type-variable T
- [Fix] java.net.MalformedURLException: unknown protocol
- Java 7 addSuppression() and getSuppression() Exception Handling
- Convert Java Array to ArrayList Code Example
- How to Word-Warp Console logs in IntelliJ
- Ways Compare Dates in Java Programming with Examples
- Remove Trailing zeros BigDecimal Java
- CRUD operations in Spring Boot + JDBC
- [Java Threads] Should we extend Thread Class or implement Runnable interface
- Json Serialization and Deserialization using Java Jackson
- Create simple struts2 project using maven commands
- How to install Java OpenJDK 11 on Alpine Linux
- Unsupported major.minor version 52.0 in java
- Error: Can not find the tag library descriptor for
- Java: Convert String to Binary
- How to run Java Unit Test cases with Apache Maven?
- Java: Testing Private Methods in JUnit using reflection API Example
- Java JDBC Connection with MySQL Driver in VS Code + Troubleshooting
- Java Join Strings with Comma Separator
More Posts:
- This Toast was not created with Toast.makeText() : Android RuntimeException - Android
- Python: How to Check If Element is or not in List - Python
- [Solution] Alpine Docker apt-get: not found - Docker
- Angular CLI ng Error: You need to specify a command before moving on. Use --help to view the available commands - HowTos
- Google Colab: How to read file from Google Drive - Google
- Release Date and iPhone Devices that will Support iOS 16 - iOS
- Install Native M1/M2 Apple Silicon based IntelliJ IDEA IDE on Mac - MacOS
- Fix NVIDIA GeForce Experience ERROR CODE 0x0003 - HowTos