In one project I found an .class extension file with this content.

cafe babe 0000 0032 005f 0700 0201 0015 6e65 742f 6d63 676c 2f4d 4347 4c4c 6175 6e63 6865 7207 0004 0100 106a 6176 612f 

and so on about 70 lines. What it is?

    3 answers 3

    This is a regular executable file of a program or library intended for execution on a Java virtual machine. Obviously, you opened it with an editor that displays the contents of non-text files in hexadecimal.

    The hexadecimal sequence 0xCAFEBABE is the signature of the header of the .class file according to the standard.

      What you find is called bytecode. This is a set of instructions that is intermediate between the source code and the machine code. In the future, it is either interpreted or compiled by the jit compiler into the machine.

      As you know, java cross-platform language. Because of this, the source code to compile into the machine immediately under all platforms is extremely difficult. Therefore, invented bytkod. It is not tied to a specific architecture, but it also parses the source code into small instructions that allow for some optimization.

      The format of this file is described in the spec .

      To disassemble bytecode, you can use the standard javap utility .

        0xcafebabe more precisely CA FE BA BE is the standard signature of the .class Java file - everyone has already said that.

        There are many legends why such a signature cafebabe is chosen - a cafe beauty , according to James Gosling (for those who are in the tank - the creator of the Java language):

        It’s a funky place to go. Dead Kinda Place. When I use it, I’ve seen a little Buddhist-esque shrine. There is a need to make it a little bit different. I’m on it and decided to use it. So you can’t have a good idea. But the persistent object facility went awa It is eventually replaced by RMI.

        In the Russian interpretation it sounds something like this (only the meaning has been translated, irrelevant details have been omitted):

        We often dropped into one restaurant (at the time when we created the Java language). According to local legend in ancient times, the local rock band Grateful Dead performed in this restaurant, which later became very famous. We’ve been between ourselves and called the restaurant "At the Dead" (Cafe Dead). One day someone noticed that CAFEDEAD is composed of HEX characters CA FE DE AD - I then applied this as a signature for the format of the Java object files. The word CAFE - it was generally “in the subject” (in American slang Java means second-rate coffee), I chose DEAD - BABE (beauty) for .class files, then nobody thought it was so important. This is how CAFEBABE signature appeared, and CAFEDEAD eventually died and was replaced by the RMI protocol.

        I heard somewhere that BABE was also chosen by no means by chance, someone from the team flirted with a girl who served them in this restaurant.