In this tutorial, we will discuss how to install Java 8 on Windows 10. The steps should be the same for other versions of Java and older versions of Windows.
Notes: You may also install the popular IDEs to develop Java applications by following - How To Install Eclipse For Java On Windows, How To Install IntelliJ IDEA for Java on Windows, How To Install NetBeans On Windows, and How To Install VSCode For Java On Windows. You may also follow the How To Install OpenJDK 16 On Windows, How To Install OpenJDK 16 On Ubuntu 20.04 LTS to install the latest OpenJDK and How To Install Java 16 On Windows, How To Install Java 16 On Ubuntu 20.04 LTS to install Oracle JDK.
System Checks
In this step, we will test whether Java is already installed or not. To do so, open the command prompt and type java -version as shown in Fig 1. It shows that Java is not installed.
Download Java 8
Open the download link to select the available versions as shown in Fig 2.
Click the Download Option as highlighted in Fig 3. It will ask to accept the License Agreement before starting the download as shown in Fig 3 and Fig 4. It might also ask to login to Oracle before starting the download.
Install Java 8
Double click the downloaded file to start the installation. In windows 10, the installer asks for system permission before starting the installation. Click the Yes Button to allow the installer to execute. The installer shows the Welcome Screen as displayed in Fig 5.
Make sure that you have gone through the updated License Agreement of Java. Now click the Next Button to continue with the installation. The next screen shows options to select optional features to be installed together. Leave the default options without making any change. We can also change the installation location on this screen if required as displayed in Fig 6.
Now click the Next Button to start the installation. It will show the progress as displayed in Fig 7.
The installer will also ask to choose the location of JRE as displayed in Fig 8.
Click the Next Button to start the JRE installation. It will show the progress as shown in Fig 9.
At last, it shows the Success Screen after completing the installation as shown in Fig 10.
Now open the Command Prompt and type the command java -version to confirm whether it's installed successfully as shown in Fig 11.
It will either show the message - java is not recognized as an internal or external command or show the previously installed version. In order to start using the JDK installed by us from the command prompt, we need to set the environment variable. You can follow the below-mentioned steps to do so.
Right Click -> My Computer(This PC) -> Properties -> Advanced System Settings
The above steps will open the Windows settings panel as shown in Fig 12.
Now click on Environment Variables, select Path under System Variables section and click on Edit. We need to add the path of installed JDK to system Path.
Remove the path of previously installed JDK. Also, update JAVA_HOME in case it's already set. Now click on New Button and add the path to JDK bin which is C:\Program Files\Java\jdk1.8.0_241\bin in my case as shown in Fig 13. Press OK Button 3 times to close all the windows. This sets the JDK 8 on system environment variables to access the same from the console. You may also set the JAVA_HOME environment variable which is referred by some of the software including Android SDK Tools to determine the Java version.
Now again open the console and test the Java version as shown in Fig 14.
Getting started with Java - Hello World
In this step, we will write, compile, and execute our first program in Java using the standard Hello World example.
Now write the first Java program as shown below, save the program as HelloWorld.java and exit the editor. Make sure that the class name and file name are the same.
class HelloWorld {
public static void main( String[] args ) {
System.out.println( "Hello World !!" );
} }
Now open the command prompt and navigate to the path where you have saved your Java program. Use the below-mentioned commands to compile and execute the program.
# Compile - Specify file name and extension javac HelloWorld.java
# Execute - Spicy file name java HelloWorld
# Output Hello World !!
These are the easy to install steps required to install Oracle Java on Windows and write, compile and execute the Java program.
Summary
This tutorial provided all the steps required to install Java 8 on Windows 10 and also provided the steps to configure the system path to access Java from the console. At last, it explained the steps required to compile and run the Java programs using a simple Hello World program.