Java Development Kit (JDK) is the Software Development Kit that contains all the tools and files required for compiling, developing, and running Java programs. JDK has the Java Compiler Program known as Javac which compiles the Java source files to the bytecode class files i.e. ( .java to .class). JDK also has an essential component known as JVM.
Java Virtual Machine (JVM) is the software component that provides a runtime environment to execute Java programs. It is a very vital component of JDK because it is responsible for executing the Java Bytecode. For gaining the inner working and execution of JVM during the Runtime we use the command known as -verbose.
What is -Verbose Command?
- Verbose Command in Javac is used to find the runtime of the current Java file to show what the compiler is doing at the runtime.
- It loads all the classes and the source files which are used in compile time of the Java file.
- The -verbose command is effective to check or ensure that all the classes have been loaded successfully or not. Because many times some classes do not load due to some incorrectness of the program file and some compiler issues or may be due to the ClassLoader which is present in the Java Runtime Environment.
- Basically, it is used for debugging purposes.
Steps to Run the Verbose Command
- Go to the File Directory Where the Java file is saved.
- Open the cmd from that directory.
- write javac file_name.java to compile the program.
- After Compilation writes javac -verbose file_name.java to use the verbose command.
Run the below command that is given below:
commands on cmd
Time taken to compile and load various classes
The above Output shows the mechanism of the verbose command for obtaining the working and loading of different classes. In the given Output, the modules are loading one by one with their respective classes which after all combine the time for loading the Output i.e 237ms which varies for each program and system to system.
Some Other Functions of Java Verbose
The -verbose command is also used for gaining information about garbage collection and Java Native Interface (JNI).
For proceeding with the information about garbage collection, the following command is applied
java -verbose:gc <class name>
In this command, <class name> represents the name of the class that has to be run. The -verbose:gc flag communicates with JVM to enable the logging of the event in garbage collection. After running this command, the console shows the information about the process of garbage collection. The flags decide the output in the case of the garbage collector.
There is a collection of flags in verbose from which a few of them are given below.
- “-XX:+PrintCommandLineFlags”: To start the JVM, the command line flags that were used are printed by this flag.
- “-XX:+PrintCompilation “: The method that is compiled by the JIT (Just-In-Time) compiler is printed by this flag.
- “-XX:+PrintGC”: All the activities made by the garbage collector are printed by this flag.
- “-XX:+PrintGCDetails”: It prints detailed information about the garbage collection events and also about the memory area that is collected.
- “-XX:+PrintHeapAtGC “: After each garbage collector event, it gives the information about the heap.
It is generally used to diagnose JNI(Java Native Interface) call error messages. It also enables the Logging of JNI. When a JNI or native method is resolved. It also prints a trace message when a native method is registered using the JNI RegisterNative function. The -verbose:jni option is very useful for the diagnosis of issues related to the applications that use the native libraries. The verbose will prints a mark every time when a native method. It provides and tells information about the use of native methods and Java Native Interface activities.
java -verbose:jni <Class Name>
Output: redirects to “jni.log” file .
The above command enables the verbose output for Java Native Interface (JNI) calling. This command line code redirects to a file namely ‘jni.log’.
Overall, the -Verbose in Java plays a vital role in executing and loading various functions of Java classes. The verbose option is very useful during the development and testing of various software and programs. JVM provides extra information about the application’s execution to the console with the use of the verbose option. This information can be helpful in diagnosing issues, identifying and enhancing performance, and understanding the inner workings of the JVM(Java Virtual Machine).
Share your thoughts in the comments
Please Login to comment...