-1

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.

Boann
  • 48,794
  • 16
  • 117
  • 146
minteks
  • 23
  • 2

1 Answers1

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
  • Is it just to type, javac fileName.java at the top of the code? – minteks Sep 10 '15 at 18:18
  • @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