1,105,450 Community Members

To check java installation (jdk /jre) on computer

Member Avatar
shankarjadhav
Newbie Poster
4 posts since Jan 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Guys,
How to check for java installation in windows, i want some code/pseudo code/algorithm..
Help me out.....

Member Avatar
ksaxena
Light Poster
31 posts since Jul 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

use java -help on command line to find various options which you may use to get information about JRE installation on windows.

Member Avatar
PoovenM
Junior Poster
148 posts since Aug 2006
Reputation Points: 30 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 0 [?]
 
0
 

Interesting, well on the command line one would type java -version but you want to execute code within your program to determine the runtime version. Well I think this should work:

Process java = Runtime.getRuntime().exec("cmd /C java -version");
BufferedReader in = new BufferedReader(new InputStreamReader(java.getInputStream()));
String line;
while ((line = in.readLine()) != null)
    System.out.println(line);

It should give you the following output from which you could extract the version:

java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)

However, it doesn't work :icon_confused: Well at least you have something to work with... sorry mate.
Oh and the command I executed is a Windows based command that will not work on Linux.

Member Avatar
shankarjadhav
Newbie Poster
4 posts since Jan 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Interesting, well on the command line one would type java -version but you want to execute code within your program to determine the runtime version. Well I think this should work:

Process java = Runtime.getRuntime().exec("cmd /C java -version");
BufferedReader in = new BufferedReader(new InputStreamReader(java.getInputStream()));
String line;
while ((line = in.readLine()) != null)
    System.out.println(line);

It should give you the following output from which you could extract the version:

java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)

However, it doesn't work :icon_confused: Well at least you have something to work with... sorry mate.
Oh and the command I executed is a Windows based command that will not work on Linux.

Thank u dude...
Let me try...

Member Avatar
shankarjadhav
Newbie Poster
4 posts since Jan 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thank u dude...
Let me try...

I tried with the following program

 class test{
    public static void main(String args[]){

      Process java = Runtime.getRuntime().exec("cmd /C java -version");

      BufferedReader in = new BufferedReader(new InputStreamReader(java.getInputStream()));

      String line;

      while ((line = in.readLine()) != null)

      System.out.println(line);
}
}

saved as test.java, when i compiled this, it gives error "cannot read test.java"

Member Avatar
PoovenM
Junior Poster
148 posts since Aug 2006
Reputation Points: 30 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 0 [?]
 
0
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Test
{
	public static void main(String args[]) throws IOException
	{
		Process java = Runtime.getRuntime().exec("cmd /C java -version");
		BufferedReader in = new BufferedReader(new InputStreamReader(java.getInputStream()));
		String line;
		while ((line = in.readLine()) != null)
			System.out.println(line);
	}
}

Well there are a few imports that you must first have, though I've never seen such an error. What IDE are you using? On and Test is prefered over test for class file names :icon_wink: But for me this code has no output :icon_sad:

Member Avatar
shankarjadhav
Newbie Poster
4 posts since Jan 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Test
{
	public static void main(String args[]) throws IOException
	{
		Process java = Runtime.getRuntime().exec("cmd /C java -version");
		BufferedReader in = new BufferedReader(new InputStreamReader(java.getInputStream()));
		String line;
		while ((line = in.readLine()) != null)
			System.out.println(line);
	}
}

Well there are a few imports that you must first have, though I've never seen such an error. What IDE are you using? On and Test is prefered over test for class file names :icon_wink: But for me this code has no output :icon_sad:

Dude, no out put :(...

Member Avatar
PoovenM
Junior Poster
148 posts since Aug 2006
Reputation Points: 30 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 0 [?]
 
0
 

hehe yeah that's what I said! but it was suppose to work. For example, instead of cmd /C java -version try using cmd /C dir and you'd get the output from the command prompt. Does anyone have any ideas?

Member Avatar
Ezzaral
Posting Sage
7,431 posts since May 2007
Reputation Points: 2,714 [?]
Q&As Helped to Solve: 953 [?]
Skill Endorsements: 31 [?]
Moderator
Featured
 
0
 

Well, that is about the longest way around the problem if you simply want to know the java version from within a program. All you need is

System.getProperty("java.version");

There is a lot of other info available as well

for (java.util.Map.Entry s : System.getProperties().entrySet())
            System.out.println(s.getKey()+": "+s.getValue());

But all that is completely irrelevant if you are trying to check to see if java is installed on a machine. If Java isn't installed, Java code won't run. You will need a batch script or something else if you want to check for Java before running or installing an application.

The original poster does not explain the context, nor what the he/she needs to do with that information. Without a little more detail, you can't really provide a sufficient answer.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article