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
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.
- "-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.
-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).
Similar Reads
Java Comments Comments are a very important part of any programming language that enhances the readability of the codes. While compiling a code, comments are always ignored by the Java compiler. So you can also test alternative code by commenting on the other code or you can say comments can be used for debugging
5 min read
Java Cheat Sheet Java is a programming language and platform that has been widely used since its development by James Gosling in 1991. It follows the Object-oriented Programming concept and can run programs written on any OS platform. Java is a high-level, object-oriented, secure, robust, platform-independent, multi
15+ min read
Introduction to Java Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. It is platform-independent, which means we can write code once and run it anywhere using the Java Virtual Machine (JVM). Java is mostly used for building desktop applications, web applications, Android
4 min read
Java.lang.ProcessBuilder class in Java This class is used to create operating system processes. Each ProcessBuilder instance manages a collection of process attributes. The start() method creates a new Process instance with those attributes. The start() method can be invoked repeatedly from the same instance to create new subprocesses wi
8 min read
Java.lang.Runtime class in Java In Java, the Runtime class is used to interact with Every Java application that has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime() method. Methods of Java
6 min read