Pages

Sunday, September 26, 2010

How To Find The Number Of JREs Running On Windows Machine?

It will only run on Windows :) because we are using Runtime class. This code is not doing anything great, just queries the registry and reflects the answer on the console. 


import java.io.*;

class NoofJRE {
static String REG_PATH = "reg query HKLMSoftwareJavaSoftJava Runtime Environment";
     public static void getJREInfo() {
try {
      Process process = Runtime.getRuntime().exec(REG_PATH);
      InputStream inputstream = process.getInputStream();
      InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
      BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
      String line;
      while ((line = bufferedreader.readLine()) != null) {
System.out.println(line);
}
}catch (Exception e) {
     System.out.println("I am in Exception");
}
}
public static void main(String s[]) {
getJREInfo();
}
}


Output

! REG.EXE VERSION 3.0
HKEY_LOCAL_MACHINESoftwareJavaSoftJava Runtime Environment CurrentVersion REG_SZ 1.6
BrowserJavaVersion REG_SZ 1.6.0_01
HKEY_LOCAL_MACHINESoftwareJavaSoftJava Runtime Environment1.6
HKEY_LOCAL_MACHINESoftwareJavaSoftJava Runtime Environment1.6.0
HKEY_LOCAL_MACHINESoftwareJavaSoftJava Runtime Environment1.6.0_01

No comments:

Post a Comment