Table of Contents
grammar
When not using options
Example
Output
When to use options
in conclusion
Home Java javaTutorial Javap tools and examples in Java

Javap tools and examples in Java

Aug 28, 2023 am 08:09 AM
Example java programming javaptool

Javap tools and examples in Java

Thejavap tool is a useful way to retrieve information about a specific class or interface. Through its disassembly capabilities, the javap command (also known as Java disassembler) is given the role of providing comprehensive internal information to the user. From the two options -c or -verbose, each giving unique results, the user can find himself in the realm of bytecode and bytecode orchestration. If no options are used, javap runs the public, protected, and package fields and methods of the input class.

grammar

javap [option] [classname]
Copy after login

When not using options

Example

javap class_name
Copy after login

Output

C:\Users\Aashi>javap java.lang.Object 
Compiled from "Object.java"
public class java.lang.Object {
   public java.lang.Object();
   public final native java.lang.Class<?> getClass();
   public native int hashCode();
   public boolean equals(java.lang.Object);
   protected native java.lang.Object clone() throws java.lang.CloneNotSupportedException; public java.lang.String toString();
   public final native void notify();
   public final native void notifyAll();
   public final native void wait (long) throws java.lang.InterruptedException;
   public final void wait(long, int) throws java.lang.InterruptedException;
   public final void wait() throws java.lang.InterruptedException;
   protected void finalize() throws java.lang.Throwable;
   static {};
}
Copy after login

When to use options

Here are instructions for each option and how to apply it -

  • -help or --help or -? -

This is used to print help messages for the javap command.

Example

javap -help
Copy after login

Output

C:\Users\Aashi>javap -help 
Usage: javap <options> <classes> 
where possible options include: 
-help --help -?      Print this usage message
-version             Version information
-V  -verbose         Print additional information
-1                   Print line number and local variable tables
-public              Show only public classes and members
-protected           Show protected/public classes and members
-package             Show package/protected/public classes and members (default)
-p -private          Show all classes and members
-C                   Disassemble the code
-S                   Print internal type signatures
-sysinfo             Show system info (path, size, date, MD5 hash) of class being processed
-constants           Show final constants
-classpath <path>    Specify where to find user class files
-cp <path>           Specify where to find user class files
-bootclasspath <path> Override location of bootstrap class files
Copy after login
  • -Version

Used to print Java version information.

Example

javap -version
Copy after login

Output

C:\Users\Aashi>javap -version
1.8.0_151
Copy after login
  • -v or -verbose -

This is used to print additional information such as stack size, number of local variables and method parameters.

Example

javap -v class_name
Copy after login

Output

C:\Users\Aashi>javap -v java.lang.Object
Classfile jar:file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/rt.jar! /java/lang/Object.class
Last modified Sep 5, 2017; size 1497 bytes
MD5 checksum 074ebc688a81170b8740f1158648a3c7 
Compiled from "Object.java"
public class java.lang.Object 
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Integer         999999
#2 - String          #16                //@
#3 = String          #38                //nanosecond timeout value out of range
#4 = String          #42               //timeout value is negative
#5 - Utf8            ()I
#6 = Utf8            ()Ljava/lang/Object;
#7 - Utf8            ()Ljava/lang/String;
#8 = Utf8            ()V
#9 - Utf8            (I)Ljava/lang/String;
#10 - Utf8           (J)V
#11 = Utf8           (JI)V
#12 - Utf8           (Ljava/lang/Object;)Z
#13 = Utf8           (Ljava/lang/String;)V
#14 - Utf8           <clinit>
#15 = Utf8           <init>
#16 - Utf8           @
#17 - Utf8           Code
#18 = Utf8           Exceptions
#19 - Utf8           Line Number Table
#20 = Utf8           Signature
#21- Utf8            Source File
#22 = Utf8           StackMapTable
#23 Utf8             Append
#24 Utf8             Clone
#25 = Utf8           Equals
#26 Utf8             finalize
#27 = Utf8           getClass
#28 Utf8             getName
#29 - Utf8           hashCode
#30 = Utf8           java/lang/Class
#31 - Utf8           java/lang/CloneNotSupportedException
#32 = Utf8           java/lang/IllegalArgumentException
#33 - Utf8           Java/lang/Integer
#34 Utf8             java/lang/InterruptedException
Copy after login
  • -l -

This is used to print line numbers and local variable tables.

