Why CAFEBABE?

A discussion thread from comp.lang.java




In May of 1996, as I was working on my second JavaWorld article, "The Class File Lifestyle," I became curious about the Java class file's magic number, 0xCAFEBABE . The first four bytes of every Java class file are specified to be 0xCAFEBABE , a magic number that can help tools quickly differentiate likely class files from non class files. Wondering whether any deep meaning lurked behind this value, I posted the following question to the comp.lang.java newsgroup.

Subject: Why CAFEBABE?

Date: Mon, 20 May 1996

From: Bill Venners <bv@artima.com>

To: comp.lang.java

The first 4 bytes of every Java class file has the magic value 0xCAFEBABE. I am curious. Does anyone know how this value was chosen? Does anyone who doesn't know want to venture a guess?

Thanks in advance.

bv

This rest of this page shows all the responses my question triggered.

Subject: Re: Why CAFEBABE?

Date: Mon, 20 May 1996 19:53:33 -0500

From: Matthew Travis <mtravis@uiuc.edu>

To: comp.lang.java

I have heard why before, but the answer seems to have long since been deleted from my e-mail archives. I, too, would like to know why. why?

matt

Subject: Re: Why CAFEBABE?

Date: Wed, 22 May 1996 12:16:27 +0100

From: Rolf Howarth <rolf@parallax.co.uk>

To: comp.lang.java

Bill Venners wrote:

The first 4 bytes of every Java class file has the magic value 0xCAFEBABE. I am curious. Does anyone know how this value was chosen? Does anyone who doesn't know want to venture a guess?

Well, 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 :-)

-Rolf

Subject: Re: Why CAFEBABE?

Date: Tue, 21 May 1996 12:31:36 -0600

From: Alastair Mayer <al@bix.com>

To: comp.lang.java

Matthew Travis wrote:

I have heard why before, but the answer seems to have long since been deleted from my e-mail archives. I, too, would like to know why. why? matt

Well, the file has to start with *some* magic number (or string) to make it easy to recognize as a valid class file and not something else.

As to why the magic number is 3405691582 (0xCAFEBABE), well 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").

:-)

-- Alastair

