Open In App

Java -verbose Command

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?

Steps to Run the Verbose Command

  1. Go to the File Directory Where the Java file is saved.
  2. Open the cmd from that directory.
  3. write javac file_name.java to compile the program.
  4. After Compilation writes javac -verbose file_name.java to use the verbose command.

Run the below command that is given below:

commands on cmd

Output:



Time taken to compile and load various classes

Explanation:

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).

-verbose:gc

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.

-verbose:jni

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.

For Example:

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’.

Conclusion

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).

Article Tags :