Usually when saving a java file we do not save in java’s bin folder e.g (C:\Program Files\Java\jdk\bin). We tend to save in some other folder or drive which is easier to access or which is comfortable.

While all the executable codes and files are in bin folder of jdk. Once you are in the location of the java program file which you want to compile e.g (D:\Programs\Practice). The program wont even compile because the operating system e.g Windows is unaware where the executable file resides.

In order to let the OS know where the executable files are, we have to set path before compiling the program. There are many ways to set path of bin folder.
The first one is generally used eg: set path = C:\Program Files\Java\jdk\bin
set path long

But the above mentioned way only works till the cmd is open. Once the cmd is closed the path for bin which is set is also terminated. You have to put the above command again in cmd, in order to compile java programs. This consumes precious time and could also be frustrating.

So, in order to set the path once and permanently follow the steps.

Steps to “set path” permanently:

  • Right click on “My Computer” and select “Properties” or Go to “Control Panel” and select “System“.
  • On the left side of control panel select “Advanced System Settings”  as shown in the picture below.

adv sys settings

  • You will get “System Properties” window. In that go to “Advanced” tab and select “Environment Variables…“.

Sys properties

  • After that you will get “Environment Variables” window. Select “New…” under the section of “User variables for Username“.

envi var

  • You will see “New User Variable” window. In that enter any “Variable Name” you want for eg PATH. in “Variable Value” enter the path of the java’s bin folder. e.g C:\Program Files\Java\jdk\bin

new user var

  • After that click on OK on “New User Variable” window, then click OK on “Environment Variables” window and then click OK on “System Properties” window.
  • That’s it you are done now. You can directly compile java programs through cmd without setting the path again and again.