Have you ever try to run a Java program from command line only to get an error?
‘java’ is not recognized as an internal or external command,
operable program or batch file.
What happened? You know you installed Java. The above error on Windows means, that you didn’t add the Java directory to the System PATH. I typically add the JAVA_HOME environment variable and the %JAVA_HOME%bin to the PATH. This works. But, since I work with different versions of Java, I tend to add these to batch files that run Java command, instead of hard coding to one version at the system level.
You want to see if Java is installed on your machine and if so what version? you can simply search for “Java.exe” in Windows explorer. But, there are several ways to make sure it will work as expected:
On command prompt
This works if Java is installed and is JDK/JREbin is added to the system PATH. This shows you:
java version “1.8.0_91”
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) Client VM (build 25.91-b14, mixed mode, sharing)
Where is Java?
If you do a where(1) Java on command line, you may find it as follows:
That’s a surprise. You surely didn’t install it in ProgramData. If you go there and look at java.exe, you will notice that it is a symbolic link pointing to the installed Java version. Another way, Symbolic links are helpful.
Here is a post that talks about Oracle using this “new technique” to be able to find Java from anywhere, without adding it to the system PATH. It also talks about switching different versions of Java.
Here is another discussion on this technique in Java. As the author mentions, I remember seeing Java.exe in WindowsSystem folder. It is not there now. Oracle probably silently replaced copying to Windows system folder with the symbolic link in ProgramData folder. At least, it’s cleaner.
Using Windows Start menu Search option(2)
Recently, while watching one of the training videos on Java, got a simpler method:
Just goto start button and type “about Java” (it goes into Search programs and files box) and press Enter. It pops up the below window, if Java is installed:
Java Install location
Finally, I tend to keep all my JDKs and JREs in a directory called, C:Java. I do not like the default locations, C:Program Files(x86)Java (32-bit) or C:Program FilesJava (64-bit) as the embedded space causes issues.
C:Java>dir j* /b
This way, I can all my versions in one place (3), (4).
And yes, please keep your Java JDK/JRE versions up to date. Oracle has been issuing a lot of security patches recently.
(1) In case you are not aware, as of Windows 7, Windows shell has a new command called “Where”. This is almost like Unix which command. Finds all instances of a file in the System PATH.
(2) This feature of typing into Start Button started with Windows 7 and is available in Windows 8, 8.1, Windows 10. Have you tried it? You don’t have to drill down Start menu to find items. You can start typing on it and it will start showing icons with matching names.
(3) I always keep the latest versions of Java 6, 7 and 8, as different programs may use different Java versions.
(4) All my versions are 32-bit. If I I had installed 64-bit versions, then I would have named them jdk_1.8.0_66_x86 and 1.8.0_66_x64.