How to Set Path in Java

The path is a variable required for the System to give an execution environment to the java application. With java development kit we get the required environment for execution and compilation environment. When we run a java command we have to specify the location where command definition can be found. We do that by setting the classpath.

There are two way to set the classpath

  1. Temporarily path
  2. Permanently path

How to set the Temporary Path of JDK in Windows

To set the temporary path, follow these steps –

  • Open command prompt
  • Execute below command
  • Set path = C:\Program Files\Java\ jdk-10.0.2\bin
  • Compile your class javac
  • className.java
  • Run your class.
  • java className

How to set Permanent Path of JDK in Windows

To set path variable permanent, so every time you open command prompt you do not need to set path explicitly, follow these steps –

Step 1:
Go to my computer and open properties

How to Set Path in Java Step - 1 | Java Point Tutorial

Step 2:
Click on Advance system settings

How to Set Path in Java Step - 2

Step 3:
Click on Environment Variable

How to Set Path in Java Step - 3

Step 4:
Click on the new tab

How to Set Path in Java Step - 4

Step 5:
Give a name to the variable

how to set classpath in java step - 5

Step 6:
Copy your java configuration location

how to set classpath in java step - 6

Step 7:
Paste it at the value text of the variable.

how to set classpath in java step - 7

Step 8:
Click on OK button

how to set classpath in java step - 8

Step 9:
Click on OK button

how to set classpath in java step - 9

Done.
These are the ways we can set a path.

Share