What is inside .class file?

A .class file represents a single compiled class and is what the Java Virtual Machine ultimately executes. Any JVM language code is compiled into .class. The specification defines the format, it is independent of platform or virtual machine implementation. The contents of a specific class can be viewed using the javap tool from the standard JDK suite. The structure of the file is detailed on Wikipedia, in documentation, and in numerous articles. The file consists of 10 sections, which can be broadly grouped into categories:

• File properties: Define the type of file with the "magic word" 0xCAFEBABE and the format version;
• Constant Pool: Contains all the method names and class names used, in a special format, along with other symbolic information. Other sections use only references to elements in the pool;
• Main class properties: Access flags, the name of the class, its superclass, and interfaces;
• Internal content: List of class fields and the bytecode of methods;
• Class attributes.

Separate files are also created for inner classes, named in the format OuterClass$InnerClass.class. If the class is anonymous, numbers starting from 1 are used instead of names.