How to set Path

PATH CONCEPT:

Better to separate the java program files from java bin folder location like below:
javapadho
Folder Structure where HelloWorld.java file save

Now if you want to compile our program follow bellow steps

  1. First we have to go to the location where our source code is available (i.e. D:\sdjbatch)
  2. For compiling we use javac command. Like below.
  3. javapadho
    Compile Time Error HelloWorld.java
  4. When we are compiling 'HelloWorld' program from where our source code is available we still gets an error as follows. D:\sdjbatch>
    javac HelloWorld.java javac is not recognized as an internal or external command operable program or batch file.
  5. To overcome this we need to compile our program where java commands are available.
    javapadho
    Compile Time Error HelloWorld.java
  6. Note
    • Here we are getting again an error(i.e. "error: cannot read: HelloWorld.java") Why because operating system looks for our HelloWorld.java inside /bin folder but it isn't there, due to that we are getting above error.
    • So here we found one tpical problem i.e., when we try to compile our program from our java file location OS isn't able to find out the java cmds,and when we try to compile our program from java cmd place OS isn't able to find out the java program.
  7. To overcome above two errors & if we want to make compile success Setting PATH environment variable

    Here PATH is one of the system variable,by using this we can intimate the third party software location to OS.By default Os will look for third party software commands under current location, if it not found then it looks into PATH variable location.

  8. PATH VARIABLE

    We can set Path variables in three ways they are
    1. Command prompt wise environment variables.
    2. User environment variable.
    3. System environment variable.
  1. Command prompt wise environment variables.
  2. By using command prompt wise,single user can compile & run the file with in that cmd prompt only

    javapadho
    Command prompt wise path environment variables

    Steps for compilation process :

    • Looks for "javac" command under current directory i.e. src. if it is not found then it looks into "Path" variable location where "javac" command is found.
    • Finds HelloWorld.java
    • Then finally "Compile Success" & create ".class" file under current location.
    • The drawback of Command Prompt Wise is that,the path is available only for 1 command prompt window, for a new window we have to set the path again.
    • This process will be done within the single cmd prompt only.

  3. UserWise
    • In order to overcome the drawback of Command Prompt Wise sun people came up with User Wise Path setting.
    • By using User Wise, single user with multiple cmd prompts will be worked.(1 User+multiple Command prompts)

    User Wise path variable settings is done by using following steps:

    Step1: start->Right Click on MyCompute->Click of Properties
    javapadho
    User wise path environment variables Step-1
    Step2: click on select Advanced system settings
    javapadho
    User wise path environment variables Step-2
    Step3: click on Advanced -> Environment Variables
    javapadho
    User wise path environment variables Step-3
    Step4: click on Environment Variables->inside user variables select New
    javapadho
    User wise path environment variables Step-4
    Step5: After selecting new, two options will appear i.e. Variable name & Variable value.
    javapadho
    User wise path environment variables Step-5
    Step6:   Give the Variable name as "PATH" and Variable value as "java installed location" i.e "D:\JDK6.0\bin" and select OK.
    Note
    • By using User Wise variable "javac" command works not only in the directory in which the java is installed but also in any directory.

    Drawbacks: Drawback of user wise path variable is only one user can use. In case if the system has multiple users it won't work

  4. System Wise variables:

  5. To overcome the drawback of "user wise variable" sun people came up with "System wise variable"
    By using "System wise variable" multiple users can use the multiple cmd prompts with single system only (multiple users multiple cmds one system).

    Steps for setting system variables are as follows:
    First 4 steps is same as the user wise variable

    Step5: click on Environment Variables->inside system variables select New
    javapadho
    System wise path environment variables Step-5
    Step6: After selecting new, two options will appear i.e, Variable name & Variable value. Give the Variable name as "PATH" and Variable value as java installed Location i.e, "D:\JDK6.0\bin" and select OK.
    javapadho
    System wise path environment variables Step-6