Java class file format specfication

Java class file format spec Link: https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html

Here is an example:

-----------------------------------------------------java source file---------------------------------------------------------
public class Main {
public static void main(String[] args) {
System.out.println("hello");
}

}
-----------------------------------------------------java class file----------------------------------------------------------
0000000: cafe babe 0000 0033 001d 0a00 0600 0f09 .......3........
0000010: 0010 0011 0800 120a 0013 0014 0700 1507 ................
0000020: 0016 0100 063c 696e 6974 3e01 0003 2829 .....<init>...()
0000030: 5601 0004 436f 6465 0100 0f4c 696e 654e V...Code...LineN
0000040: 756d 6265 7254 6162 6c65 0100 046d 6169 umberTable...mai
0000050: 6e01 0016 285b 4c6a 6176 612f 6c61 6e67 n...([Ljava/lang
0000060: 2f53 7472 696e 673b 2956 0100 0a53 6f75 /String;)V...Sou
0000070: 7263 6546 696c 6501 0009 4d61 696e 2e6a rceFile...Main.j
0000080: 6176 610c 0007 0008 0700 170c 0018 0019 ava.............
0000090: 0100 0568 656c 6c6f 0700 1a0c 001b 001c ...hello........
00000a0: 0100 044d 6169 6e01 0010 6a61 7661 2f6c ...Main...java/l
00000b0: 616e 672f 4f62 6a65 6374 0100 106a 6176 ang/Object...jav
00000c0: 612f 6c61 6e67 2f53 7973 7465 6d01 0003 a/lang/System...
00000d0: 6f75 7401 0015 4c6a 6176 612f 696f 2f50 out...Ljava/io/P
00000e0: 7269 6e74 5374 7265 616d 3b01 0013 6a61 rintStream;...ja
00000f0: 7661 2f69 6f2f 5072 696e 7453 7472 6561 va/io/PrintStrea
0000100: 6d01 0007 7072 696e 746c 6e01 0015 284c m...println...(L
0000110: 6a61 7661 2f6c 616e 672f 5374 7269 6e67 java/lang/String
0000120: 3b29 5600 2100 0500 06 B: 0000 0000 00 0200 ;)V.!...........
0000130: 0100 0700 0800 0100 0900 0000 1d00 0100 ................
0000140: 0100 0000 052a b700 01b1 0000 0001 000a .....*..........
0000150: 0000 0006 0001 0000 0002 0009 000b 000c ................
0000160: 0001 0009 0000 0025 0002 0001 0000 0009 .......%........
0000170: b200 0212 03b6 0004 b100 0000 0100 0a00 ................
0000180: 0000 0a00 0200 0000 0400 0800 05 00 0100 ................
0000190: 0d00 0000 0200 0e ........

---------------------------------------------------java class file parse--------------------------------------------------------
magic number: {CA FE BA BE}
minor_version: {00 00}
major_version: {00 33}
constant_pool_count: {00 1d} (29) --> (28)
constant_pool[01]: {0a 0006 000f}--> CONSTANT_Methodref_Info
constant_pool[02]: {09 0010 0011} --> CONSTANT_Fieldref_Info
constant_pool[03]: {08 0012} --> CONSTANT_String_info
constant_pool[04]: {0a 0013 0014} --> CONSTANT_Methodref_Info
constant_pool[05]: {07 0015} --> CONSTANT_Class_info
constant_pool[06]: {07 0016} --> CONSTANT_Class_info
constant_pool[07]: {01 0006} --{3c 69 6e 69 74 3e}--"<init>" --> CONSTANT_Utf8_info
constant_pool[08]: {01 0003} --{28 29 56}--"()V"--> CONSTANT_Utf8_info
constant_pool[09]: {01 0004} --{43 6f 64 65}--"Code" --> CONSTANT_Utf8_info
constant_pool[10]: {01 000f} --{4c 69 6e 65 4e 75 6d 62 65 72 54 61 62 6c 65} --> "LineNumberTable" --> CONSTANT_Utf8_info
constant_pool[11]: {01 0004} --{6d 61 69 6e}--"main"--CONSTANT_Utf8_info
constant_pool[12]: {01 0016} --{285b4c6a6176612f 6c61 6e67 2f53 7472 696e 673b 2956} --"([Ljava/lang/String;)V" -->CONSTANT_Utf8_info
constant_pool[13]: {01 000a} --{53 6f757263 6546 696c 65} -- "SourceFile" --> CONSTANT_Utf8_info
constant_pool[14]: {01 0009} --{4d61 696e 2e6a 6176 61} -- "Main.java" --> CONSTANT_Utf8_info
constant_pool[15]: {0c 0007 0008}--> {<init>()V} -- CONSTANT_NameAndType_info
constant_pool[16]: {07 0017} -- CONSTANT_Class_info
constant_pool[17]: {0c 0018 0019} CONSTANT_NameAndType_info
constant_pool[18]: {01 0005} -- {68 656c 6c6f} "hello" --> CONSTANT_Utf8_info
constant_pool[19]: {07 001a} --> CONSTANT_Class_info
constant_pool[20]: {0c 001b 001c} --> CONSTANT_NameAndType_info
constant_pool[21]: {01 0004} --> {4d 6169 6e} -- "Main" --> CONSTANT_Utf8_info
constant_pool[22]: {01 0010} --> {6a61 7661 2f6c 616e 672f 4f62 6a65 6374} -- "java/lang/Object"-->CONSTANT_Utf8_info
constant_pool[23]: {01 0010} --> {6a 6176612f 6c61 6e67 2f53 7973 7465 6d} -- "java/lang/System"-->CONSTANT_Utf8_info
constant_pool[24]: {01 0003} --> {6f 75 74}--"out"--> CONSTANT_Utf8_info
constant_pool[25]: {01 0015} --> {4c6a 6176 612f 696f 2f507269 6e74 5374 7265 616d 3b} -- "Ljava/io/PrintStream;"-->CONSTANT_Utf8_info
constant_pool[26]: {01 0013} --> {6a617661 2f69 6f2f 5072 696e 7453 7472 65616d} -- "java/io/PrintStream" --> CONSTANT_Utf8_info
constant_pool[27]: {01 0007} --> {7072 696e 746c 6e}--"println"-->CONSTANT_Utf8_info
constant_pool[28]: {01 0015} --> {284c 6a61 7661 2f6c 616e 672f 5374 7269 6e67 3b29 56} -->"(Ljava/lang/String;)V"
access_flag: {00 21} --> {ACC_PUBLIC | ACC_SUPER}
this_class: {00 05} --> "Main"
super_class: {0006} --> "java/lang/Object"
interface_count: {00 00} --> 0
field_count: {00 00} --> 0
methods_count: {00 02: 2}
methods[1]: {0001: ACC_PUBLIC, 00 07: "<init>", 00 08: "()V", 00 01: 1, attributes[1]{00 09: Code, 00 0000 1d: 29, info:{next line}}}
Code{00 01 00 0100 0000 052a b700 01b1 0000 0001 000a 0000 0006 0001 0000 0002}
methods[2]: {0009: ACC_PUBLIC | ACC_STATIC, 000b, 00 0b: "main", 000c: ([Ljava/lang/String;)V, 0001: 1, attributes[1]{0009: Code, 0000 0025: 37}}
Code{0002 0001 0000 0009 b200 0212 03b6 0004 b100 0000 0100 0a00 0000 0a00 02 0200 0000 0400 0800 05}
attributes_count:{00 01}
attributes[1]:{00, 0d:SourceFile, 00 00 00 02: 2, 00 0e:"Main.java" }

-------------------------------------------------------------------------------------------------------------------------------

时间: 2024-08-09 14:48:46

Java class file format specfication的相关文章

关于Java的File.separator

一.File类 在Windows下的路径分隔符(\)和在Linux下的路径分隔符(/)是不一样的,当直接使用绝对路径时,跨平台会报No Such file or diretory异常. File中还有几个与separator类似的静态常量,与系统有关,在编程中应尽量使用. ps:File file = new File("G:"+ File.separator +"demo.txt"); File类是java.io包中唯一一个与文件本身操作有关的类,文件本身操作是指

Java API —— File类

1.File类的概述 文件和目录路径名的抽象表示形式,创建File对象后,仅仅是一个路径的表示,不代码具体的事物一定是存在的. 2.构造方法 · public File(String pathname):根据一个路径得到File对象 · public File(String parent,String child):根据一个目录和一个子文件/目录得到File对象 · public File(File parent,String child):根据一个父File对象和一个子文件/目录得到File对

JVMS Specification(3)-The class File Format

Subsections 3 The class File Format 3.1 The ClassFile Structure 3.2 The Internal Form of Names 3.2.1 Binary Class and Interface Names 3.2.2 Unqualified Names 3.3 Descriptors and Signatures 3.3.1 Grammar Notation 3.3.2 Field Descriptors 3.3.3 Method D

配置tomcat连接器后,启动服务报错“No Certificate file specified or invalid file format&quot;异常

1:原来的配置是 1 <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" 2 maxThreads="150" scheme="https" secure="true" 3 clientAuth="false" sslProtocol="TLS" keystoreFile=

配置CAS错误No Certificate file specified or invalid file format

配置tomcat证书 keystore文件后启动一直报错:(tomcat版本:apache-tomcat-6.0.43) tomcat配置: <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth=&qu

Validate File Format

介绍 通过Schema来校验File格式的正确与否. package shuai.study.validator; import java.io.File; import java.io.IOException; import java.net.URL; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; imp

The Portable Executable File Format from Top to Bottom(每个结构体都非常清楚)

The Portable Executable File Format from Top to Bottom Randy KathMicrosoft Developer Network Technology Group Created: June 12, 1993 Click to open or copy the files in the EXEVIEW sample application for this technical article. Click to open or copy t

Java篇:File类的基本API

1 package ares.io; 2 3 import java.io.File; 4 import java.io.IOException; 5 6 public class Main { 7 8 public static void main(String[] args) { 9 // TODO Auto-generated method stub 10 File file = new File("c:\\javas"); 11 //File file1 = new File(

Java中File类如何扫描磁盘所有文件包括子目录及子目录文件

详细情况看代码吧,我这个代码有个BUG,扫描U盘的时候可能会报空指针异常,希望大虾指点下 import java.io.File; import java.util.ArrayDeque; public class FileListDemo { public static void main(String[] args) { File f1 = new File("E:\\"); //深度搜索 getPathDFS(f1); System.out.println("=====