Java Reference
In-Depth Information
This is information generated by javap to give us information about the class file. It's useful for keeping
a record of what you are doing, and helping you catch silly mistakes when you're working with classfile
printouts. The first line is the file system information about the file; the next line is a checksum, which is a
quick way to see if two class files are equal; the final line tells you what the origin of this classfile is. None of
this is about the class in the classfile itself, however. For that, we need to look at the following (lines 11-15):
public class Listing1
SourceFile: "Listing1.java"
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
These lines declare the class. The first line tells us that we are declaring a class (instead of an interface),
and what the name and permission level is. The next line tells us where the class comes from, which is
usually redundant with the final line of the preamble. The next two lines are the version number, which tells
you that the class was compiled with Java bytecode version 52.0 - that is a magic value which corresponds
to Java 8.0. The very last lines tell you what the access flags are for the class: ACC_PUBLIC and ACC_SUPER.
ACC_PUBLIC means that this class is publicly visible. You can read ACC_SUPER as meaning that the class
was compiled post-Java 2: it is mandatory for all contemporary class definitions, and exists purely for
backwards compatibility.
Immediately after the class declaration is the constant pool. The constant pool contains all of the
constants that are used by the class. This constant pool will include all the constants that you are used to in
Java, such as character strings and integer values. It will also include many things that you might not think of
as constants, such as class and method names. In our case, the constant pool looks like this (lines 16-35):
Constant pool:
#1 = Methodref #3.#17 // java/lang/Object."<init>":()V
#2 = Class #18 // Listing1
#3 = Class #19 // java/lang/Object
#4 = Utf8 <init>
#5 = Utf8 ()V
#6 = Utf8 Code
#7 = Utf8 LineNumberTable
#8 = Utf8 LocalVariableTable
#9 = Utf8 this
#10 = Utf8 LListing1;
#11 = Utf8 main
#12 = Utf8 ([Ljava/lang/String;)V
#13 = Utf8 args
#14 = Utf8 [Ljava/lang/String;
#15 = Utf8 SourceFile
#16 = Utf8 Listing1.java
#17 = NameAndType #4:#5 // "<init>":()V
#18 = Utf8 Listing1
#19 = Utf8 java/lang/Object
The numbers on the constant pool entries are how the rest of the bytecode will refer to each constant.
For example, if you wanted to refer to the class “Listing1,” then you would refer to constant #3. Most of the
constant pool is character strings encoded using utf8. Constants #2 and #3 represent Java class names: note
that which class name they implement is given by a string constant. So the way you read this is that constant
#2 is the class whose name is given by the string at constant #18. Helpfully, javap will provide a comment
 
Search WWH ::




Custom Search