The Java source files (.java files) get compiled into .class files. Since Java is a platform-independent language, it compiles its sources into bytecode, which it stores in a .class file. If the source code has more than one class, each class is compiled into a separate .class file. These .class files can be loaded by any Java Virtual Machine.
Since JVMs are available for many platforms, the .class file compiled in one platform will execute in a JVM of another platform. This makes Java platform-independent.
Class files are identified by the following 4 byte header (hex): CA FE BA BE.
As of 2006, the modification of the classfileformat is being considered under Java Specification Request (JSR) 202.
I was re-vamping some fileformat code and needed a couple of magic numbers: one for the persistent object file, and one for classes.
I used CAFEDEAD for the object fileformat, and in grepping for 4 character hex words that fit after "CAFE" (it seemed to be a good theme) I hit on BABE and decided to use it.