How to properly install and setup Java (JDK/JRE) in Windows.


There are many tutorials out there explaining how to setup Java in Windows. The reason of this blog is not to blame other posts for the lack of clarity, but to make your Java environment on Windows so stable that, should you upgrade the JDK/JRE in future, you will need minimal change and everything will still run.

I have just played with Java 9 Early Access Release, Build 166 (jdk-9-ea+166_windows-x64_bin) as of time of writing writing (thanks to Hackday at the HacktheTower and JoziJUG). Many had issues running the project on Windows, especially when creating modules, so I thought it was a perfect reason to write this blog and have it as a memorium.

Install the JDK.

I prefer installing the JDK because I am and have always been a developer and I need the compiler to compile my code. Installing the JDK, I prefer downloading the executable, in my case jdk-9-ea+166_windows-x64_bin.exe and following the prompt. By now, if you're a developer, I don't need to tell you how to install Java.

Setup the Java environments

I setup all my environment variables as User variables as System variables MIGHT require a system restart.
  1. Set JAVA_HOME variable to be the root path of your Java directory.
  2. Set CLASSPATH variable to the value %JAVA_HOME%\lib
  3. Add %JAVA_HOME%\bin to the PATH environment variable. If the PATH is not yet specified, or does not exist, PATH can just be %JAVA_HOME%\bin else just prepend your value with the semicolon(;).
If you set those environments as System variable(s), restart your system for sanity sakes.

In future, if you upgrade your Java and install it in another folder, just update the JAVA_HOME environment variable.


Now, to test, Open the command prompt and enter: echo %JAVA_HOME%


If you get the root path of your java directory, then you have properly configured JAVA_HOME environment variable. Now, do the same for CLASSPATH and PATH.

I hope this helps.


Comments