Thursday May 15, 2008

Weekend with registry and JDK :)

Last weekend, I was trying to find out all the JDK installed in my machine and its path(JAVA_HOME) as well. Just want to see that shall I control all JDK from one place. Most of time it happens with me, I need to check my code on several JDK and finally everything messed up. Setting JAVA_HOME, setting PATH and many more.

So, I see if I get to know the path of java and javac of all JDK versions, I can compile it and even run it from a single location. Solaris and Linux sounds similar in this case but the problem was to find it on Windows. Off course, checking some registry entries of installation and finally I wrote a small code which can tell you all the JDK version and PATH of it on your local machine. From here, you can download the jar file from  HERE (for windows)and if you want the code, please let me know. Now, need to move further and work on my problem of various JDK version.

Surprisingly joke happened with my friend, when I was given him this jar file. He told me I have only JDK 1.5.0_14 on my machine and I am not using any other because this is the most stable version of JDK(I don't know on which basis, he was making that conclusion). He ran my jar file and came up with 2 versions of JDK 1.3, 1 version of JDK1.4.2, 3 version of JDK 1.5 and 1 version of JDK 1.6. Oh God, I am wasting so much of space :)).

 

Thursday Mar 13, 2008

How many JRE on my Windows machine

Today we are doing some discussion on JRE and one of my friends Lawrence asked me a question "How to find how many JRE are installed on system by Java Code ? " Now I don't think Java have any such API which will tell how many JRE are installed on System and what are they ? But my another friend Vikram has a saying that JRE installation write information in Registry. And here I tried to write this code. It will only run on Windows :) because again I have used Runtime class. I would love to know how the same could be achieved in Unix Systems. This code is not doing anything, just do query from registry and reflectes the answer on the console. 

import java.io.\*;
class NoofJRE {
static String REG_PATH = "reg query " +
    "\\"HKLM\\\\Software\\\\JavaSoft\\\\Java 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();
    }
}

And here is my output:

E:\\Program Files\\Java\\jdk1.6.0\\bin>java NoofJRE
! REG.EXE VERSION 3.0
HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment
    CurrentVersion      REG_SZ  1.6
    BrowserJavaVersion  REG_SZ  1.6.0_01
HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.4.2_17
HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.6
HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.6.0
HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.6.0_01

Which sounds true in my case. It is clearly telling me that I have JRE 1.4.2_17, 1.6.0 and 1.6.0_01. I have old bad habit on not uninstalling JRE's :). Please let me know if there is any other way to know how many and which JRE is/are installed in my system.

And to know where it is installed is also easy by querying  JAVA_HOME in registry value.



 

About

Hi, I am Vaibhav Choudhary working in Sun. This blog is all about simple concept of Java and JavaFX.

Search

Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today