The path is required to be set for using tools such as javac, java, etc.

If you are saving the Java source file inside the JDK/bin directory, the path is not required to be set because all the tools will be available in the current directory.

However, if you have your Java file outside the JDK/bin folder, it is necessary to set the path of JDK.

There are two ways to set the path in Java:

  1. Temporary
  2. Permanent

1) How to set the Temporary Path of JDK in Windows

To set the temporary path of JDK, follow the given steps:

  • Open the command prompt
  • Copy the path of the JDK/bin directory
  • Write in command prompt: set path=copied_path

For Example:

set path=C:\Program Files\Java\jdk1.6.0_



2) How to set Permanent Path of JDK in Windows

For setting the permanent path of JDK, follow the given steps:

  • Go to MyComputer properties -> advanced tab -> environment variables -> new tab of user variable -> write path in variable name -> write path of bin folder in variable value -> ok -> ok -> ok

For Example-

  1. Go to MyComputer properties
MyComputer Properties
    

     2. Click on the advanced tab

Advanced tab

   3. Click on environment variables

Environment Varialbes

4. Click on the new tab of the user variable

User variables

5. Write the path in the variable name

variable name


6. Copy the path of the bin folder

Bin folder

7. Paste path of bin folder in the variable value

Variable value


8. Click on OK button

OK button


9. Click on OK button

Step 9


Now your permanent path of JDK is set. Now you can execute any Java Programs.


Setting Java Path in Linux OS

Setting path in Linux OS is the same as setting the path in Windows OS. But, here we use the export tool rather than setting the path. For doing that do the following:

export PATH=$PATH:/home/jdk1.6.01/bin/