
why to set classpath in java?

The Java runtime system needs to know where to find programs that the user want to run and libraries that are needed. It knows where the predefined Java packages are, but if you are using additional packages, you must specify where they are located. So for this, we have to set the environment variable CLASSPATH where JVM can easily find Java programs and libraries.