java -version and javac -version showing different versions

'javac' is not recognized as an internal or external command, operable program or batch file.
javac -version command
javac command not found
javac -sourcepath

I have java 7 and java 8 both installed on my windows system under C:\Program Files\Java

In the environment's path I specified the path of java 7 like this.

%JAVA_HOME%/bin where JAVA_HOME = C:\Program Files\Java\jdk1.7.0_17

But when I type javac -version it shows javac 1.7.0_17 which makes sense

but when I do java -version it shows

java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

Any idea what may be the problem here?

Edit The installed folder :

And one more thing echo %PATH% has only one occurence of JDK that is for java 7 and no occurence for JRE found in it.

The issue is occuring most probably because you have a JRE in your path , before your JDK . This usually happens when we add JDK in the path and do not remove previously added JREs. Thus when you do java it points to the JRE and when you do javac it points to the other version/JDK (since jre does not have a javac in it)

Edit:- Since you edited your question and posted not having any JREs in your path, You can copy your %JAVA_HOME% and paste it first in your path variable (make sure its before system32 path), I have faced this issue before (while installing android sdk) and doing this resolved it.

Also found a possible explanation for this from here :-

JRE also puts a java.exe to c:\Windows\System32, that's how first command is resolved. Second command is resolved by the C:\Program Files\Java\jdk1.7.0_02\bin entry in your PATH variable. If (and when) you are developing from the command prompt, you have to adjust the PATH variable so that C:\Program Files\Java\jdk1.7.0_02\bin is before c:\Windows\System32.

