I'm trying to get the "magic number" (the bytes that say what format the file is)... I did try to open the file myself in a hex editor. But I only get "70 75" at the start. And that's wrong. I'm doing homework and can't find the right hex code. I do not have much experience with hex editors.
Asked
Active
Viewed 819 times
-1
-
1`.java` files are simple text files. You may want to check `.class` files instead and you will find two words. – Pshemo Sep 10 '15 at 17:32
-
If you mean the `.class` file it should be `0xCAFEBABE` – Sean Bright Sep 10 '15 at 17:34
1 Answers
5
.java
files are the source files. They're plain text files and don't have any particular magic number. 70 75
are the bytes of the characters pu
- you were probably looking at a public class ...
definition.
Compiled Java .class
files start with the bytes CA FE BA BE
("Café babe"). See Java Virtual Machine Specification §4.1 – The ClassFile Structure for a description of the format.

Boann
- 48,794
- 16
- 117
- 146
-
How do I compile the file exactly? Haven't learned that stuff yet, I'm 3 weeks in on my first semester. We have only experimented with a program called BlueJ, for learning object-oriented Java code.. – minteks Sep 10 '15 at 18:15
-
-
@minteks Not at the top of the code, [on the command line](https://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html). BlueJ doubtless compiles your code too, but I'm not familiar with it so I don't know where it puts the compiled files. – Boann Sep 10 '15 at 18:48