Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes classpath and Path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply locked New topic

classpath and Path

Tusshar Fasate
Ranch Hand

Joined: May 21, 2008
Posts: 81
can anybody tell me details of classpath and path.?
Are they same or any difference is there?

SCJP 5.0
Matthew Plant

Joined: May 07, 2008
Posts: 18
CLASSPATH is where java applications look to find compiled classes (ie. *.class, *.jar)

PATH is where the system looks to find executables (ie. java.exe, javac.exe) so when you type java from the command line, it can find it and you don't have to change to the correct directory first.
Tusshar Fasate
Ranch Hand

Joined: May 21, 2008
Posts: 81
How can i set path and classpath?
where to set it?
Does classpath come in to picture at runtime only or it plays any role compile time?
Matthew Plant

Joined: May 07, 2008
Posts: 18
Under Windows, Goto control panel, system, advanced, environment variables. Path and classpath will probably already be under system variables, you can edit these.

classpath maybe set to "." which means the current directory.

you can also set classpath at runtime when you run java.exe by using the command line switch "-cp [classpath]"

If your project uses external jars, you may need to set this switch when you use javac to compile your classes so javac can located the classes within the jar file.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

Please don't post the same question multiple times.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
It is sorta covered in the JavaRanch Style Guide.
subject: classpath and Path
Similar Threads
import in Windows environment
quick question about exercise 1-1
path and class path
JQPlus - after sales service - I don't think so.......
How can I use abstract class methods