A probe into bytecode files

Source: Internet
Author: User

The Java source file (. java) written by the programmer is compiled to generate a bytecode file (. Class).

Java programs need to be run by the JVM (Java Virtual machine, Java machines) support. The JVM is a software that is installed in the operating system and provides a running environment for bytecode files.

Java Official provides JVM software for different platforms (such as JVM for Linux, JVM for Windows, etc.), as long as the standard bytecode files can be run on different JVMs and run the same effect. This is where programming is used everywhere (and a clear advantage of Java programs).

Other languages, such as the C language source files, directly generate executable files that can be run directly in the operating system.


For Java source files compiled generated bytecode files are recognized and run by only 0 and 1 of the computer, very curious, after several studies, finally to the code of the bytecode has a preliminary understanding.


In the following example, the first program of each programmer HelloWorld (plus a simple variable) is tried to parse the next byte-code file.


Source code for HelloWorld:

Package Day02;public class HelloWorld {public static void main (string[] args) {String str = "Hello world!"; System.out.println (str);}}


The compiler is using JDK 1.8:

Open the bytecode file (I use EditPlus to open, the middle will let the selection encoding, using the "Hex viewer" can be shown)

Tip failed to open document, but click OK to open the bytecode file correctly.

Bytecode opens as.

The part of the red box is the content of Helloworld.class, the other part is EditPlus auto-generated: The left part of the red box represents the line number, the right part is the character of the binary code (UTF-8 encoding)

To understand how the Helloworld.java and helloworld.class files correspond, we must understand the bytecode specification of the JVM. The structure of bytecode files is very compact, without any redundant information, not even delimiters, it uses a fixed file structure and data type to achieve the segmentation of the content. The bytecode includes two data types: unsigned number and table. The unsigned number also includes U1,u2,u4,u8 four, representing 1 bytes, 2 bytes, 4 bytes, and 8 bytes, respectively. The table structure is composed of unsigned data.


Cond


A probe into bytecode files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.