How to set path in Java

JDK (Java Development Kit) is a software development environment which has collection of various tools and libraries to develop a Java program.

In order to run a Java program, you have to install JDK in you device. After the JDK installation, path has to be set properly, or else you cannot run the code.

Only if the Java file exists outside the jdk/bin folder, it is required to set the path of JDK. If the file is saved within the jdk/bin folder itself, there is no need to set the path.

To set the path in Java, you can use two ways:

  1. Temporary
  2. Run command prompt.
  3. Open the jdk/bin folder of Java and copy the path.
  4. In command prompt, type the command and press enter.
  5. Permanent
  6. From My Computer, go to Properties and open environment variables.
  7. Set the path of User Variables to the jdk/bin folder with the name PATH.
  8. To set the path temporarily in Windows:

Open Command Prompt and type the below command:

set path=C:\Program Files\Java\jdk1.8.0_161\bin

How to set path in Java
  • To set the path permanently in Windows:

To set the permanent path of JDK, use the following steps:

  • Open the MyComputer/ ThisPC of your device. Right click on the This PC and open the properties.
How to set path in Java
  • In the Advanced system settings, click on theEnvironment Variables.
How to set path in Java
How to set path in Java
  • In the Environment Variable tab, we will set the User Variables. Click on the New button.
How to set path in Java
  • A new dialog box named New User Variable will pop up.
How to set path in Java
  • Set the User Variable name as PATH, paste the Variable value as the copied path of jdk/bin folder.
How to set path in Java
  • Click OK -> OK -> OK and close the Control Panel.Now go to Command Prompt and run your Java program.
How to set path in Java

In this way, we have learned how to set the path in Java, using both temporary and permanent ways.

Pin It on Pinterest

Share This