Sponsored Link •
|
Advertisement
|
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.
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
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
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
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.)
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
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
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. --
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 ...
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
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.
(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).
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
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.
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! ;)
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
Sponsored Links
|