0

There's a 10 year old question, Correct way to check Java version from BASH script. Obviously some flaws of that approach were already pointed out, since we no longer have "the Java", but also OpenJDK and others.

Does Java guarantee that the output always contains the term "version", i.e. it must neither be translated, nor abbreviated ("v.") and also not omitted?

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
  • 1
    It is not stated in any specification that it *always* does ... therefore it is not guaranteed. (But *in practice* it could always be the case that ...) – Stephen C Feb 01 '22 at 06:51

1 Answers1

2

I second like Stephen C that this is no guarantee but a solid practice. However the different vendors are likely to follow one pattern in their line, and there are just a few relevant vendors anyway.

It would not be too tyring to check relevant vendor's distribution (and their names for sure show up) and implement it from there.

If you want a fully standardized solution you could also create a java class that is to be executed with the JVM in question. This java class would print the content of the system properties. These are standardized and contain specification version as well as implementation version.

Queeg
  • 7,748
  • 1
  • 16
  • 42