In this article, I will describe the use of PATH Variable in Java.
PATH variable in Java is an environment variable that specifies a list of directories where the operating system should look for executable files. So, in the context of Java, the
PATH variable is used to specify the location of the
java executable, which is used to run Java applications. Therefore, by adding the directory that contains the
java executable to the
PATH variable, you can run Java applications from any directory without having to specify the full path to the
java executable every time you run a Java program.
An Example of Using PATH Variable in Java
In order to run a Java program, we can use
PATH variable in a command-line interface (CLI). So, assuming that the
java executable is located in
C:\Program Files\Java\jdk1.8.0_202\bin, you would add this directory to your
PATH environment variable. The following steps explains this process.
- At first, open the Command Prompt or terminal window on your computer.
- After that, type the following command to view the current value of your
3. Now, add the path to the
java executable to your
PATH variable by executing the following command:
set PATH=%PATH%;C:\Program Files\Java\jdk1.8.0_202\bin
4. Once, you add this path, verify that the
PATH variable has been updated by executing the following command:
When the above command shows the correct path, you should be able to run the Java program from any directory by typing
java <program-name> in the command prompt or terminal window.
- Dot Net Framework
- Power Bi
- Scratch 3.0