-Java basic structure of the class file Class notes

Independence

Slogan just born at the beginning of Java: "write once (write once, run anywhere)".

Platform independence - the key is to support this statement: a wide variety of virtual machines running on different platforms. Program storage format virtual machine platforms and a variety of different platforms are unified use - byte code (ByteCode) constitute the cornerstone of platform-independent.

Language-independent - there is another virtual machine independence, at the beginning of Java development, designers have considered and implemented so that the possibility of other languages running on the Java virtual machine. Therefore, Java specification document is split into the Java Language Specification and Java Virtual Machine Specification . The foundation is the implementation language-independent virtual machine storage and bytecode format. Java virtual machine and does not in any language including Java bindings associated only with "Class Files" this particular binary file format . That is as long as you can in this language is compiled into bytecode Class files are stored, then the virtual machine can run it, the virtual machine is not a source of concern CLass what language.

 

Class structure of the class file

Class file is a binary stream to a set of 8 bytes of base units, the exact order of each data item are arranged in a compact Class file not added any intermediate separator.

Class file structure uses a pseudo-C language data structure to store similar, only two of such dummy structure data types:

Unsigned: unsigned belong to the basic data types to u1, u2, u4, u8 to represent one byte, 2 bytes, 4 bytes, 8 bytes. Unsigned number can be used to describe figures, reference index, the value of the number of values or string configuration according to UTF-8.

Table: TABLE unsigned number is a plurality of tables or other types of data items as data conforming to the configuration, "_info" end of the table to all customary. Table used to describe the data have a hierarchical relationship composite structure, the entire Class file is essentially a table.

无论是无符号数还是表,当同一类型但数量不定时,经常会使用一个前置的容量计数器加若干个连续的数据项的形式,这时称这一系列连续的某一类型的数据为某一类型的集合。

Class文件不像XML等描述语言,由于它没有任何分隔符号,所以在上表中的数据项,无论是顺序还是数量,甚至数据存储的字节序这样的细节,都是被严格限定的。哪个字节代表什么含义,长度是多少,先后向顺序,都不允许改变。

使用十六进制编辑器WinHex打开一个被编译后的.class文件就是如下所示:

 

Guess you like

Origin blog.csdn.net/helianus/article/details/89311934