What is a javap tool?
The javap tool is used to get the information of any class or interface. The javap command (also known as the Java Disassembler) disassembles one or more class files. Its output depends on the options used (“-c” or “-verbose” for byte code and byte code along with innards info, respectively). If no options are used, javap prints out the package, protected, and public fields and methods of the classes passed to it.
javap [classname] [option]
To understand it clearly, see the below example on Command prompt which prints the details of String class
The command used is:
How to create a user defined javap tool?
To create a user defined javap tool, we will use following methods of java.lang.class
- Method getDeclaredMethods(): This method returns a Method object that reflects the specified declared method of the class or interface represented by this Class object.
- Field getDeclaredFields(): This method returns an array of Field objects reflecting all the fields declared by the class or interface represented by this Class object. This includes public, protected, default (package) access, and private fields, but excludes inherited fields.
- Constructor getDeclaredConstructors(): This method returns an array of Constructor objects reflecting all the constructors declared by the class represented by this Class object. These are public, protected, default (package) access, and private constructors.
Below programs implement user defined javap tool:
Example 1: In this example we use this program on user defined class.
Fields of class int test_class.a double test_class.d char test_class.c java.lang.String test_class.s Constructors of class test_class(int, double, char, java.lang.String) test_class() Methods of class void test_class.printData() void test_class.setData()
Example 2: In this example we use this user-defined javap tool on pre-defined Java classes.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- javap tool in Java with Examples
- How to create an unordered_map of user defined class in C++?
- How to create an unordered_set of user defined class or struct in C++?
- How to create a Java HashMap of user defined class type?
- User-defined Custom Exception in Java
- Swap two Strings without using third user defined variable in Java
- Using TreeMap to sort User-defined Objects in Java
- JSwing | Create a Magnifying tool using Java Robot
- How to Create a New User in Windows 10?
- What is JavaDoc tool and how to use it?
- Chrome Inspect Element Tool & Shortcut
- How to find out where a function is defined using PHP ?
- Why error "$ is not defined" occurred in jQuery ?
- How to detect which one of the defined font was used in a web page?
- Gradle Build Tool I Modern Open Source Build Automation
- Java Deprecated API Scanner tool (jdepscan) in Java 9 with Examples
- CSS | User Interface
- How to get user location in Android
- How to Take Input from the User in Golang?
- Program to validate a user using JSP
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.