Overview of Class file Structure in Java?
1. Magic Number
- The first four bytes of the class file is the magic number. This is a predefined value used by JVM to identify a .class file is generated by the valid compiler or not.
- The value should be “OXCAFEBABE”.
- Note:- Whenever we are executing a java class if JVM unable to find the valid magic number then we will get runtime exception to say java.lang.classFormateError:- incompatible magic value.
2. Minor_version, major_version
- Major and minor versions represent .class file version.
- JVM will use these versions to identify which version of compiler generates the current .class file.
- Note:- lower version compiler generated .class file can be run by higher version JVM but higher version compiler generated .class files can’t be run by lower version JVMs. If we are trying to run we will get RuntimeException sayingÂ java.lang.unsupportedClassVersionError.Â
Constant pool count
- It represents no of the constant present in the constant pool
Constant pool array
- It represents info. About constant present in the constant pool.
- It provides info. About modifiers which are declared to the class.
- It represents the fully qualified name of the class.
- It represents the fully qualified name of the immediate superclass of the current class.
- It returns no of interface implemented by the current class.
- It returns interface information implemented by the current class.
- It represents no of fields present in the current class.
- It represents fields of info. Present in the current class.
- It represents no of methods present in current class.
- It provides info. All method present in current class.
- It returns no of attribute present in current class.
- It provides info. About all attributes present in current class