ISC Computer Science for Class 12, Different versions of text editors are available like edit or ne (for DOS In Sun's JDK (Java Development Kit), the Java Compiler is javac and the Java Interpreter is java. With this the class file will execute and display the required output. Let’s roll, In this java tutorial or java tips, we will learn how to set java version and javac version. The main reason is you might have a few different java versions installed in your machine. But Sometimes for some projects, we need to use some specific java version and javac version to build that project.

Ok, as you said that you have no JRE on your path, I assume that where java (if you have Windows 7) will give you C:\Windows\System32\java.exe.

Changing the java running

Try using the Java-Settings Dialog from the control panel to change the Java System Version, which is currently active. This should change the version java -version is returning. If this does not work, you will probably need to reinstall the Java version of which you want to run the java command, specify the path explicitly, write you own wrapper (which works if you are in the same directory as the wrapper) or place the JRE path before C:\Windows\System32\ onto your path (don't know if last option really is a good one).

A wrapper could look just like this:

@"C:\Program Files\Java\jre7\bin\java.exe" %*

and you can either name it java.bat (where it will work if you are in the same directory or put it in PATH before C:\Windows\System32\java.exe or you could name it java7.bat and put it anywhere on you path to be able to run the Java 7 JRE if you desire to do so.

A wrapper is also a good option if you want to change the JAVA_HOME when running.

Changing the javac running

If you want to run a different javac hit Windows + Pause and open the system dialog to change the PATH so it contains the path to your JDK 8 instead of your JDK 7. You will need to restart your command line for changes to show.

ISC Computer Sciencefor Class 11, Different versions of text editors are available like edit or ne ( for DOS In Sun ' s JDK ( Java Development Kit ) , the Java Compiler is javac and the Java Interpreter is java . With this the class file will execute and display the required output . so how i should change version of java. Thanks . 35 Views 1. Re: javac and java showing different versions. 843810 Sep 27, 2007 8:39 PM

Go to Environment Variables in your windows machine. In User Variables : Make sure to set - Your user variable "JAVA_HOME" value to "C:\Program Files\Java\jdk-xxxx\bin" where "jdk-xxx" is the version of your jdk.

In System Variable : - Add same "C:\Program Files\Java\jdk-xxxx\bin" value to "Path" variable. make sure to move the added value on top of all values.

Now try running java -version and javac -version. worked for me. :) Here i've linked my screenshot

Java 2 Enterprise Edition 1.4 (J2EE 1.4) Bible, However, a cleaner way is to use the nested tags src and include, as shown in 27-3: Specifying. different. Java. source. locations. <javac destdir=”${build}”  Next step is this alternatives --config java and pick the latest one. Suddenly this particular machine I am having issue when I run this 2 commands it shows me different version of java and javac causing my programme can't be compiled. Below is all the java. alternatives --config java. There are 4 programs which provide 'java'.

My case (moving jdk8 -> jdk9 -> jdk11) I had a garbage left by jdk8 in PATH (before JAVA_HOME:"C:\path\java11")

so I just remove C:\ProgramData\Oracle\Java\javapath_jdk8 from system variables

// or place it below javapath_jdk11

Learning Java, You can use the -d option with javac to specify an alternative directory for BigBird.java You can specify multiple .java files in a single javac command; the javac can compile an application even if only the compiled (binary) versions of some  Somehow I do not know that javac is running with JDK 1.5.0 version compiler and java is running with JDK 1.4.2 java.exe. How can I tell the java.exe file to use JDK 1.5.0 java.exe file???. My java and javac exes are running on different versions[unsolved] (Beginning Java forum at Coderanch)

To resolve such kind of environment issue I always believe on command whereis, To do the same in windows download whereis.exe then set in path and execute the command

whereis java.exe

whereis javac.exe

You will easily find the exact path from which location java is being called in environment as well about javac.

java - Messed up javac, The command you issued: set > eg.java. Overwrite the eg.java file with other text (​specifically, the output of the set command). You'll need to  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.

javac, There are two ways to pass source code file names to javac: are compiled against a bootstrap and extension classes of a different Java platform implementation. Without -deprecation, javac shows the names of source files that use or override In previous releases, the -g and -O options could not be used togther. It finally UPDATED!!! I deleted all the older versions of JDK manually, and typed: javac -version to make sure it was properly updated to the newest version. The system variables of JAVA_Home were also automatically updated to the new version. Thank you! – ChosenJuan Sep 29 '16 at 22:07

I need a little help with the "script" packages - support, 'javac' is not recognized as an internal or external command, operable program or batch Different versions of Windows do things differently. C:\Program Files (x86)\Java\jdk1.8.0_121\bin but it works better now it shows a lits of “stuff” in the command prompt and the error in atom has changed javac:  Under the General tab in the Java Control Panel, the version is available through the About section. A dialog appears (after clicking About) showing the Java version. Java Version in Windows Programs. The latest version (s) of Java on your system will be listed as Java 8 with an associated Update number (eg. Java 8 Update 111). Older versions

Javac vs. javacpl vs. javaw?, check this link for more information : Different between java v/s javac v/s to Oracle's OpenJDK 11 instead of Oracle JDK 11 or to other open JDK versions? >javac sample.java The java command is used to execute the bytecode of java. It takes byte code as input and runs it and produces the output. Following is the syntax of this command. >java sample Let us consider an example create a Sample Java program with name Sample.java. Sample.java

Comments
  • Are you sure you installed the Java 8 JDK, and not just its JRE?
  • See if echo %PATH% contains the JRE folder of Java 8 before the JDK folder of Java 7
  • set your jre7 bin location path at first like - set PATH=%JAVA%\bin;%PATH% so it will pick your jdk7 bin path first.
  • @Mureinik please if you dont mind check the edit of the question
  • @ChrisMartin if you read the query properly you can most probably find what is the problem
  • echo %PATH% shows only one occurence of JDK and that is for java 7 and no occurence for JRE found in it.
  • Ok so I just found that c:\Windows\System32\java.exe date-modified is same as the java 8 installation date so I guess that the java.exe in c:\Windows\System32 is of java8 how to resolve this problem?
  • Yes, which i guess confirms that its taking java.exe of java 8 from system32, I have written in my answer, You can copy your %JAVA_HOME% and paste it first in your path variable (make sure its before system32 path) , this way it will get both jdk and jre of java 7 before system32 version that is of java 8
  • +1 not an ideal solution though but indeed thanks for the help :)
  • I just found that c:\Windows\System32\java.exe date-modified is same as the java 8 installation date so I guess that the java.exe in c:\Windows\System32 is of java8 how to resolve this problem without tempering the path?
  • @M.Sharma Second paragraph of my answer. Guess reinstalling the JRE 7 could be the best option. For me there is now way to change the System JRe through the Java-settings-panel also I think that this was once possible.
  • java path sometimes really can be a pain in the ass
  • So that means next time if I uninstall and reinstall java 8 again I'll face the same problem unless I keep my desired path before c:\Windows\System32