According to the Java documentation:
-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.
Now consider Wikipedia's definition of stderr:
Standard error is another output stream typically used by programs to output error messages or diagnostics.
Most POSIX-centric tools prescribe a very careful specification for their stdout stream, so the tool's output can be piped elsewhere. Stderr is much less prescribed, and used liberally for logging and errors.
With -showversion
, Java allows the version information to be printed adjacent to a running application. However, if the version information were printed to stdout
, it would be indistinguishable from the normal application output that could accompany it, forcing you to scan for and remove that line of output yourself. Of course, with -version
instead of -showversion
, the version string very likely is the intended output, but keeping consistency is a decent end in itself.
For what it's worth, printing requested metadata to stderr vs stdout is something of an open question, so there's little in terms of "standard practice" aside from behavior documented per-application.
To work around this, just redirect stderr to stdout:
VERSION=$(java -version 2>&1)