CLASSPATH - Points to the jar files(tools.jar,rt.jar etc) needed for the execution of the java application.
PATH -Points to the Java installation folder where java executable files (java,javac etc.) are found.
Significance of Environment Variables in Java :
Java can be run without setting the environment variables too.
With setting the PATH variable ,Java can be able to run at any location on your drive i.e., java is available globally in your system.
- First, OS(kernel) checks for the executable by the name of command in the current directory.
- If not available it goes to the locations in the PATH variable if the executable is found in those locations , then that will be executed.
- Else displays the message
not recognised as internal or external command
- If any java class is not found,JVM checks for the class in the locations specified in this variable.
- If found success else java compiler raises an error like
cannot find symbol.
- This variable can hold directory locations,zip files,jar files separated by semicolon(;).