Check java version without java -version

Solution 1:

To show what version of Java is installed without running java -version, open the terminal and type:

apt policy openjdk-* oracle-java* 

A small part of the results of apt policy openjdk-* looks like this:

openjdk-7-jre-lib:
  Installed: (none)
  Candidate: (none)
  Version table:
openjdk-8-jdk:
  Installed: 8u162-b12-0ubuntu0.16.04.2
  Candidate: 8u162-b12-0ubuntu0.16.04.2

Search for sections that contain either openjdk-*-jre , openjdk-*-jdk or oracle-java* where the wildcard * character can be a Java version number like 6, 7, 8 or 9.

Solution 2:

You can discover the full path of the default java executable with:

readlink -f "$(which java)"

All (sane) Java packages or bundles that I know use installation path names that include the vendor name and major version number which would answer your question. E. g. on my system

$ readlink -f "$(which java)"
/usr/lib/jvm/java-9-openjdk-amd64/bin/java

tells me that the default Java installation is OpenJDK 9.

Solution 3:

You could also try:

dpkg -l | egrep -i 'jre|java|jdk'

Solution 4:

You can use this command for checking your java version:

update-alternatives --config java