How to Set Path in Java?
In this section we will demonstrate that how we can set path in Java. When the path for java is set we are able to use the tools that include javac to compile the Java program and java etc. If the Java source file is saved inside the jdk\bin directory then the path for this java is file is not mandatory to be defined, the tools will be available for the java program. But defining the path for Java is a good practice.
If the Java source file is saved outside the JDK\bin directory then the pet should be defined. It will become mandatory to define the path. The peth can be defined in two ways:
To set the temporary path of JDK in windows, first of all open the command prompt from the start menu. After this you need to copy the address of the JDK\bin directory. Now paste this address in the command prompt as the following command:
set path = copied_path
Consider the following example to understand this concept:
set path = C: \ Program Files \ Java \ jdk1.8.0_111 \ bin
How to set Permanent Path of JDK in Windows?
The permanent path of JDK in windows can be set by right clicking on the “my computer” and selecting properties, consider the following picture:
Another window will be opened. Now choose “Advanced tab”:
Select “Environment variables” from the new tab:
After clicking on the “environment variable”, click on new from the environment variable tab:
Now write path in variable name and write the path or address of the bin folder in the variable value tab. Then press the ok button three times.
The path can be copied in the following way:
Then click on the OK button.
In this way we have set permanent path. You can use any java program from any drive in your computer.
The path is Linux operating can be set easily; it is same as we set the path in windows operating system. The only difference is that in Linux operating system we use “Export” tool instead of set that we used for the temporary path in windows.
Consider the following command to set path for the Linux operating system:
Export path = $Path: / home / jdk1.8.0_111 / bin
In this way we have installed the JDK in the directory named home.