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
Joined: Nov 04, 2001
Posts: 1865
posted
0
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.
where this magical word will be stored, can v read this word?
Vadiraj Deshpande
Ranch Hand
Joined: Aug 16, 2000
Posts: 78
posted
0
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
Joined: Jul 16, 2001
Posts: 83
posted
0
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
Joined: Aug 16, 2000
Posts: 78
posted
0
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.