Much ado about CAFEBABE
I was going through the documentation of BCEL and started wondering how come the magic-number in the Java class file 0xCAFEBABE looks so meaningful. While the original purpose for specifying the begining four bytes of Java class files is to assist in segregating prbable class files from non class files the the choice lets one ponder on whether it was just inadvertant or an easter egg. Googleing on the origin of the word lead me to some interesting discussions of the past in Java circles.
The most convincing rationale is perhaps at Doug Landauer's blog where he mentions that the term originated in 1989 from the name for an erstwhile C++ compiler CAFE (C++, A Front End) and the suffix BABE came from the cafe product manager Kim Polese's name who was “described” by people as “babe”. Another opinion says “0xcafebabe is also the constant value at the start of mach-o files. mach-o is the binary format for native Mac OS X libraries and applications. “ Few other interesting comments at artima are worth mentioning here:
.. they presumably had to pick something as their magic number to identify class files, and there's a limit to how many Java or coffee related words you can come up with using just the letters A-F 🙂
..my guess is that (a) 32-bit magic numbers are easier to handle and more likely to be unique, and (b) the Java team wanted something with the Java-coffee metaphor, and since there's no 'J' or 'V' in hexadecimal, settled for something with CAFE in it. I guess they figured “CAFE BABE” was sexier than something like “A FAB CAFE” or “CAFE FACE”, and definitely didn't like the implications of “CAFE A FAD” (or worse, “A BAD CAFE”).
..they *could* have used the number 12648430, if you choose to read the hex zeros as the letter 'O'. That gives you 0xC0FFEE, or 0x00C0FFEE to specify all 32 bits. OO COFFEE? Object Oriented, of course..