File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes path vs classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "path vs classpath" Watch "path vs classpath" New topic
Author

path vs classpath

Gaurav
Greenhorn

Joined: Apr 17, 2007
Posts: 5
To run a simple program we need to set the path in environment variables
we may specify it in path or classpath variable,

what is the difference between the two

i.e path C:\Program Files\Java\jdk1.5.0_06\bin;
and classpath C:\Program Files\Java\jdk1.5.0_06\bin;

And also in Environment varibale we have User variables and System variables, what is the difference between the two.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

The PATH variable contains directories where binary files (e.g. EXE files in Windows) will be looked for.
If you open a command prompt and type "javac", you're supposed to have the "bin" directory of your sdk into the PATH, otherwise you'll get an infamous "Command not found" error message.

The CLASSPATH contains directories (or JAR files), from where your java compiler/runtime will look for .class files (and some others).
For example, "java Hello.class" will not work unless you set the directory (or JAR file) Hello.class is in, into your CLASSPATH.


[My Blog]
All roads lead to JavaRanch
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Just to add - it is unusual to have a "bin" directory in your CLASSPATH, usually it would contain directories like "lib", "jar"...


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: path vs classpath