To create java programs you need the Java Development Kit (JDK) installed on your machine. For personal use you can download the JDK from the Oracle website (Oracle purchased Sun Microsystems who originally developed Java).
You can install 1 JDK version or you can install multiple JDK versions if you need to. For the purposes of this tutorial we will be downloading Java 8. One of the things you may find confusing is the Java version numbering system. Sometimes you can see it referred to as Java 1.8 for example, sometimes as Java8. These are essentially the same versions, but often these days the leading 1.x is dropped and just the number after referenced.
Whats New In Java 8
Downloading the JDK for Java 8
Navigate to https://www.oracle.com/technetwork/java/javase/downloads/index.html and scroll down till you get to the Java SE 8 version. You should see a section on the page similar to the below.
Theres quite a bit going on here so lets take the time to explain. What this is referring to is Java SE 8u221 or Java Standard Edition update 221. If you click on the learn more option it will take you to a page that details all the updates (usually bug and security fixes) since JDK 8 was released.
The JDK is what we are interested in, but there are also runtime version which allow you to run but not modify the java code. These are useful for end user machines or servers where there is no need to change the ode, just run the applications.
If you click on the JDK Download button you will be presented with a page similar to below
The Oracle JDK Licence has changed
Previously you could download and install the java versions and run them on your Pc, servers etc and not worry too much about the license. But as of April 16th, 2019 the license that Oracle use for java has changed. Thankfully for personal use, such as using the Java JDK to learn how to program in Java, the license hasnt really changed and you can download and use.
But if you are using Java in a commercial setting such as developing software for your business, then you need to have a license that lets you use Java, either by purchasing a subscription, or getting a license included with some other Oracle software such as Oracle Solaris operatiing system.
For those that want to use Java in a commerical setting without a license, you will need to switch to using the relevant OpenJDK open source version of java. The main difference here is that those versions arent as up to date and also are unsupported by Oracle. In practice this just means that you wont be able to use the latest and greatest version of Java as they come out, which shouldnt cause too many problems anyway, as most people stick to old version for quite a long time.
Java Download For You Operating System
Scrolling down and you get presented with various downloads depending on which operating system you need Java for, Linux, Mac, Solaris or Windows.
Assuming that you are using a recent windows machine running windows 10, you would click on the Windows x64 to download the 64 bit version, jdk-8u221-windows-x64.exe. At this point when you click on the ‘Accept License Agreement’ and then click on the link to the download you will be presented with the Oracle Account login page.
You can either login if you already have an account or sign up and then login and continue the download.
Once you login here, the download should start immediately.
Installing the JDK
Once the executable installer has downloaded, click on it to begin the install. You may get windows asking you if you want to allow the installer to make changes, so click yes in this case as we know we are doing an install.
You should then get presented with the JDK 8 Update 221 install window, so click next to continue
You should then see the Java SE Development Kit 8 Update 221 (64 bit) Custom Setup window. This tells you what you are about to install and where. Normally you would leave the defaults and click next to continue.
Then you get a confirmation page for installation of the JRE, so click next to continue
You will then see the installer splash screen with the progress bar as it installs the Java JDK and JRE.
Once the install is complete you will see the install complete confirmation screen. Click Close and at that point you are done with the installer.
Checking The Java Environment
To make java accessible from the command link easily, it should be on your system path. You can check this by starting a command prompt and checking. Right click the start button then click command prompt.
At the command prompt, type java -version, and it will show you which version of java is currently setup on your path, or an error if not.
As you can see we have the correct version showing up. We could additional check the environment variables, but as its showing the correct version we dont need to for now.
Installing Multiple Versions Of Java
If you want to have multiple version of java available on your computer for some reason, such as you have a piece of software that demands a specific version of java, you can install java just as we have done here, and then use a windows batch file to point to a specific version of java.
Or you may want to point to the jdk instead of the JRE, for instance if you have some specific software that may need to compile code, so as software for developers. in that case what we would do would be to create a windows batch file that would modify the path so that the version of java we require is run instead of what has already been defined on the path.
set path=C:\Program Files\Java\jdk1.8.0_221\bin;%path% java -version
We create a windows batch file by opening notepad, and then saving that with a .bat extension. If we then run that we get the below.
This does look the same as before as we havent actually installed an additional version yet, but if we check the path by typing path at the command line we can see that the one we sit is there first now.