Java Path and Classpath setting
Java path and classpath setting can be done in two different ways. one is temporary setting through command prompt and permanent setting by using environment variable.
Temporary setting : ( not recommended)
For beginners who are excited to compile and run their first “HelloWorld” program , I would like to say please take care of path and classpath setting. Most of the beginners will try to compile and run their first programs through command prompt. so setting up a path and classpath in command prompt is temporary.
From our JDK installation page we have installed jdk in C:\Program Files\java\jre 1.8.0_7. You have finished writing your first program and saved as for example HelloWord.java. Then you have to compile and run the program in the command prompt. But before compiling and executing the program you have to set the path and classpath as follows.
Step 1: Open command prompt
Step 3: Path setting
Type set path =C:\Program Files\Java\jdk1.8.0_71\bin and then press Enter
Step 4 : Confirming the path
To ensure your path please type
echo %path% and press Enter , it will display your settled path.
Now your windows knows where your javac tool is. but remember if your source code HelloWorld.java is in jdk/bin folder , no need to set the path.
Before setting the classpath let’s consider your HelloWorld program is in D drive myprograms folder
open command prompt
Step 2 :
Type set classpath = d:\myprograms;.; and then press Enter.
Step 3: Confirming
To confirm your Classpath please type echo %classpath% and then press Enter
Why this procedure called temporary setting ?
This is called temporary setting because whenever your system restarts these settings will be deleted. You have to set the path and classpath settings every time you logged into windows account.
Permanent Path setting
For permanent path setting please follow the following steps.
Double click mycomputer or go to mycomputer and then right-click for properties
click on Advance system Settings
Click Environment variables tab and then click new tab in user variables section
Step 4 :
After clicking new tab please type path in variable name section and then please copy the location of the bin folder and paste it in variable value section
and then click OK for all windows.
Now your permanent java path is set and you can execute your java programs from any drive. Everything is ready to go for your first java program. You are set to go through the online java training. Happy learning.
If you have any questions regarding JDK installation and setting classpath please comment below , our experts will get back to you asap. Thank you.