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" }
-------------------------------------------------------------------------------------------------------------------------------
Java class file format specfication的更多相关文章
- Java API —— File类
1.File类的概述 文件和目录路径名的抽象表示形式,创建File对象后,仅仅是一个路径的表示,不代码具体的事物一定是存在的. 2.构造方法 · public File ...
- 配置tomcat连接器后,启动服务报错“No Certificate file specified or invalid file format"异常
1:原来的配置是 <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true&quo ...
- Java ZIP File Example---refernce
In this tutorial we are going to see how to ZIP a file in Java. ZIP is an archive file format that e ...
- 配置CAS错误No Certificate file specified or invalid file format
配置tomcat证书 keystore文件后启动一直报错:(tomcat版本:apache-tomcat-6.0.43) tomcat配置: <Connector port="8443 ...
- java中File类的常用所有方法及其应用
创建:createNewFile()在指定位置创建一个空文件,成功就返回true,如果已存在就不创建,然后返回false.mkdir() 在指定位置创建一个单级文件夹.mkdirs() 在指定位置 ...
- 【java】文件操作java.io.File
package 文件操作; import java.io.File; import java.io.IOException; public class TestFile { public static ...
- Java的File.separator
一.File类 在Windows下的路径分隔符(\)和在Linux下的路径分隔符(/)是不一样的,当直接使用绝对路径时,跨平台会报No Such file or diretory异常. File中还有 ...
- Java中File常用的方法汇总
创建:createNewFile()在指定位置创建一个空文件,成功就返回true,如果已存在就不创建,然后返回false.mkdir() 在指定位置创建一个单级文件夹.mkdirs() 在指定位置创建 ...
- 关于Java的File类、字节流和字符流
一.File类: 在Windows下的路径分隔符(\)和在Linux下的路径分隔符(/)是不一样的,当直接使用绝对路径时,跨平台会报No Such file or diretory异常. File中还 ...
随机推荐
- Swift解算法——台阶问题
题目:一个台阶总共有n级,如果一次可以跳1级,也可以跳2级. 求总共有多少总跳法,并分析算法的时间复杂度. 首先对题目进行分析: 台阶一共有n级 因此当n = 1时——只有一种跳法 当 ...
- 浏览器与HTML5的相辅相成
浏览器与HTML5的相辅相成 往往一项技术的更新和发展并不是单一性的,浏览器和HTML5技术的发展亦是如此,而它们的进步也带动了整个行业的变化.浏览器与HTML5相辅相成的关系也让我们的网页能够实现更 ...
- Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
- jquery/js实现一个网页同时调用多个倒计时(最新的)
<div class="time countdown_1" data-time="1449429731"> <span class=" ...
- c++宏使用总结【转】
C/C++中宏总结C程序的源代码中可包括各种编译指令,这些指令称为预处理命令.虽然它们实际上不是C语言的一部分,但却扩展了C程序设计的环境. ANSI标准定义的C语言预处理程序包括下列命令: #de ...
- 【OPENGL】第三篇 着色器基础(一)
在这一章,我们会学习什么是着色器(Shader),什么是着色器语言(OpenGL Shading Language-GLSL),以及着色器怎么和OpenGL程序交互. 首先我们先来看看什么叫着色器. ...
- IO:File类(java.io.File)
public class File extends Object implements Serializable, Comparable<File> 构造方法: public File(S ...
- MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)【转】
MVC 默认 Request 方式为Get. actionpublic JsonResult GetPersonInfo(){var person = new{Name = "张三" ...
- window.showModalDialog的简单实践
Super.jsp - 父窗口 <%@ page language="java" import="java.util.*" pageEncoding=&q ...
- CSS 后代选择器
后代选择器(descendant selector)又称为包含选择器. 后代选择器可以选择作为某元素后代的元素. 根据上下文选择元素 我们可以定义后代选择器来创建一些规则,使这些规则在某些文档结构中起 ...