What is the difference between java -version
and java -showversion
?
This blog says
The -version flag terminates the JVM immediately after printing out the above data. However, there is a similar flag -showversion which can be used to produce the same output but then proceed and execute a given Java application.
So I ran a Java program in one tab in my terminal. (I use Ubuntu) And in another tab, while the program was still running, I gave java -version
. As per the above statement given in the blog, I expected my Java program to quit, but it didnt. Also, when i ran java -showversion
, it gave exactly the same output and the program execution didnt terminate.
So what is the difference between the two ?
I use Java 8 and this was the output :
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)
Note : The blog uses Java 6. So has something changed in later versions of Java ?
Thanks in advance.
As per Java docs
-showversion
Displays version information and continues execution of the application. This option is equivalent to the -version option except that the latter instructs the JVM to exit after displaying version information.
-version
Displays version information and then exits. This option is equivalent to the -showversion option except that the latter does not instruct the JVM to exit after displaying version information.
When you run your program it creates a process. That process is independent of the second process you create when you run 'java -version' in another shell.
The first process is unaffected by anything that the second process does.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.