File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes CAFEBABE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "CAFEBABE" Watch "CAFEBABE" New topic
Author

CAFEBABE

O. Subramaniam
Greenhorn

Joined: Aug 04, 2003
Posts: 17
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: 1871
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

Joined: Aug 04, 2003
Posts: 17
where this magical word will be stored, can v read this word?
Vadiraj Deshpande
Ranch Hand

Joined: Aug 16, 2000
Posts: 78
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
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
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
 
subject: CAFEBABE
 
Similar Threads
Good one..... ( System.out.println() )
Writing a file reader
Java exe observer
Identify whether the string is a actual string or hexadecimal.
how to view CAFEBABE in class file?