I have Oracle JDK 17 installed on my system at the default location in my Windows 10 OS. I can use the javac compiler from the command line.
I am going to install GraalVM JDK [java17] in my system (zip file) at a different location.
Online docs have instructed me to add the path to GraalVM bin directory (Eg C:\path\graalvm\bin) to the PATH variable on Windows .
Now when i type C:\javac mySourceFile.java and press enter
How will the OS decide which java compiler(oracle javac /GraalVM javac) will it use to compile the source code as both of them are named javac ?
Here i am not explicitly passing the location of the javac to be used.
is there any way to specify which jdk to use at command line?
Please note that compiling is done using command line tools only and no IDE is used. (I am aware that IDE's allow you to select the JDK based on the location using preferences/settings)
When you type "javac MyClass.java", the path list defined in the PATH variable will be searched from left to right. When it finds a match, it will use that command. So, it's possible you may have include multiple java\bin folders in the path. It will execute the first one it finds. If you want a particular version of Java to execute, add it as the first path to the path variable.