Open any Java class file in a hex editor and you will notice that it begins(the first four bytes) with the hex code CA FE BA BE. This is known as the magic number and the practice of starting the file with a specific byte sequence is quite common. This is just one of the several methods employed to verify that the file is valid or to differentiate between class and non-class files.

In the words of James Gosling, father of Java programming language:

We used to go to lunch at a place called St Michael’s Alley. According to local legend, in the deep dark past, the Grateful Dead used to perform there before they made it big. It was a pretty funky place that was definitely a Grateful Dead Kinda Place. When Jerry died, they even put up a little Buddhist-esque shrine. When we used to go there, we referred to the place as Cafe Dead.

Somewhere along the line it was noticed that this was a HEX number. I was re-vamping some file format code and needed a couple of magic numbers: one for the persistent object file, and one for classes. I used CAFEDEAD for the object file format, and in grepping for 4 character hex words that fit after “CAFE” (it seemed to be a good theme) I hit on BABE and decided to use it. At that time, it didn’t seem terribly important or destined to go anywhere but the trash-can of history. So CAFEBABE became the class file format, and CAFEDEAD was the persistent object format. But the persistent object facility went away, and along with it went the use of CAFEDEAD – it was eventually replaced by RMI.

CA FE D0 0D (“Cafe Dude”) is another magic number used by Java for the Pack200 compression format.

8B AD F0 0D (“ate bad food“) is used by Apple in iOS crash reports, and indicates that an application has been terminated by iOS because a watchdog timeout occurred.