How to Install Java on Windows?

Video Tutorial
FREE
Environment Setup - Windows 1 thumbnail
This video belongs to
Java Course - Mastering the Fundamentals
12 modules
Certificate
Topics Covered

Java requires the Java Development Kit (JDK) for execution on Windows. The JDK, encompassing the Java Runtime Environment (JRE) and the Java Virtual Machine (JVM), is essential for running Java applications like Minecraft or developing complex projects. This guide outlines the steps to install JDK SE 16 on Windows 10, providing the necessary tools for Java development and execution.

Prerequisites:

  • A system running Windows 10.
  • A network connection.
  • Administrator privileges.

Check If Java is Already Installed

Having multiple Java versions on the same system can lead to conflicts, as applications might try to utilize different versions. Moreover, outdated versions can pose substantial security risks over time.

Before proceeding with the installation of the latest Java Development Kit, it's advisable to verify whether a Java version is already installed on Windows:

  • Type "cmd" in the Windows search bar.
  • Open the command prompt.
  • Execute the following command to check the Java version in Windows: java -version

If the message says that Java is not recognized as an internal or external command, Java is not installed. If the system shows a Java version number, uninstall the previous Java installation before continuing.

Which Java Distribution Do We Need?

When selecting a Java Distribution, Oracle, Azul, Amazon, and Microsoft are among the companies that offer their Java installers based on the open-source OpenJDK project. Oracle is a reliable and widely used option. Oracle provides official Java installers and robust support for their JDK (Java Development Kit). This ensures a stable and well-maintained Java environment, making it a suitable choice for various development needs.

How to Install Java in Windows 10?

Step 1: To download Java, you should have an account on Oracle. You can sign in if you have one, or else you can sign up and create an account.

Step 2: Go to the site of Java Oracle using this link and download the latest version of JDK 16 from oracle.com for windows.

oracle window

Note: Before downloading check whether your system is 32-bit or 64-bit and download accordingly. In my case, it's 64-bit.

Step 3: Clicking on the installation link will take you to a popup window as shown below. Click on I reviewed and accept the Oracle Technology Network License Agreement for Oracle Java SE development kit and click on the download button. It will take you to the login page of Oracle, log in, and start downloading the software.

oracle login page

Step 4: Once the JDK 16 download is complete, run the .exe file on Windows to start installations. First, allow Windows to make necessary changes during installation.

allow changes

Begin the installation by clicking on next.

begin the installation

Step 5: Select the PATH where you want to install Java in Windows. Leave it default and click on Next.

default path

Step 6: After installations are done, click on Close.

done installation

Step 7: After installation, we need to set environment variables PATH and CLASSPATH to run a program. Path and Classpath both are operating system-level environment variables. Path is used to define where the system can find the executables(.exe) files and classpath is used to `specify the location of .class files.

PATH Variable:

  • The PATH variable gives the location of executables like javac and java that are stored in the bin folder of Java.
  • When you try to execute a program from the command line, the operating system searches for the specified program in the current direction and executes it if it's available.
  • In case the programs are not available in the current directory, the operating system verifies in the set of directories specified in the ‘PATH ’ environment variable.

CLASSPATH Variable:

  • The CLASSPATH variable gives the location of library files that are stored in the lib folder of Java.
  • This environment variable is used to specify the location of the classes and packages.
  • When we try to import classes and packages that are not available in Java Standard Library.
  • JVM verifies the current direction for them, if not available it verifies the set of directories specified in the CLASSPATH environment variable.

To set these environment variables right-click on this PC and go to properties.

setting enviroment

Step 8: Click on Advanced System Settings

click advance

Step 9: Go to environment variables and click on New.

enviroment variables

click new

Step 10: Create a new PATH variable and set its path to the bin folder, which is in the installed JDK folder.

create new path

Copy the address of the bin folder in JDK.

copy address for paste

Paste it in path variable value. paste in path

Step 11: Follow the same steps to create the CLASSPATH variable. Its variable value will be set to the lib folder in JDK.

creating classpath

Step 12: The PATH and CLASSPATH variables are set. Click on OK.

click ok

Here the installation of JDK 16 is complete and environment variables are set.

Conclusion

  • Java needs JDK which is a superset of JRE and JVM to execute programs.
  • javac command is used to compile java code and java command is used to execute it.
  • java command activates JVM, which is responsible for executing java programs.
  • After successful installation, we need to set environment variables to execute java commands.
  • IDE consists of the smart editor and other applications which are helpful in developing and debugging Java applications easily.