You can do this with the –version parameter as shown in the examples below, which came from three different machines:
Java > java -version
Java > java -version
java version "1.5.0_25"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_25-b03)
Java HotSpot(TM) Server VM (build 1.5.0_25-b03, mixed mode)
Java >
C:\Users\J0294094>java -version
java version "1.6.0_38"
Java(TM) SE Runtime Environment (build 1.6.0_38-b05)
Java HotSpot(TM) 64-Bit Server VM (build 20.13-b02, mixed mode)
C:\Users\J0294094>
andrew@UBUNTU:~/Java$ java -version
java version "1.6.0_27"
OpenJDK Runtime Environment (IcedTea6 1.12.3) (6b27-1.12.3-0ubuntu1~12.04.1)
OpenJDK Client VM (build 20.0-b12, mixed mode, sharing)
andrew@UBUNTU:~/Java$
java version "1.6.0_27"
OpenJDK Runtime Environment (IcedTea6 1.12.3) (6b27-1.12.3-0ubuntu1~12.04.1)
OpenJDK Client VM (build 20.0-b12, mixed mode, sharing)
andrew@UBUNTU:~/Java$