RSS Forums RSS
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 3111 | Replies: 8 | Thread Tools  Display Modes
Reply
Join Date: Jan 2008
Posts: 4
Reputation: shankarjadhav is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
shankarjadhav shankarjadhav is offline Offline
Newbie Poster

Help To check java installation (jdk /jre) on computer

  #1  
Jan 29th, 2008
Guys,
How to check for java installation in windows, i want some code/pseudo code/algorithm..
Help me out.....
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2007
Posts: 31
Reputation: ksaxena is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
ksaxena ksaxena is offline Offline
Light Poster

Re: To check java installation (jdk /jre) on computer

  #2  
Jan 30th, 2008
use java -help on command line to find various options which you may use to get information about JRE installation on windows.
Reply With Quote  
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 129
Reputation: PoovenM is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 11
PoovenM PoovenM is offline Offline
Junior Poster

Troubleshooting Re: To check java installation (jdk /jre) on computer

  #3  
Jan 30th, 2008
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:
  1. Process java = Runtime.getRuntime().exec("cmd /C java -version");
  2. BufferedReader in = new BufferedReader(new InputStreamReader(java.getInputStream()));
  3. String line;
  4. while ((line = in.readLine()) != null)
  5. 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 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.
Last edited by PoovenM : Jan 30th, 2008 at 6:22 am. Reason: After thought
Reply With Quote  
Join Date: Jan 2008
Posts: 4
Reputation: shankarjadhav is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
shankarjadhav shankarjadhav is offline Offline
Newbie Poster

Re: To check java installation (jdk /jre) on computer

  #4  
Jan 31st, 2008
Originally Posted by PoovenM View Post
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:
  1. Process java = Runtime.getRuntime().exec("cmd /C java -version");
  2. BufferedReader in = new BufferedReader(new InputStreamReader(java.getInputStream()));
  3. String line;
  4. while ((line = in.readLine()) != null)
  5. 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 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...
Reply With Quote  
Join Date: Jan 2008
Posts: 4
Reputation: shankarjadhav is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
shankarjadhav shankarjadhav is offline Offline
Newbie Poster

Re: To check java installation (jdk /jre) on computer

  #5  
Jan 31st, 2008
Originally Posted by shankarjadhav View Post
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"
Reply With Quote  
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 129
Reputation: PoovenM is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 11
PoovenM PoovenM is offline Offline
Junior Poster

Troubleshooting Re: To check java installation (jdk /jre) on computer

  #6  
Jan 31st, 2008
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. class Test
  6. {
  7. public static void main(String args[]) throws IOException
  8. {
  9. Process java = Runtime.getRuntime().exec("cmd /C java -version");
  10. BufferedReader in = new BufferedReader(new InputStreamReader(java.getInputStream()));
  11. String line;
  12. while ((line = in.readLine()) != null)
  13. System.out.println(line);
  14. }
  15. }
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 But for me this code has no output
Reply With Quote  
Join Date: Jan 2008
Posts: 4
Reputation: shankarjadhav is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
shankarjadhav shankarjadhav is offline Offline
Newbie Poster

Re: To check java installation (jdk /jre) on computer

  #7  
Jan 31st, 2008
Originally Posted by PoovenM View Post
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. class Test
  6. {
  7. public static void main(String args[]) throws IOException
  8. {
  9. Process java = Runtime.getRuntime().exec("cmd /C java -version");
  10. BufferedReader in = new BufferedReader(new InputStreamReader(java.getInputStream()));
  11. String line;
  12. while ((line = in.readLine()) != null)
  13. System.out.println(line);
  14. }
  15. }
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 But for me this code has no output
Dude, no out put ...
Reply With Quote  
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 129
Reputation: PoovenM is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 11
PoovenM PoovenM is offline Offline
Junior Poster

Re: To check java installation (jdk /jre) on computer

  #8  
Feb 1st, 2008
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?
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,345
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 16
Solved Threads: 333
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Nearly a Senior Poster

Re: To check java installation (jdk /jre) on computer

  #9  
Feb 1st, 2008
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
  1. System.getProperty("java.version");
There is a lot of other info available as well
  1. for (java.util.Map.Entry s : System.getProperties().entrySet())
  2. 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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the Java Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 7:26 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC