• ClassPath is a keyword. It is used to specifying third party .class files to another class file (or) java file.
  • It is mainly used for java environment system only, but not for the Operating System.
  • Path variable is 100% used for operating System for specifying java commands to operating system.
  • We can set ClassPath in three ways.
    • 1.) Single command wise
      2.) Single command prompt wise
      3.) Entire system wise
    Set classpath Folder Structure

Example 1:

                    package com.sdj.calci;
                    public class Calculator 
                       public static int add(int val1,int val2)
                          return (val1+val2);

                    package com.sdj.account;
                    import com.sdj.calci.Calculator;
                    class Accounts 
                       public static void main(String[] args) 
                          int sum=Calculator.add(10,20);
                          System.out.println("Sum of 10,20 is:"+sum);
    E:/lab/1stbatch/dev1/src>javac –d ../classes com/sdj/calci/
    E:/lab/1stbatch/dev2/src>javac –d ../classes com/sdj/account/

    Here we will get No Class Definition Found Error i.e.
    • If we want to compile first we should have to finish the compilation of
    • Compiler will looks the file inside the E:/lab/1stbatch/dev2/src but the is available under E:/lab/1stbatch/dev1/src so we get No Class Definition Found Error.
    • In order to avoid this,we should specify where the class is available.

    1.) Single command wise :

    • E:/lab/1stbatch/dev2/src>javac -d ../classes –classpath ../../dev1/classes com/sdj/account/
    • Here we get an Error i.e. can’t find inside dev1/classes .Because it looks under the dev1/src which is not available.
    • E:/lab/1stbatch/dev2/src>javac -d ../classes –classpath ../../dev1/classes;. com/sdj/account/
    • In the above command compiler will go to Calculator.class and then go the current location i.e. E:/lab/1stbatch/dev2/src

    2.) Single command prompt wise :

    • Single command prompt wise makes .class files available untill and unless we close the command prompt.
    • Once we close the command prompt then that .class files will not be available whenever we open the new command prompt.
    • Syntax :
    •     Set classpath=”destination of .class file location”


        E:/lab/1stbatch/dev2/src>set classpath=../../dev1/classes;.
        E:/lab/1stbatch/dev2/src>javac –d ../classes com/sdj/account/
        E:/lab/1stbatch/dev2/classes>java com.sdj.account.Accounts
        Sum of 10,20 is:30

    3.) Entire System Wise :

    • Right click on computer then it will following .
    • javapadho
      Click on the properties
    • Click on the properties then it will show the following wizard.
    • javapadho
      Click on the Advance System settings
    • Click on the Advance System settings then it will show the following wizard then click on Advanced.
    • javapadho
      By clicking on Advanced
    • By clicking on Advance then it will show following wizard.
    • javapadho
      Environment Varialbles
      • Click on new option for entering new classpath entry, then it will show following wizard
      • Now enter variable name and variable value as shown in below.
      • We can enter N no.of variable values followed by semicolon.
      New User Variables
    • Click on ok button for completion of classpath entry.
    • javapadho
      User varialbles add
    • Finally click on ok button to exit from the environment variables.
    • javapadho
      ok button to exit from the environment variables