File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Classpath!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Classpath!!" Watch "Classpath!!" New topic


Ravi Kumar Ravuru
Ranch Hand

Joined: Apr 18, 2002
Posts: 176
What is the significance of classpath and path in Java?If i won't set the classpath and path and run my programs from the bin directory itself?Will my programs run?
Uma Balu
Ranch Hand

Joined: Aug 22, 2003
Posts: 61
The path is generally set for the exe files. To locate your javac and java commands, we set the path to the bin folder of jdk. Yes, you can execute the programs from bin itself, provided you have your java files in the same folder.
The classpath environmental variable is set for the javac/java to identify the external classes used in the program. For example, if you use System.out.println, you need to tell the compiler where exactly the System class is present, hence we set the classpath to the rt.jar file present in the jre/lib.
Hope this helps you.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Well, now a days Sun's Java compilers and JREs know where to find the J2SE packages, and adding rt.jar to the CLASSPATH is not needed or recommended.
The CLASSPATH will likely need to be addressed when using packages on your own project, or when using classes from others that are not part of the J2SE.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I guess, while running the application; Java Runtime Environment (JRE) does not need the class files. please correct me if I am wrong?
say I compiled the .java files ,which utilize some jar packages, on machine A; then moved these .class files to desktop B. where .jar files donot exist. They should run?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

No, they sure won't. If they were required for compilation on machine A, the JAR files will (very likely, unless the application is deliberately coded to allow for them to be missing) be needed on machine B.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Classpath!!
It's not a secret anymore!