How to set javac path - setting up jdk path, How to set java path in environment variables


How to set javac path - setting up jdk path, How to set java path in environment variables

To compile and run a java program from command prompt we need to tell the java compiler and java interpreter path to the DOS System because javac and java commands are not defined in command prompt so we explicitly tell the javac and java path to the DOS command prompt.


Setting Up Java path:-


There are few steps to set the java path for command prompt.

The first method to set up path for one time...

>> Open Command prompt

>> Go to your directory where your program is saved.
If your program saved in "javawork" folder in D drive, change your directory like this.

c:\Program Files>D:

now you are in d drive and the path is now like this..

D:\>

Now change the directory like this

D:\>cd javawork press enter

Now you are in javawork directory and the path look like this.

D:\javawork>

now write your jdk path setting string like this

D:\javawork>set path=%path%;C:\Program Files\Java\jdk1.7.0\bin press enter
 
Now your path set for one time, this path scope will remain till the command prompt is open now, write your program name like this
 
D:\javawork>javac programname.java press enter
 
If your program doesn’t have any error then your program is compiled successfully and the screen show like this  

D:\javawork>

Now you need to run your program like this

D:\javawork>java programname press enter

If your program does not have any runtime error then you can see your desired output..


 This method to set up path for all time...


Go to your java installation files like by default the jdk is installed in c:\Program Files\java\jdk 1.7.0\bin

so if your jdk installed in same directory so simply go to your installation path and copy the path from windows explorer address bar.

after copying the path right click on My Computer and the click on properties.

if you are using windows xp then you are directly see a button with name Environment Variables,
if you are using higher version of windows then you see the Advance System Settings and then you can see Environment Variables Button.

click on this button and you see the user variables click on new button, a new window appear with two text boxes write path on first textbox and paste the copied path into the second textbox then ; and then ok ok ok.


Now your path has been set and you can directly run your program by following the above steps

{ 0 comments... read them below or add one }

Post a Comment