Divaksh
/What is the meaning of PATH and CLASSPATH?

What is the meaning of PATH and CLASSPATH?

Compiled on Oct 28 2012 in Java

In this Java tutorial we will learn What is Classpath in Java and How Classpath works in Java.
Java is an OOP language. In java programming language compiler compiles and converts the source code into the byte code, that byte code is interpreted by JVM that converts the bytecode into the machine independent code.

The CLASSPATH is an environment variable that tells the Java compiler javac.exe where to look for class files to import or java.exe where to find class files to interpret.

In contrast, the PATH is an environment variable that tells the command processor the where to look for executable files, e.g., *.exe, *.com and *.bat files. The Classpath is one of the most confusing things in Java. Unfortunately, you must master it to even compile HelloWorld.

In Java how the Java compiler and the JVM use the class search path to locate classes when they are referenced by other Java code. Searching class path is important for all Java developers. Many development tools have their own ways of manipulating the class path, which vary from product to product. For doing this we will use only simple command-line tools to carry out the compile operations. No difference, between the way that the Java compiler searches for classes, and the way that the JVM does it at run time. The compiler can compile classes from source code, where the JVM does not. We will use the compiler, but similar issues apply at run time.

Determining the current values of PATH and CLASSPATH

Unix

Type these commands in a command window:

echo $PATH
echo $CLASSPATH

If you get a blank command line in response to either of these, then that variable has no value (it has not yet been set).

Windows

Type these commands in a command window:

echo %PATH%
echo %CLASSPATH%

If you get the message "echo is on" for either of these, then that particular variable has no value (it has not yet been set).

In my next tutorial I'll tell you how to set PATH and CLASSPATH?