18

I have recently checked on my Java version. I ran the command java -version and I found out that I was using java version 1.7.0_09. But when I tried to check on C:\Program Files\Java\ directory, I don't seem to find the same version. I only see the following:

  • j2re1.4
  • jdk1.6.0_32
  • jdk1.7.0_06
  • jdk1.7.0_07
  • jre6
  • jre7

And so on...

My programs still run, but I'm just trying to compile everything manually, and understand how Java is being treated by the OS.

Another thing that is weird is, I tried to check on environment variable settings, and it does not say anything about jdk1.7.0_09.

Path:

  • C:\Program Files\Common Files\Microsoft Shared\Windows Live;
  • %SystemRoot%\system32;
  • %SystemRoot%;
  • %SystemRoot%\System32\Wbem;
  • %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
  • C:\Program Files\TortoiseSVN\bin;
  • C:\Program Files\Windows Live\Shared;
  • C:\eclipse\plugins\com.google.appengine.eclipse.sdkbundle_1.6.5\appengine-java-sdk-1.6.5\bin;
  • C:\Program Files\Java\jdk1.7.0_07\bin;C:\Program Files\QuickTime\QTSystem\;
  • %ANT_HOME%\bin

Just want to let you guys know that it somehow automatically became a jre.

The complete directory is C:\Users\User02\AppData\LocalLow\Sun\Java\jre1.7.0_09 and it's just got the file named lzma.dll.

But, I have another directory that says C:\Users\User02\AppData\LocalLow\Sun\Java\jdk1.7.0_07. The files inside it are:

  • jdk1.7.0_07.msi
  • sj170070.cab
  • ss170070.cab
  • st170070.cab
  • and sz170070.cab
Franz Noel
  • 1,820
  • 2
  • 23
  • 50
  • is it just me, or are there two directories of the same name in that list? – stevevls Dec 05 '12 at 23:06
  • 1
    You get whatever your path is set to if you aren't explicitly specifying it, just like any other program on your computer. **Edit:** See: http://www.computerhope.com/issues/ch000549.htm – Brian Roach Dec 05 '12 at 23:06
  • 1
    Use the search in windows and find all the instances of `java`. Your path is pointed at one of those locations, and that's the one you get if you just type `java` – Brian Roach Dec 05 '12 at 23:12
  • I got the directory and I found it on this location. `C:\Users\User02\AppData\LocalLow\Sun\Java`. I used the keyword `1.7.0_09`. – Franz Noel Dec 05 '12 at 23:19
  • 1
    Installing the JDK puts a driver `java.exe` in `%SYSTEMROOT%\System32`. You can either delete this, or make sure the JDK you want to use is on the path before the `%SYSTEMROOT%\System32` entry. – clstrfsck Dec 05 '12 at 23:21
  • @FranzNoel Those look like installation files. `AppData` is often used for temprorary storage. It looks like the installer unpacked its data into those folders and just didn't delete them all. If they don't contain a `java.exe` file, then they're not what you're looking for. – Brian Dec 06 '12 at 00:23

4 Answers4

18

It's possible to have many JRE side-by-side on a computer.

If the JRE is properly installed on Windows, informations about each version are stored in the registry. The installation process installs a special java.exe in the system PATH (%SYSTEMROOT%\System32). So you don't need to alter you PATH because this special java.exe will find the current JRE. From a command line, type java -version to display the current jre version installed.

With release 1.6, it's now possible to select a different JRE installation than the last one without any registry modification.

The JRE installation are listed in the registry in the key

HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment

Take this simple test class

public class ShowVersion {
 public static void main(String args[]) {
   System.out.println(System.getProperty("java.version"));
 }
}

On a system, with 1.6 and 1.5 installed. If you type

> java ShowVersion

It's probably the 1.6 JRE that will be used since it's the last installed.

To force the 1.5 JRE instead, use this command line.

> java -version:"1.5" ShowVersion

If the bytecode is incompatible with the given JRE then .. it won't work, of course.

ref : technote java 6

You can always give the complete path to use a specific installation. Launching the JVM this way does not use the registry setting at all.

>"C:\Program Files\Java\j2re1.4.1_02\bin\java" -version
java version "1.4.1_02"
sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
RealHowTo
  • 34,977
  • 11
  • 70
  • 85
5

Adding the following will resolve your issue:

set JAVA_HOME="your jdk path"
set PATH=%JAVA_HOME%\bin;%PATH%.

Additionally if it does not work that means you have set the PATH for multiple java versions, include only the latest one and remove all from PATH variables.

Satan Pandeya
  • 3,747
  • 4
  • 27
  • 53
Shashidhar
  • 61
  • 1
  • 2
2

In answer to the "actual" question:

Another thing that is weird is, I tried to check on environment variable settings, and it does not say anything about jdk1.7.0_09.

What happened here is that you installed jdk1.7.0_07 and then you auto-upgraded it. When that happens , it still uses the old folder name that you originally installed to.

After I install Java , I usually make a copy of the JDK directory and name it with the version number. Then, I can directly call a certain java like so:

@echo off
:: testjava.bat
set JAVA_HOME=C:\JDK1.x.xx
set PATH=%JAVA_HOME%\bin;%PATH%;.
java -version
pause

So, my recommendation is to set your JAVA_HOME system variable and PATH variable like I show above. This would override everything on your system so that your JDK of your choice is the default over the JRE.

djangofan
  • 28,471
  • 61
  • 196
  • 289
  • Are you sure auto-updating is available for the JDK? ([Relevant question.](http://stackoverflow.com/questions/1829986/is-there-a-way-to-update-the-jdk-without-manually-downloading-the-new-version)) I thought only the JRE had auto-updating. – Brian Dec 05 '12 at 23:37
  • Thats true. In that case, that explains why java JRE installed to Program Files in a directory named after the major version of java and doesn't include the minor versions or build number. That would be because it auto-upgrades. So, in this case, his system is pointing to the updated JRE7 as the default java and the version of that java had auto-upgraded to minor revision 09. – djangofan Dec 05 '12 at 23:53
2

That AppData path in your comment isn't on your path (supposedly, anyway), so that's probably not what it's using. Unfortunately, there isn't a which command on Windows either.

If you edit your path and move the C:\Program Files\Java\bin directory to the very beginning of the list and it still prints 1.7.0_09, then somehow you have JDK7u9 in your JDK7u7 folder. If not, browse to all the other directories on your path and open them 1-by-1 until you find the appropriate java file. Fortunately for you, your path is much shorter than mine.

Note that when doing:

> java -version

It may also look for java.bat and other non-exe extensions, so keep an eye out for this while you're searching your path. Try running:

> java.exe -version

That way you know you're looking for an exe file.

One last thing you can try:

> "C:\Program Files\Java\jdk1.7.0_07\bin\java" -version

If this returns 1.7.0_09, then something happened that updated your JDK in-place, which isn't supposed to happen, AFAIK (but I could be wrong).

Brian
  • 17,079
  • 6
  • 43
  • 66