Why is java -version implemented in Java?
david.holmes at oracle.com
Fri Nov 20 22:44:46 UTC 2020
On 21/11/2020 2:22 am, Thomas Stüfe wrote:
> java -version seems to be called by scripts very frequently to get the java
> version. Folks complain about the time that takes.
> I always wondered, why is this implemented in java? Which requires the
> whole jvm machinery to start up just to print the version information.
Some of that version information pertains to the JVM configuration which
is affected by the runtime flags passed to it e.g.
Java HotSpot(TM) 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)
"Server", "mixed mode" and "sharing" are all dynamic.
There is static build information built into the libjvm binary that is
accessed via -Xinternalversion:
Java HotSpot(TM) 64-Bit Server VM (14+36-1461) for linux-amd64 JRE
(14+36-1461), built on Feb 6 2020 19:11:22 by "mach5one" with gcc 8.3.0
And of course there is a lot of history here - in particular hotspot
express meant you needed to show distinct JDK and VM version information.
> VersionProps.java seems not to be very complex; that information could have
> been baked into the launcher, or the hotspot.
> Or is using 'java -version' as a simple VM test just too convenient?
That is certainly useful! :)
> Thanks, Thomas
More information about the jdk-dev