了解Java字节代码 [英] Understanding Java Byte Code
问题描述
我经常遇到一个没有源代码的java类文件,我试图理解我手头的问题。
Often I am stuck with a java class file with no source and I am trying to understand the problem I have at hand.
注意反编译器很有用但不是在所有情况下都足够......
Note a decompiler is useful but not sufficient in all situation...
我有两个问题
- 什么工具可以查看java字节代码(最好从linux命令行获得)
- 熟悉java字节代码语法有哪些好的参考资料
推荐答案
不是直接查看需要熟悉Java虚拟机及其操作的Java字节码,而是可以尝试使用Java反编译实用程序。反编译器将尝试从指定的类
文件创建 java
源文件。
Rather than looking directly at the Java bytecode, which will require familiarity with the Java virtual machine and its operations, one could try to use a Java decompiling utility. A decompiler will attempt to create a java
source file from the specified class
file.
如何反编译Java类文件? 是一个相关的问题,可以提供有关如何反编译Java class
文件的信息。
The How do I "decompile" Java class files? is a related question which would be informative for finding out how to decompile Java class
files.
也就是说,可以使用 javap
命令,该命令是JDK的一部分,用于反汇编Java class
文件。 javap
的输出将是类
文件中包含的Java字节码。但请注意,字节码根本不像Java源代码。
That said, one could use the javap
command which is part of the JDK in order to disassemble Java class
files. The output of javap
will be the Java bytecode contained in the class
files. But do be warned that the bytecode does not resemble the Java source code at all.
了解Java字节码和Java虚拟机本身的明确来源是< a href =http://java.sun.com/docs/books/jvms/second_edition/html/VMSpecTOC.doc.html =nofollow noreferrer> Java虚拟机规范,第二版。特别是,第6章:Java虚拟机指令集具有所有字节码指令的索引。
The definite source for learning about the Java bytecode and the Java Virtual Machine itself would be The Java Virtual Machine Specification, Second Edition. In particular, Chapter 6: The Java Virtual Machine Instruction Set has an index of all the bytecode instructions.
这篇关于了解Java字节代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!