34

I am trying to install java windows application on client machine.I want to check whether requried JRE is installed on the machine or not. I want to check it by java program not by cmd command

Sandeep Sehrawat
  • 576
  • 2
  • 7
  • 18
  • 7
    Go to command prompt and simply type "java" and press Enter ;) – Nir Alfasi Sep 19 '13 at 07:06
  • 1
    this has a problem, if java is installed but not set in path, this might give you misleading results – dharam Sep 19 '13 at 18:12
  • "I want to check it by java program" So you don't want to check just that java is installed, but also the correct version? Like from a bootstrap? – killjoy Aug 13 '18 at 16:12
  • You will be able to see a screen like, [enter image description here](https://i.stack.imgur.com/fMToI.png) – Imrankhan May 29 '19 at 17:02

12 Answers12

54

if you are using windows or linux operating system then type in command prompt / terminal

java -version

If java is correctly installed then you will get something like this

java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)

Side note: After installation of Java on a windows operating system, the PATH variable is changed to add java.exe so you need to re-open cmd.exe to reload the PATH variable.

Edit:

CD to the path first...

cd C:\ProgramData\Oracle\Java\javapath
java -version
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
SpringLearner
  • 13,738
  • 20
  • 78
  • 116
  • This doesn't really answer the question - "I want to check it by java program not by cmd command". A good answer to this question is below by A4L (https://stackoverflow.com/a/18888451/100465). – Zach Alberico Aug 20 '19 at 17:52
9

You can do it programmatically by reading the java system properties

@Test
public void javaVersion() {
    System.out.println(System.getProperty("java.version"));
    System.out.println(System.getProperty("java.runtime.version"));
    System.out.println(System.getProperty("java.home"));
    System.out.println(System.getProperty("java.vendor"));
    System.out.println(System.getProperty("java.vendor.url"));
    System.out.println(System.getProperty("java.class.path"));
}

This will output somthing like

1.7.0_17
1.7.0_17-b02
C:\workspaces\Oracle\jdk1.7\jre
Oracle Corporation
http://java.oracle.com/
C:\workspaces\Misc\Miscellaneous\bin; ...

The first line shows the version number. You can parse it an see whether it fits your minimun required java version or not. You can find a description for the naming convention here and more infos here.

A4L
  • 17,353
  • 6
  • 49
  • 70
5

Open Command Prompt and type in the following command: java -version

Upon successful execution, the command will output the version of Java along with Java SE Runtime Environment’s build and Java HotSpot Client VM’s build.

enter image description here

M. Abbas
  • 6,409
  • 4
  • 33
  • 46
4

command prompt:

C:\Users\admin>java -version (Press Enter>
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
bNd
  • 7,512
  • 7
  • 39
  • 72
3

Go to this link and wait for a while to load.

http://www.java.com/en/download/testjava.jsp

You will see the below image: enter image description here

You can alternatively open command window and type java -version

dharam
  • 7,882
  • 15
  • 65
  • 93
  • 7
    This solution would only work if you have the Java browser plugin installed and enabled, which really you shouldn't. Some modern browsers don't support or won't allow the Java plugin to run. For instance Google Chrome has no support for Java plugin – HairOfTheDog Oct 19 '15 at 23:23
  • MOST modern browsers do not support the NPAPI anymore. The latest version of firefox that supports Java is Firefox-ESR 51 – killjoy Aug 13 '18 at 15:53
  • This doesn't really answer the question - "I want to check it by java program not by cmd command" – Zach Alberico Aug 20 '19 at 17:52
0

After installing Java, set the path in environmental variables and then open the command prompt and type java -version. If installed properly, it'll list the java version, jre version, etc.

You can additionally check by trying the javac command too. If it displays some data, you've your java installed with the proper path set, else it'll that javac is an invalid command.

Rahul
  • 44,383
  • 11
  • 84
  • 103
0

Type in the command window

java -version

If it gives an output everything should be fine. If you want to develop software you might want to set the PATH.

Theolodis
  • 4,977
  • 3
  • 34
  • 53
0

Check the installation directories (typically C:\Program Files (x86) or C:\Program Files) for the java folder. If it contains the JRE you have java installed.

jiggunjer
  • 1,905
  • 1
  • 19
  • 18
0

type java -version in command prompt, it will give you the installed version of java on your system.

0

1)Open the command prompt or terminal based on your OS.

2)Then type java --version in the terminal.

3) If java is installed successfullly it will show the respective version .

RBT
  • 24,161
  • 21
  • 159
  • 240
zaursh
  • 39
  • 4
0

Using Apache Commons-Lang's SystemUtils.isJavaVersionAtLeast(JavaVersion)

import org.apache.commons.lang3.JavaVersion;
import org.apache.commons.lang3.SystemUtils;

if (SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8)
    System.out.println("Java version was 8 or greater!");
killjoy
  • 3,665
  • 1
  • 19
  • 16
-1

If java not installed yet. Then program written by java cannot be run to check if java is installed or not.

wenchunl
  • 21
  • 1