(BTW, of course they're far from the first to use hex digits to spell out meaningful words in their magic numbers. Twenty-something years ago the Burroughs B6700 initialized its "uninitialized" memory of 48-bit words to 0xBADBADBADBAD.)

Subject: Re: Why CAFEBABE?

Date: Wed, 22 May 1996 11:04:39 -0600

From: Alastair Mayer <al@bix.com>

To: comp.lang.java

Alastair Mayer wrote:

[snip] 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"). :-)

Don't know why I missed this before, but 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... :-)

-- Alastair

Subject: Re: Why CAFEBABE?

Date: Wed, 22 May 1996 19:43:46 GMT

From: David N. Smith <dnsmith@watson.ibm.com>

To: comp.lang.java



Alastair Mayer wrote:

Well, the file has to start with *some* magic number (or string)to make it easy to recognize as a valid class file and not something else. As to why the magic number is 3405691582 (0xCAFEBABE), well 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"). :-) -- Alastair (BTW, of course they're far from the first to use hex digits to spell out meaningful words in their magic numbers. Twenty-something years ago the Burroughs B6700 initialized its "uninitialized" memory of 48-bit words to 0xBADBADBADBAD.)

Back when I was a mere child, I was helping a numerical analyst debug a program. The S/360 core dump (anyone remember hex matrixes!) finally yielded up the culpret: a very out-of-range floating point value.

The first three digits were 0xBAD.

I had a hell of a time convincing that guy that it was purely a coincidence!

Dave

Subject: Re: Why CAFEBABE?

Date: Sun, 26 May 1996 02:40:10 -0700

From: Paul Snively <chewy@chelsea.ios.com>

To: comp.lang.java

David N. Smith wrote:

Back when I was a mere child, I was helping a numerical analyst debug a program. The S/360 core dump (anyone remember hex matrixes!) finally yielded up the culpret: a very out-of-range floating point value. The first three digits were 0xBAD. I had a hell of a time convincing that guy that it was purely a coincidence!

A canonical (that is, referred to explicitly in "The New Hacker's Dictionary") "bogus value" to stick in places that need an easily-identifiable bogus value is 0xDEADBEEF.

On the Macintosh, which lacks protected memory, a popular thing to do is to stick some magic number into location 0 so that dereferencing a null pointer or handle will crash immediately. Long ago, a friend used the ASCII value of 'NIL!' for the purpose, but time and some real thought about what a good value on the Macintosh really was eventually led to 0x50FFC001, which is a flawless Mac crasher value (for at least three reasons that are left as an exercise to the reader) but unfortunately isn't a cool legible value. --

Subject: Re: Why CAFEBABE?

Date: 23 May 1996 04:54:44 GMT

From: Vivian Man Cheng <vmcheng@unixg.ubc.ca>

To: comp.lang.java

I originally saw 0xCAFEBABE as a magic number used by NeXTSTEP. NX used "fat binaries", which were basically binaries for different platforms stuck together in one executable file. If you were running on NX Intel, it would run the Intel binary; if on HP, it would run the HP binary. 0xCAFEBABE was the magic number to distinguish either the Intel or the Motorola binaries ( can't remember which ).

Seems that Sun carried it over ...

Subject: Re: Why CAFEBABE?

Date: Sat, 25 May 1996 02:15:20 GMT

From: David Harvey-George <david@threewiz.demon.co.uk>

To: comp.lang.java

Vivian Man Cheng wrote:

I originally saw 0xCAFEBABE as a magic number used by NeXTSTEP.

Strange but true... 0xfeedface is for moto and 0xcafebabe for intel. What about Sun and HP though?

Do you think it's copyrighted or trademarked to NeXT? :-)

David

Subject: Re: Why CAFEBABE?

Date: Wed May 22 09:17:37 1996

From: James Lynn <jlynn@jetform.com>



Since the word babe is pretty synonmous with chick, I doubt you'll find any _deep_ meaning here. When I hear "CafeBabe" I think of a typical Coffee Grrl: nose peirced, minimum one tatoo, hair dyed black, hate the world the government and parents, and is rather attractive in a necro sort of way.

But that's what I get from it. It could be a tribute to the waitress who served Sun's Java team at their favorite bean hole. Or, maybe it one of the few things they could spell with A-F, and CAFEBEEF or DEADCAFE wasn't nearly as nice sounding to them as CAFEBABE.

Who knows. You could write them.

Subject: Re: Why CAFEBABE?

Date: Fri, 24 May 1996 16:35:55 GMT

From: Lee Crocker <lee@Unify.com>

To: comp.lang.java

(BTW, of course they're far from the first to use hex digits to spell out meaningful words in their magic numbers. Twenty-something years ago the Burroughs B6700 initialized its "uninitialized" memory of 48-bit words to 0xBADBADBADBAD.)

And don't forget the old IBM machines that used 0xDEADBEEF for the same purpose. Using uninitialized memory is still called a "dead beef error" in some circles (at least among programmers old enough to remember that).

Subject: Re: Why CAFEBABE?

Date: Tue, 28 May 96 16:20:57 GMT

From: William Halchin <halchin@bostech.com>

To: comp.lang.java

Lee Crocker wrote:

(BTW, of course they're far from the first to use hex digits to spell out meaningful words in their magic numbers. Twenty-something years ago the Burroughs B6700 initialized its "uninitialized" memory of 48-bit words to 0xBADBADBADBAD.) And don't forget the old IBM machines that used 0xDEADBEEF for the same purpose. Using uninitialized memory is still called a "dead beef error" in some circles (at least among programmers old enough to remember that).

AIX on RS6000 still uses 0xdeadbeaf to represent unitialized storage.

Vasili N. Galchin

This reply is the actual answer to the question, supplied by Patrick Naughton, one of the original members of the team that eventually produced Java. I quoted Patrick in my JavaWorld article.

Subject: Re: Why CAFEBABE?

Date: Sun, 26 May 1996 22:12:58 -0700

From: Patrick Naughton <naughton@starwave.com>

To: comp.lang.java

Bill Venners wrote:

The first 4 bytes of every Java class file has the magic value 0xCAFEBABE. I am curious. Does anyone know how this value was chosen? Does anyone who doesn't know want to venture a guess?

Strangely enough the magic number for .class files was chosen long before the name Java was ever uttered in reference to this language. We were looking for something fun, unique and easy to remember. 0xcafebabe was better than the second runner-up, 0xdeadbabe. :-)

It is only a coincidence that the oblique reference to the cute barristas at Peet's Coffee was foreshadowing for the name Java.

Subject: Re: Why CAFEBABE?

From: Simon Bennett <simonb@wormald.com.au>

To: comp.lang.java

Patrick Naughton wrote:

Strangely enough the magic number for .class files was chosen long before the name Java was ever uttered in reference to this language. We were looking for something fun, unique and easy to remember. 0xcafebabe was better than the second runner-up, 0xdeadbabe. :-)

0xdeadbabe is used at the start of all IRIX arena files! So good thing you didn't use it! ;)

Subject: Re: Why CAFEBABE?

Date: Sun, 09 Jun 1996 19:25:32 GMT

From: Bob Pasker <rbp@well.com>

To: comp.lang.java



Simon Bennett wrote:

0xdeadbabe is used at the start of all IRIX arena files! So good thing you didn't use it! ;)

and a debugging solaris kernel puts 0xCAFEFEED into all kmemfree() blocks. --b