In this article, we will learn how to set path in java. Setting path in Windows allows you to run Java applications and compile Java code from the command line, without specifying the full path to the Java executable. Here’s how you can do it:
Step-by-Step Guide:
- Download and Install Java Development Kit (JDK):
- The first step is to download and install JDK, download it from the Oracle website or OpenJDK site.
- Install the JDK.
- Find the JDK Installation Path:
- After installation, find the folder where the JDK is installed. Usually, it looks like
C:\Program Files\Java\jdk-xx.x.x
.
- After installation, find the folder where the JDK is installed. Usually, it looks like
- Open Environment Variables:
- Press
Win + X
and select System or System settings. - In System settings, click on Advanced system settings on the left-hand side.
- In the System Properties window, click on the Environment Variables button.
- Press
- Set JAVA_HOME:
- In the Environment Variables window, click on the
New
button under the System variables section. - Enter
JAVA_HOME
as the Variable name. - Enter the JDK installation path (e.g.,
C:\Program Files\Java\jdk-xx.x.x
) as the Variable value. - Click
OK
.
- In the Environment Variables window, click on the
- Update the PATH Variable:
- In the Environment Variables window, find the Path variable in the System variables section and select it.
- Click on the Edit button.
- In the Edit Environment Variable window, click on the New button and add the following:
%JAVA_HOME%\bin
- Click
OK
to close all windows.
- Verify the Setup:
- Open a new Command Prompt window (press
Win + R
, typecmd
, and press Enter). - Type the following command and press
Enter
:java -version
- If the path is set correctly, you should see java version information. This confirms that everything is setup correctly.
- Open a new Command Prompt window (press
Summary of Commands and Entries:
JAVA_HOME:
Variable name: JAVA_HOME
Variable value: C:\Program Files\Java\jdk-xx.x.x
Path:
%JAVA_HOME%\bin
Example:
Let’s say, you installed JDK version 15.0.2 in the default directory, the entries would be:
JAVA_HOME:
Variable name: JAVA_HOME
Variable value: C:\Program Files\Java\jdk-15.0.2
Path:
%JAVA_HOME%\bin
Once these steps are completed, your path is permanently set in Windows. You can compile and run Java programs without needing to specify the full path to the Java executables.
Leave a Reply