Please support our Java advertiser: Lunarpages Java Web Hosting
![]() |
•
•
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 129
Reputation:
Rep Power: 3
Solved Threads: 11
Interesting, well on the command line one would type
It should give you the following output from which you could extract the version:
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.
java -version but you want to execute code within your program to determine the runtime version. Well I think this should work: java Syntax (Toggle Plain Text)
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);
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)
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
•
•
Join Date: Jan 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
Interesting, well on the command line one would typejava -versionbut you want to execute code within your program to determine the runtime version. Well I think this should work:
It should give you the following output from which you could extract the version:java Syntax (Toggle Plain Text)
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);
However, it doesn't workjava 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)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...
•
•
Join Date: Jan 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
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"
•
•
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 129
Reputation:
Rep Power: 3
Solved Threads: 11
java Syntax (Toggle Plain Text)
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); } }
•
•
Join Date: Jan 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
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 namesjava Syntax (Toggle Plain Text)
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); } }But for me this code has no output
... •
•
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 129
Reputation:
Rep Power: 3
Solved Threads: 11
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 There is a lot of other info available as well
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.
java Syntax (Toggle Plain Text)
System.getProperty("java.version");
java Syntax (Toggle Plain Text)
for (java.util.Map.Entry s : System.getProperties().entrySet()) System.out.println(s.getKey()+": "+s.getValue());
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.
![]() |
Other Threads in the Java Forum
- Previous Thread: help !!!
- Next Thread: Executable JAR...
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode