Path and classpath

What is the main difference between path and classpath in java language?

Questions by anandkumarjha   answers by anandkumarjha

Showing Answers 1 - 1 of 1 Answers

gadhiaharsh

  • Jul 22nd, 2011
 

Hi friends, here's an answer for the question

PATH defines where exactly the complier should find the tools to compile and run the java programs.

CLASSPATH defines where exactly the classes required to compile a particular program are located.

for eg:
in command prompt if we write ' set path=C:Program FilesJavajdk1.7.0in '
this tells the compiler that the tolls such as javac and java are located at the given path.

in command prompt if we write ' set classpath=C:UsersDocumentsJava Class Files '
this tells the compiles that all the classes required to compile a particular program are located in the above directory.

Hope this satisfies.

Code
  1. public class Demo

  2. {

  3.  

  4. public static void main(String args[])

  5. {

  6. someClass c;       //this is a variable of type someClass which is a class in some other directory

  7. c=new someClass();

  8. System.out.println("Hello Friends");

  9. }

  10. }

  11.  

  12.  

  13. /*

  14. Note:

  15. In the above code snippet the class called 'somesomeClass' is located in some directory other than the current directory.

  16.  

  17. So to compile the above code, we hav to define two things,

  18. 1. 'path' i.e path to the jdk1.x.xin directory.

  19. 2. 'class path' i.e path to the directory where that class is located.

  20.  

  21. Thanks

  22. */

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions