Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CAFEBABE

 
O. Subramaniam
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
couple of days before i took a technical test in java.
the first questions was "What is CAFEBABE in Java?" can anyone
explain to me what it is?
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
look for that on google and u'll find more
CAFEBABE is a magic word for a class file. as u might observe it is consisting of only hex letters. if the class file doesn't have this magic word then it is not a valid class file (well i'm myself little unsure about this on various systems Windows/Linux/Unix as magic word is used by mostly Unix based systems so i donno if Windows jvm cares about CAFEBABE or not)...
regards
maulin.
 
O. Subramaniam
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where this magical word will be stored, can v read this word?
 
Vadiraj Deshpande
Ranch Hand
Posts: 78
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by O. Subramaniam:
where this magical word will be stored, can v read this word?

Hi,
Best option is to try out yourself. I found out from the net that "CAFEBABE" are
the starting bytes of each and every java class files.
So here is the program to find out the truth.

If we run this program using the command

we see that the first bytes are indeed "CAFEBABE".
HTH
ALan
 
Roy Tock
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... under Windows, using cygwin's "od -t x2 blah.class" to show me what's in the file, I get "feca beba".
Not nearly as cool sounding as CAFEBABE.
[ August 14, 2003: Message edited by: Roy Tock ]
 
Vadiraj Deshpande
Ranch Hand
Posts: 78
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Roy Tock:
Hmmm... under Windows, using cygwin's "od -t x2 blah.class" to show me what's in the file, I get "feca beba".
Not nearly as cool sounding as CAFEBABE.
[ August 14, 2003: Message edited by: Roy Tock ]

May be because of platform encoding or with cygwin?
As you can see, if you reverse the hex words we get "CAFEBABE" again.

-A
[ August 18, 2003: Message edited by: Allan Deshpande ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic