Skip to content

Commit 6a8e090

Browse files
committed
Final changes in "Class File Format" before 0.2
1 parent 4b52896 commit 6a8e090

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

doc/Class Loading and structure/Class File Format.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ According to the [official JVM Specifications](https://docs.oracle.com/javase/sp
2424

2525
Looks complicated... But here is the pretty diagram, that explains everything!
2626

27-
<img src="../Diagrams/Class%20Loading%20and%20structure/Class%20File%20Structure.drawio.svg" alt="drawing" width="100%"/>
27+
<details style="background-color:#F6F6F6">
28+
<p style="background-color:#F6F6F6">
29+
<summary>Diagram</summary>
30+
<img style="background-color:#F6F6F6" src="../Diagrams/Class%20Loading%20and%20structure/Class%20File%20Structure.drawio.svg" width="100%"/>
31+
</p>
32+
</details>
2833

2934
Still complicated, of course. But at least it is much more convenient to work with, right?
3035
## Detailed fields description
@@ -34,5 +39,24 @@ Let's start describing each field, one by one:
3439
<img align="right" src="../Diagrams/Class%20Loading%20and%20structure/Magic%20Value.png" alt="drawing" width="100"/>
3540

3641
### Magic value
37-
Each `.class` value starts with special 'magic value' - a sequence of 4 bytes, that all Java class start with. It's value is 0xCAFEBABE
38-
</p>
42+
Each `.class` value starts with special 'magic value' - a sequence of 4 bytes, that all Java class start with. Its value is 0xCAFEBABE
43+
</p>
44+
45+
### Minor and major versions
46+
<img align="right" src="../Diagrams/Class%20Loading%20and%20structure/Versions.png" alt="drawing" width="200"/>
47+
Each class was compiled to be used with a specific version of Java. It was quite complex back in old versions of Java, but today everything is pretty straightforward - JVM can run classes of its version and classes with *older* versions. In other words, JVMs are **backwards compatible**
48+
49+
To store version of the Java that compiled the file, Major and Minor fields exist
50+
51+
Each major release of Java is assigned to its *major version*. For example, Java 6, that JavOC is intended to implement, has major version of `50`.
52+
53+
Minor version, however, is just a legacy field, that does not mean anything - any JVM should be able to run any minor version, if it supports the major. For example, Java 6 should be able to run `50.0`, `50.1`, `50.255` or any other.
54+
55+
Modern compilers set this field to 0
56+
57+
### Constant pool
58+
59+
<img align="right" src="../Diagrams/Class%20Loading%20and%20structure/Constant%20Pool.png" alt="drawing" width="400"/>
60+
This data structure is very complex, so there is a dedicated article about it:
61+
62+
[Constant Pool](Constant%20pool.md)
40.9 KB
Loading
23.4 KB
Loading

0 commit comments

Comments
 (0)