Skip to main content

Command Palette

Search for a command to run...

Java Dev 7 - Java Bytecode (not done)

Updated
1 min read
Java Dev 7 - Java Bytecode (not done)
S

Contact: phmclong@gmail.com

Giới thiệu về Java Bytecode

Sau khi compile, file mã nguồn .java sẽ trở thành file .class. File .class này sẽ chứa các Java bytecode,

Sử dụng javac <tên_file_java>.java để compile sang .class. Ở đây tôi compile file HelloWorld.java bằng câu lệnh javac HelloWorld.java đã tạo ra file HelloWorld.class.

Xem thêm về javac: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html

Sử dụng javap [các option] <tên_file_class>.class để xem thông tin file .class. Ở đây tôi xem thông tin file HelloWorld.class bằng câu lệnh javap -c -l HelloWorld.class.

Xem thêm về javap: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javap.html

Cấu trúc của 1 file .class

Ở trong 1 file .class có chứa cấu trúc của 1 ClassFile như sau:

ClassFile {
    u4             magic;
    u2             minor_version;
    u2             major_version;
    u2             constant_pool_count;
    cp_info        constant_pool[constant_pool_count-1];
    u2             access_flags;
    u2             this_class;
    u2             super_class;
    u2             interfaces_count;
    u2             interfaces[interfaces_count];
    u2             fields_count;
    field_info     fields[fields_count];
    u2             methods_count;
    method_info    methods[methods_count];
    u2             attributes_count;
    attribute_info attributes[attributes_count];
}
35 views

More from this blog

Sheon

18 posts

  • Another blog: https://phmclong.github.io/myblog
  • Email: phmclong@gmail.com