View RSS Feed

My Java Tips

Path vs ClassPath

Rate this Entry
by , 11-07-2011 at 06:47 PM (511 Views)
I have found may people asking the difference between ClassPath and path. They tend to mix these and find this confusing. I will address this issue in this post.


Path is simply a system wide variable that tells where to find your commands. Like you can run directory command (dir) from an path. This is so because Windows path is set in the path variable. To see the contents of path variable, use following command on command prompt:


echo %PATH%

Now lets talk about Classpath. It is Environment Variable that tells JVM or Java Tools where to find your classes. You may include different useful packages in the classpath for easy referencing. To view the contents of the classpath, use following command on command prompt:


echo %CLASSPATH%

Example:
Assume that Java is installed in C:\jdk1.5.0\ and your code is in C:\Test\example.java, then your PATH and CLASSPATH should be set to:


PATH=C:jdk1.5.0bin;%PATH%
CLASSPATH=C:Test

I hope this helps.

Submit "Path vs ClassPath" to Facebook Submit "Path vs ClassPath" to Digg Submit "Path vs ClassPath" to del.icio.us Submit "Path vs ClassPath" to StumbleUpon Submit "Path vs ClassPath" to Google

Tags: None Add / Edit Tags
Categories
Java SE

Comments