Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to run a compiled java class and getting errors but when I checked my java environments it points to different version.

Javac –version gives me 1.8.0

And

Java –version gives me 1.6.2

The Java_home and path is pointing to the 1.8 version.

Please help.

share|improve this question
    
which operating system is it? –  Sergey Pauk 1 hour ago
1  
Are you using an IDE like Eclipse or something? –  Dima Maligin 1 hour ago
    
When set the path set it like set PATH=%JAVA_HOME%\bin;%PATH% .. It will put your JAVA bin folder in first before others. –  Naveen Ramawat 48 mins ago

4 Answers 4

up vote 2 down vote accepted

Java installation under Windows is sometimes a really severe source of pain. The following assumes that you have Windows:

  1. Check your path variable
  2. Check JAVA_HOME variable
  3. Newer versions of Java (1.6 ?, but 1.7 and 1.8) copy some Java executables into the System32 directory of the windows installation. Simply delete this files (or move them somewhere else for easy recovery)
  4. running java applications by using .bat files a specific JDK / JRE can be provided.

There may be more sources of your problem. For example with Maven you depend on JAVA_HOME, with Eclipse you have the project settings, ...

share|improve this answer
    
i will check my system32 directory –  Nithin Varghese 58 mins ago
    
Sebastian...it works..I removed java,javaws and javaw .exe files from system32 folder. Thanks alot !! –  Nithin Varghese 50 mins ago
    
@NithinVarghese, if it worked, mark this answer as the correct one. It will increase Sebastian's reputation (he deserves xD) and can help other people with same problem. –  Albert 48 mins ago
    
I don't think it is safe to delete java.exe files from system32 folder. Internet explorer (maybe other applications too) use this jre to run applets. The correct way is highlighted in my answer. –  Mustafa sabir 45 mins ago
    
I think is safer not use internet explorer ;) –  Albert 42 mins ago

java.exe while java installation gets copied under System32 directory. Also we tend to append java path in the end of the path variable. This causes running java command pointing to the one in System32 (it takes the first path value that is encountered and ignores rest, in this case java of system32 folder). And when it cannot find javac it looks to other values of path and finds it towards the end for the java JDK (this is the one you want to use).To overcome this problem give path to your JDK for example C:\ProgramData\Oracle\Java\bin as the first entry in the windows path variables. Even before your system32 entry. This ensures you point to only one java. My path entry looks something like this:-

%JAVA_HOME%\bin;%SystemRoot%\system32;
share|improve this answer

If you are running Windows, you could perhaps check the path environment variable. It might point to an older JRE installation.

share|improve this answer
    
I checked the enviorment variables,thats not the issue .Both the java_home and path is pointing to 1.8 version –  Nithin Varghese 1 hour ago
    
I assume you have a second JRE with version 1.6.2 installed? –  Binkan Salaryman 1 hour ago
    
yes i do have 1.6 version also installed but i am not setting any env varibles for 1.6 version –  Nithin Varghese 1 hour ago
    
@NithinVarghese, check Sebastian's answer. You probably have your java command under system32, which it usually has preference over %JAVA_HOME% in your PATH enviroment variable. If exisits, delete it. –  Albert 52 mins ago
    
@Albert...i deleted java,javaw and javaws .exe files from system32 folder and it work fine now. –  Nithin Varghese 46 mins ago

One possibility is that your Java link is inconsistent. Go to this location (Windows):

C:\ProgramData\Oracle\Java\javapath and check where to does java.exe point.

In case it is not up-to-date consider fixing it with:

mklink /d C:\ProgramData\Oracle\Java\javapath "C:\Program Files\Java\<your JDK>\bin\"

(you may need to remove javapath old link before you create a new one)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.