The dudes and babes mentioned in the title are referring to the magic numbers used in the Java Class File Format and the Java pack200 compression format. This article looks at the hex dumps of class file to look at the magic number as well as the class file major revision number.
While defining a file format, it is a common practice to have the file start with a specific byte sequence. This allows the programs or Operating System to recognize that file type. Think of it as a signature(initials) if you will. The magic number concept extends to various other things like IP addresses or message formats used in protocols.
The following list shows some interesting magic numbers. If you interpret these bytes in hexadecimal base you will notice some words and messages. Obviously, by looking at the following examples, you can tell that the software engineers who came up with these, have a great sense of humor.
- 0x8BADF00D ("ate bad food") is used by Apple in iOS crash reports, when an application takes too long to launch, terminate, or respond to system events.
- 0xFEE1DEAD ("feel dead") is used as a magic number in the Linux reboot system call.
- 0xE011CFD0 is magic number for Microsoft Office files. In little endian this reads D0CF11E0, "docfile0".
- C15C:0D06:F00D (cisco dog food) used in the IPv6 address of www.cisco.com on World IPv6 Day.
The first four bytes of a Java .class file when interpreted as hexadecimal numbers are 0xCAFE 0xBABE. If you observe carefully these spell out the words Cafe Babe. As explained earlier, Java class file uses the byte sequence 0xCAFE 0x BABE as the magic number. Look at the following screenshot showing the hex-dump of a .class file. The black rectangle outlines the magic number.
Byte number 6 and 7 (first byte is being referred as byte 0) show the Java Class Major Revision Number. This should be interpreted according to the following lookup table. In the above screen shot it is 0x32 which corresponds to J2SE 6.0. This has been shown with a green border.
J2SE 7 = 51 (0x33 hex),
J2SE 6.0 = 50 (0x32 hex),
J2SE 5.0 = 49 (0x31 hex),
JDK 1.4 = 48 (0x30 hex),
JDK 1.3 = 47 (0x2F hex),
JDK 1.2 = 46 (0x2E hex),
JDK 1.1 = 45 (0x2D hex).
The pack200 jar compression utility from Sun/Oracle uses 0xCAFE 0xD00D as the magic number. I highlighted the magic number in the following hexdump of a pack200 compressed file.