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
- Temporarily path
- 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
Step 2:
Click on Advance system settings
Step 3:
Click on Environment Variable
Step 4:
Click on the new tab
Step 5:
Give a name to the variable
Step 6:
Copy your java configuration location
Step 7:
Paste it at the value text of the variable.
Step 8:
Click on OK button
Step 9:
Click on OK button
Done.
These are the ways we can set a path.