Java path and classpath setting

environment variable

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

Java path and classpath setting

 

Step 3: Path setting

Type  set path =C:\Program Files\Java\jdk1.8.0_71\bin and then press Enter

Java path and classpath setting

 

Step 4 : Confirming the path

To ensure your path please type

echo %path% and press Enter , it will display your settled path.

Java path and classpath setting

 

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.

Classpath setting 

Before setting the classpath let’s consider your HelloWorld program is in D drive myprograms folder

Step 1:

open command prompt

Java path and classpath setting

 

Step 2 :

Type set classpath = d:\myprograms;.;  and then press Enter.

Java path and classpath setting

 

Step 3: Confirming

To confirm your Classpath please type echo %classpath%  and then press Enter

Java path and classpath setting

 

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.

Step 1: 

Double click mycomputer or go to mycomputer and then right-click for properties

Java path and classpath setting

 

Step 2:

click on  Advance system Settings

Java path and classpath setting

 

 

Step 3:

Click  Environment variables  tab and then click  new tab in user variables section

Java path and classpath setting

 

 Java path and classpath setting new path

 

 

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

Java path and classpath setting copy the path

 

 Java path and classpath setting path and loacion

 

 

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.

One thought on “Java path and classpath setting

Leave a Reply

Your email address will not be published. Required fields are marked *