Java Documentation

1.3 PATH and CLASSPATH Variables

How environment variables connect your tools, compiler, and operating system, and when you actually need to set them.

Why PATH and CLASSPATH matter

In Java development, environment variables act as mediators between you, the compiler, and the operating system. Understanding the difference between PATH and CLASSPATH helps you control how programs are compiled and executed.

PATH

Tells the operating system where to find executable programs likejavac andjava. It points to the bin directory of your JDK/JRE.

CLASSPATH

Tells the Java compiler and JVM where to look for user-defined classes and libraries referenced in your source code.

When do you need to set them?

Command Prompt / Terminal

To compile and run Java programs from a plain terminal, the system must know where javac andjava live. This is why PATH (and sometimes CLASSPATH) need to be configured.

Inside IDEs

IDEs like Eclipse or IntelliJ usually manage PATH and CLASSPATH internally. You typically do not need to set these variables manually when compiling and running from an IDE.