What is difference between Path and Classpath ?

Answer : Below are differences:

Path

Classpath

To compile *.java file to *.class file we need java *.exe file which compile it in class file. To execute this command in operating system  one needs to setup and environment using path variable.To run generated *.class file in java environment java API classpath setting is required which set the path of jar files. In another words: Classpath is just setting up environment of java
Path refers to the operating systemClasspath denoted to the development environment
In path setting we only set path of executable filesOn the other hand classpath we set the path of jars for compiled classes

Please have example below to set path and classpath on window environment.

Setting path:

  • Open your command prompt (Click window –> Run –> Type cmd — click OK) it will open command prompt
  • First check if java path is set or not (Type java in command prompt press enter)

What is difference between Path and Classpath

  • As you see above show ‘java’ is not recognized means path is not set.
  • To set java path please enter command as shown in below (Please note:  my JDK installation directory is on : C:\Program Files (x86)\Java\jdk1.7.0 so that I am using its home directory and including bin folder where all java executable files are available)

What is difference between Path and Classpath

  • Above will set java path. Check again to confirm if java path set or not. Type java again in command prompt and press enter as show below:

What is difference between Path and Classpath

  • As you see above now its shows java command full option means we successfully set path.

Setting classpath:

  • Open your command prompt (Click window –> Run –> Type cmd — click OK) it will open command prompt
  • Enter below to set classpath of any jar file as shown below:

What is difference between Path and Classpath

  • To set classpath to the folder please see below:

What is difference between Path and Classpath

 

Leave a Reply

Your email address will not be published. Required fields are marked *