• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classpath!!

 
Ravi Kumar Ravuru
Ranch Hand
Posts: 176
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Regards,
Ravi
 
Uma Balu
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
Uma...
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic