How to set Java Path?. How to set Path in Java for Windows
Any person who had to study java has to install JDK. After installing JDK, path has to be set to execute java. Before we get to know about the steps involved in setting a java path we must know its necessity.
Whenever we write a java program we save it with an extension ‘.java’ and save it in any directory. To compile it we go to command prompt and enter our directory where the file has been saved. Then we use the command ‘javac filename.java’ to compile a java file.
If the path is not set it gives the message as “javac is not recognize as an internal or external command, operable program or batch file” so it is necessary to set a path for java in order to compile a java program.
We can set path in two ways
1) Temporary way
2) Permanent way
1) copy the path of jdk/bin directory
2) Go to run.
3) Enter ‘cmd’ to enter command prompt.
4) Type in command prompt: set path = copied_path/path where java has been installed
*you can copy and paste your path here and that’s it the path is set temporarily.
But the drawback of this method is you need to type this every time you enter the command prompt
so to avoid this you can also set path permanently.
You can run Java applications just fine without setting the PATH environment variable. Or, you can optionally set it as a convenience.
Set the PATH environment variable if you want to be able to conveniently run the executable (javac.exe, java.exe, javadoc.exe, and so on) from any directory without having to type the full path of the command. If you do not set the PATH variable, you need to specify the full path to the executable every time you run it, such as:
C:\ Program Files \Java\jdk1.7.0\bin\javac MyClass.java
The PATH environment variable is a series of directories separated by semicolons (;). Microsoft Windows looks for programs in the PATH directories in order, from left to right. You should have only one bin directory for the JDK in the path at a time (those following the first are ignored), so if one is already present, you can update that particular entry.
The following is a Variable value for path variable:
It is useful to set the PATH environment variable permanently so it will persist after rebooting. To make a permanent change to the PATH variable, follow the following steps:
1. Go to the hard drive where you actually installed java
2. Go to jdk1.7.0 *any version* folder -- bin then copy the address from the address bar. Which is our path.
3. Select My Computer and right click and click on properties
4. Click on Advanced system settings -- Advanced tab
5. Click on Environment Variables
6. Under System Variables, find PATH, and click on it.
7. In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
8. Reopen Command prompt window, and run your java code.
Tags: How to set Java Path?, Java (Programming Language), Path setting in java