×
Create a new article
Write your page title here:
We currently have 3,189 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,189Articles
    in:

    Java Bad Magic Number

    Question

    What is a "magic number" in Java, and why does it sometimes go bad (referring to a bad magic number error when loading applets) ?

    Answer

    The class definition files (*.class) for Java applets are loaded over the network. Sometimes during the transmission of files, the connection may be aborted, or may be scrambled, causing class loading to fail. Sometimes when copying files over to a web server, they may become garbled or a disk error might occur. For this reason, special care is taken by the JVM and the class loader, to verify that classes are intact. One of the precautions is that every class definition contains at the beginning the magic number, a sequence of four bytes that identify a file as a Java class definition file.

    For those curious to know what the magic number is, it is the hexadecimal number CAFEBABE, which is used by the class loader to see if a file is really a class definition file. Please don't ask me why it spells out cafebabe - my guess it was an attempt at humor.

    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.