Home Java Tutorial How to set path in Java

How to set path in Java

by Anup Maurya
12 minutes read

In Java, the “PATH” variable refers to the system environment variable that contains a list of directories that are searched for executable files when running a command from the command prompt or terminal. Setting the PATH in Java is essential because it enables the Java Virtual Machine (JVM) to find the necessary libraries, tools, and executable files that are needed to run a Java application.

Steps To Set The Path In Java

  1. Go to “System Properties” (Can be found on Control Panel > System and Security > System > Advanced System Settings)
  1. Click on the “Environment variables” button under the “Advanced” tab
  1. Then, select the “Path” variable in System variables and click on the “Edit” button
  1. Click on the “New” button and add the path where Java is installed, followed by \bin. By default, Java is installed in C:\Program Files\Java\jdk-11.0.1 (If nothing else was specified when you installed it). In that case, You will have to add a new path with: C:\Program Files\Java\jdk-11.0.1\bin
  2. Then, click “OK”, and save the settings
  1. Restart your computer or terminal in order for the changes to take effect.
  2. At last, open Command Prompt (cmd.exe) and type java -version to see if Java is running on your machine.

Write the following in the command line (cmd.exe):

C:\Users\Your Name>java -version

If Java was successfully installed, you will see something like this (depending on version):

java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

    Now that you have set the path in Java, you can run Java applications and compile Java code from any directory on your system without having to specify the full path to the Java executable every time.

    In summary, setting the PATH in Java is necessary to ensure that the Java Virtual Machine can find the necessary libraries, tools, and executable files that are required to run Java applications. By following the steps outlined above, you can easily set the path in Java and streamline your Java development workflow.

    related posts

    Leave a Comment

    Adblock Detected

    Please support us by disabling your AdBlocker extension from your browsers for our website.