I've heard that Java classes have something called a magic number in their headers that identifies them, and it says something like 0xCAFEBABE
.
Could someone explain to me how I can check such information?
I've heard that Java classes have something called a magic number in their headers that identifies them, and it says something like 0xCAFEBABE
.
Could someone explain to me how I can check such information?
Well, regarding your question, when you open a .class file with a hex editor, you can see "cafe babe" if it contains this magic number.
In fact here I found an explanation of James Gosling himself
The first 4 bytes are "the magic number",
to identify a valid class file.
The next 2 bytes minor version number identify the version of the .class being used.
The next 2 bytes major version number
The magic number is present at the beginning of all .class files as a result of the source code compilation process. With a simple text editor like Notepad on Windows it is possible to observe this, or with any hexadecimal text editor, like Notepad++, also opening the files with a common editor present in GNU/Linux operating systems like gedit, nano or vi.