javap--How to view class files

Source: Internet
Author: User

Sometimes in order to study the principle of javac, to see how the class file content is organized, it is necessary to view the class file. There are many ways to do this, and it is recommended to use the JAVAP tool that comes with JDK.
First establish the following source code:

 Public class helloworld{    publicstaticvoid  main (string[] args) {        System.out.println ("Hello world!" );    }}

Compile the source file using the Javac compiler, and then use the JAVAP tool to view the class file with the following command
Javap-verbose HelloWorld

This is the result of running a DOS window copied out such as:

F:\>Javac helloworld.javaf:\&GT;JAVAP-verbose helloworldclassfile/f:/helloworld.classLast modified2017-12-24; Size 426bytes MD5 checksum 4efac412ef483c8a3fe7489c87d15c8c Compiled from"Helloworld.java" Public classHelloWorld minor version:0Major Version:52flags:acc_public, Acc_superconstant pool: #1 = methodref #6. #15//java/lang/object. " <init> ":() V#2 = Fieldref #16. #17//Java/lang/system.out:ljava/io/printStream; #3 = String #18//Hello world!#4 = MethodRef #19. #20//java/io/printstream.println: (ljava/lang/String;) V #5 = Class #21//HelloWorld#6 = Class #22//Java/lang/object#7 = Utf8 <init>   #8 =Utf8 () V #9 =Utf8 Code #10 =Utf8 linenumbertable #11 =Utf8 Main #Utf8 ([ljava/lang/String;) V #13 =Utf8 SourceFile #14 =Utf8 Helloworld.java #Nameandtype = #7: #8//"<init>":() V#16 = Class #23//Java/lang/system#17 = Nameandtype #24: #25//Out:ljava/io/printstream;#18 = Utf8 Hello world!  #* = Class #26//Java/io/printstream#20 = Nameandtype #27: #28//println: (ljava/lang/string;) V#21 =Utf8 HelloWorld #* = Utf8 java/lang/Object #Utf8 = java/lang/System #24 =Utf8 Out #Utf8 = ljava/io/PrintStream; #Utf8 = java/io/PrintStream #27 =Utf8 println #Utf8 = (ljava/lang/String;) v{ PublicHelloWorld (); Descriptor: () V flags:acc_public code:stack=1, Locals=1, args_size=1 0: Aload_01:invokespecial #1//Method java/lang/object. " <init>":() V 4:returnLinenumbertable:line1:0 Public Static voidMain (java.lang.string[]); Descriptor: ([Ljava/lang/String;) V flags:acc_public, acc_static code:stack=2, Locals=1, args_size=1 0:getstatic #2//Field Java/lang/system.out:ljava/io/PrintStream; 3:LDC #3//String Hello world!5:invokevirtual #4//Method Java/io/printstream.prinTLN: (ljava/lang/String;) V8:returnLinenumbertable:line3:0 Line4:8}sourcefile:"Helloworld.java"f:\>

This is the JVM specification of the class file. Combined with this contrast source can be a deep understanding of the role of Javac.

javap--How to view class 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.