Why 0xCAFEBABE?

I'm guessing I'll get asked this question a fair number of times and that there'll be confusion around why I called my blog 'cafebabe' - do I consider myself some sort of 'babe' who hangs out in cafes?!

Well, the answer is a lot more geeky than anything like that. In the Java programming language, Java classes are compiled into class files containing bytecode that's then executed by the JVM. The first four bytes in Java class files are marked by the magic hexadecimal number 0xCAFEBABE. This marker is simply an identifier for the class file format to prevent the JVM from loading files that are definitely not valid class files.

As to why 0xCAFEBABE was chosen to be the magic number for Java? This is best explained by James Gosling, creator of the 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."