Example

javap -l class_name
Copy after login

Output

C:\Users\Aashi>javap -1 java.lang.Object 
Compiled from "Object.java” 
public class java.lang.Object { 
   public java.lang.Object();
   LineNumberTable:
   line 37: 0

   public final native java.lang.Class<?> getClass();

   public native int hashCode();

   public boolean equals(java.lang.Object);
   LineNumberTable:
   line 149: 0

   protected native java.lang.Object clone() throws java.lang.CloneNotSupportedException;

   public java.lang.String toString();
   LineNumberTable:
   line 236: 0

   public final native void notify();

   public final native void notifyAll();

   public final native void wait(long) throws Java.lang.InterruptedException;
   public final void wait(long, int) throws java.lang.InterruptedException;
   LineNumberTable:
   line 447: 0
   line 448: 6 
   line 451: 16 
   line 452: 26 
   line 456: 36 
   line 457: 40 
   line 460: 44
   line 461: 49

   public final void wait() throws java.lang.InterruptedException;
   LineNumberTable:
   line 502:0
   line 503: 5
   protected void finalize() throws java.lang.Throwable;
}
Copy after login
  • -public

This is used to print only public classes and members.

Example

javap -public class_name
Copy after login

Output

C:\Users\Aashi>javap -public java.lang.Object 
Compiled from "Object.java" 
public class java.lang.Object {
   public java.lang.Object();
   public final native java.lang.Class<?> getClass();
   public native int hashCode();
   public boolean equals(java.lang.Object);
   public java.lang.String toString();
   public final native void notify();
   public final native void notifyAll();
   public final native void wait (long) throws java.lang.InterruptedException; public final void wait (long, int) throws java.lang.InterruptedException; public final void wait() throws java.lang.InterruptedException;
}
Copy after login
  • -protected

This is used to print protected/public classes and members.

Example

javap -protected class_name
Copy after login

Output

C:\Users\Aashi>javap -protected java.lang.Object 
Compiled from "Object.java"
public class java.lang.Object {
   public java.lang.Object();
   public final native java.lang.Class<?> getClass();
   public native int hashCode();
   public boolean equals(java.lang.Object);
   protected native java.lang.Object clone() throws java.lang.CloneNotSupportedException; 
   public java.lang.String toString();
   public final native void notify();
   public final native void notifyAll();
   public final native void wait(long) throws java.lang.InterruptedException;
   public final void wait (long, int) throws java.lang.InterruptedException;
   public final void wait() throws java.lang.InterruptedException;
   protected void finalize() throws java.lang.Throwable;
}
Copy after login
  • -Bag

This is used to print package/protected/public classes and members (default).

Example

javap -package class_name
Copy after login

Output

C:\Users\Aashi>javap -package java.lang.Object 
Compiled from "Object.java"
   public class java.lang.Object {
   public java.lang.Object();
   public final native java.lang.Class<?> getClass();
   public native int hashCode();
   public boolean equals(java.lang.Object);
   protected native java.lang.Object clone() throws java.lang.CloneNotSupportedException; 
   public java.lang.String toString();
   public final native void notify();
   public final native void notifyAll();
   public final native void wait (long) throws java.lang.InterruptedException;
   public final void wait (long, int) throws java.lang.InterruptedException;
   public final void wait() throws java.lang.InterruptedException;
   protected void finalize() throws java.lang.Throwable;
   static {};
}
Copy after login
  • -c

This is used to print disassembly code.

Example

javap -c class_name
Copy after login

Output

