Sunday, October 24, 2010

PATH and CLASSPATH EXPLAINED

Hello IT Folks & computer nerds (computer KIDE in Marathi), I am back once again with something to 'EXPLAIN' to you guys. Recently I came across writing and compiling Java programs. I usually prefer Netbeans IDE for working with Java which does all compilation and execution for me on just a click of the button. Its been really long to have worked with compiling and running Java programs from the command line. But this time I felt the need to run the programs from the command line and all I could say was Oh My GOD...!

    So I begun hunting down Java tutorial websites, Java Discussion forums, Coding forums. I did not know what CLASSPATH & PATH mean and why do I necessarily need to do it. Setting only the values of these variables was not something I was looking for, but I wanted the explanation of the terms CLASSPATH & PATH which I came to know about with the help of my friend. So here we go with today's blog post.


     In simple language PATH is an Operating System variable whose value refers to the location of the executable (.exe) file to be launched from the Command Prompt. This is that location where the OS looks for file 'java.exe' or 'javac.exe' when you type 'java' or 'javac' in the command prompt (For more technical definition of PATH refer wiki here)

Same is the case of variable CLASSPATH. In simple language CLASSPATH refers to the location where the .class files of the compiled Java program are kept. Most of the programmers who use command line for java programs will set CLASSPATH to current directory (denoted by a dot). (For more technical defination of CLASSPATH refer wiki here)

1 comment:

  1. Hi,

    Its worth noting that if you have two classes with same name in classpath in that case one which comes earlier in classpath will get picked up. this concept is very useful to test patch releases where you update only few classes to quickly test patch release or have added some debug print statement to troubleshoot any issue. to read more about How classpath works in Java

    Thanks
    Javin
    FIX Protocol Interview Questions

    ReplyDelete

LinkWithin

Related Posts Plugin for WordPress, Blogger...

Share This

Share |