adam bien's blog

What are the first four bytes of the .class file? 📎

In the time of JDK 1.0/1.1 the was a long debate about different IDEs like Visual Cafe, JBuilder, Sun's Java Workshop, CodeWarrior etc. It was very similar to the today discussions about Ruby, .NET and Java :-). In every new project I was asked first about the different IDEs their advantages and drawbacks.
Once I was bored about the, not always constructive, discussions and said: "Because of the long compilation time, I write straight the byte code with UltraEdit in hex-mode".
You have just to remember the first bytes: "CAFEBABE" - everything else is easy.
No one expected such an answer - no one laughed. After two weeks the project managed came to me and asked my for a trainig about "Direct byte code programming" - he expected to save money on IDE-licenses :-). I was of course not able to give such a training and explained that...

But it is true: the first four bytes of every class-file are "CAFEBABE". If you change a letter - you will get a ClassFormatError - just try it out! It is actually waste of space - but cool :-)