C:\Users\Aashi>javap -c java.lang.Object 
Compiled from "Object.java"
public class java.lang.Object (public java.lang.Object();
Code:
0: return
public final native java.lang.Class<?> getClass();

public native int hashCode();

public boolean equals(java.lang.Object);
Code:
0: aload e
1: aload_1
2: 1f_acmpne   9
5:iconst_1 
6: goto        10
9: iconst_0
10: ireturn

protected native java.lang.Object clone() throws java.lang.CloneNotSupportedException;

public java.lang.String toString();
Code:
0: new             #52      //class java/lang/StringBuilder
3: dup
4: invokespecial   #74     //Method java/lang/StringBuilder."<init>": ()V
7: aload_e
8: invokevirtual   #73    // Method getClass: ()Ljava/lang/Class;
11: invokevirtual  #67    // Method java/lang/class.getName:()Ljava/lang/String;
14: invokevirtual  #76   // Method java/lang/StringBuilder.append: (Ljava/lang/String;) Ljava/lang/StringBuilder;
17: 1dc            #2    // String @
19: invokevirtual  #76   // Method java/lang/StringBuilder.append: (Ljava/lang/String;)Ljava/lang/StringBuilder;
22: aload_e
23: invokevirtual  #78   // Method hashCode: ()I
26: invokestatic   #69   // Method java/lang/Integer.toHexString: (I) Ljava/lang/String;
29: invokevirtual  #76   // Method java/lang/StringBuilder.append: (Ljava/lang/String;) Ljava/lang/StringBuilder;
32: invokevirtual  #75   // Method java/lang/StringBuilder.toString: ()Ljava/lang/String;
35: areturn
public final native void notify();
Copy after login
  • -s -

This is used to print internal type signatures.

Example

javap -s class_name
Copy after login

Output

C:\Users\Aashi>javap -s java.lang.Object 
Compiled from "Object.java" 
public class java.lang.Object { 
   public java.lang.Object(); 
   descriptor: ()V

   public final native java.lang.Class<?> getClass(); 
   descriptor: ()Ljava/lang/class;

   public native int hashCode();
   descriptor: ()I

   public boolean equals(java.lang.Object);
   descriptor: (Ljava/lang/Object;)Z

   protected native java.lang.Object clone() throws java.lang.CloneNotSupportedException; 
   descriptor:()Ljava/lang/Object;

   public java.lang.String toString();
   descriptor: ()Ljava/lang/String;

   public final native void notify();
   descriptor: ()V

   public final native void notifyAll();
   descriptor: ()V

   public final native void wait(long) throws java.lang.InterruptedException; descriptor: (J)V

   public final void wait(long, int) throws java.lang.InterruptedException; descriptor: (JI)V

   public final void wait() throws java.lang.InterruptedException; 
   descriptor: ()V
   protected void finalize() throws java.lang.Throwable;
   descriptor: ()V
   static {}; 
   descriptor: ()V
}
Copy after login
  • -sysinfo -

This is used to print system information (path, size, date, MD5 hash) of the class being processed.

Example

javap -sysinfo class_name
Copy after login

Output

C:\Users\Aashi>javap -sysinfo java.lang.Object
Classfile jar:file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/rt.jar! /java/lang/Object.class 
Last modified Sep 5, 2017; size 1497 bytes
MD5 checksum 074ebc688a81170b8740f1158648a3c7 
Compiled from "Object.java"
public class java.lang.Object {
   public java.lang.Object();
   public final native java.lang.Class<?> getClass();
   public native int hashCode();
   public boolean equals(java.lang.Object);
   protected native java.lang.Object clone() throws java.lang.CloneNotSupportedException;
   public java.lang.String toString();
   public final native void notify();
   public final native void notifyAll();
   public final native void wait (long) throws java.lang.InterruptedException;
   public final void wait (long, int) throws java.lang.InterruptedException;
   public final void wait() throws java.lang.InterruptedException;
   protected void finalize() throws java.lang.Throwable;
   static {};
}
Copy after login
  • -Constant -

This is used to print the final constants of the class.

Example

javap -constants class_name
Copy after login

Output

C:\Users\Aashi>javap -constants java.lang.Object 
Compiled from "Object.java"
public class java.lang.Object {

   public java.lang.Object();
   public final native java.lang.Class<?> getClass();
   public native int hashCode();
   public boolean equals(java.lang.Object);
   protected native java.lang.Object clone() throws java.lang.CloneNotSupportedException; 
   public java.lang.String toString();
   public final native void notify();
   public final native void notifyAll();
   public final native void wait (long) throws java.lang.InterruptedException;
   public final void wait(long, int) throws java.lang.InterruptedException;
   public final void wait() throws java.lang.InterruptedException;
   protected void finalize() throws java.lang.Throwable;
   static {}; 
}
Copy after login

in conclusion

javap tool is a multi-faceted and very powerful tool for Java coders, enabling them to diagnose and debug class documents, evaluate fields and methods, and generate clean code from the bytecode of class documents. This indispensable tool is suitable for Java developers of all skill levels, allowing them to easily expand their knowledge and troubleshoot Java programs. The javap tool is an irreplaceable possession for any aspiring programmer and it will surely help improve their programming skills quickly. Additionally, its wide range of features helps coders refine their practices, giving them a competitive edge when building Java applications.

The above is the detailed content of Javap tools and examples in Java. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Introduction to Python functions: Introduction and examples of exec function Introduction to Python functions: Introduction and examples of exec function Nov 03, 2023 pm 02:09 PM

Introduction to Python functions: Introduction and examples of exec function Introduction: In Python, exec is a built-in function that is used to execute Python code stored in a string or file. The exec function provides a way to dynamically execute code, allowing the program to generate, modify, and execute code as needed during runtime. This article will introduce how to use the exec function and give some practical code examples. How to use the exec function: The basic syntax of the exec function is as follows: exec

How to write a simple student performance report generator using Java? How to write a simple student performance report generator using Java? Nov 03, 2023 pm 02:57 PM

How to write a simple student performance report generator using Java? Student Performance Report Generator is a tool that helps teachers or educators quickly generate student performance reports. This article will introduce how to use Java to write a simple student performance report generator. First, we need to define the student object and student grade object. The student object contains basic information such as the student's name and student number, while the student score object contains information such as the student's subject scores and average grade. The following is the definition of a simple student object: public

Go language indentation specifications and examples Go language indentation specifications and examples Mar 22, 2024 pm 09:33 PM

Indentation specifications and examples of Go language Go language is a programming language developed by Google. It is known for its concise and clear syntax, in which indentation specifications play a crucial role in the readability and beauty of the code. effect. This article will introduce the indentation specifications of the Go language and explain in detail through specific code examples. Indentation specifications In the Go language, tabs are used for indentation instead of spaces. Each level of indentation is one tab, usually set to a width of 4 spaces. Such specifications unify the coding style and enable teams to work together to compile

Oracle DECODE function detailed explanation and usage examples Oracle DECODE function detailed explanation and usage examples Mar 08, 2024 pm 03:51 PM

The DECODE function in Oracle is a conditional expression that is often used to return different results based on different conditions in query statements. This article will introduce the syntax, usage and sample code of the DECODE function in detail. 1. DECODE function syntax DECODE(expr,search1,result1[,search2,result2,...,default]) expr: the expression or field to be compared. search1,

Introduction to Python functions: Usage and examples of abs function Introduction to Python functions: Usage and examples of abs function Nov 03, 2023 pm 12:05 PM

Introduction to Python functions: usage and examples of the abs function 1. Introduction to the usage of the abs function In Python, the abs function is a built-in function used to calculate the absolute value of a given value. It can accept a numeric argument and return the absolute value of that number. The basic syntax of the abs function is as follows: abs(x) where x is the numerical parameter to calculate the absolute value, which can be an integer or a floating point number. 2. Examples of abs function Below we will show the usage of abs function through some specific examples: Example 1: Calculation

How to write a simple student attendance management system using Java? How to write a simple student attendance management system using Java? Nov 02, 2023 pm 03:17 PM

How to write a simple student attendance management system using Java? With the continuous development of technology, school management systems are also constantly updated and upgraded. The student attendance management system is an important part of it. It can help the school track students' attendance and provide data analysis and reports. This article will introduce how to write a simple student attendance management system using Java. 1. Requirements Analysis Before starting to write, we need to determine the functions and requirements of the system. Basic functions include registration and management of student information, recording of student attendance data and

Introduction to Python functions: Usage and examples of isinstance function Introduction to Python functions: Usage and examples of isinstance function Nov 04, 2023 pm 03:15 PM

Introduction to Python functions: Usage and examples of the isinstance function Python is a powerful programming language that provides many built-in functions to make programming more convenient and efficient. One of the very useful built-in functions is the isinstance() function. This article will introduce the usage and examples of the isinstance function and provide specific code examples. The isinstance() function is used to determine whether an object is an instance of a specified class or type. The syntax of this function is as follows

Introduction to Python functions: functions and examples of eval function Introduction to Python functions: functions and examples of eval function Nov 04, 2023 pm 12:24 PM

Introduction to Python functions: functions and examples of the eval function In Python programming, the eval function is a very useful function. The eval function can execute a string as program code, and its function is very powerful. In this article, we will introduce the detailed functions of the eval function, as well as some usage examples. 1. Function of eval function The function of eval function is very simple. It can execute a string as Python code. This means that we can convert a string

See all articles