This means that when our working directory is D:\myprogram\ (on Linux, /home/user/myprogram/), we would not need to specify the classpath explicitly. If none are specified, the current working directory is used as classpath. The rule is that -classpath option, when used to start the java application, overrides the CLASSPATH environment variable. For the above example, we could also use on Windows: set CLASSPATH=D:\myprogram The environment variable named CLASSPATH may be alternatively used to set the classpath. Setting the path through an environment variable
Setting the path to execute Java programs Supplying as application argument The path for all user-defined packages and libraries must be set in the command-line (or in the Manifest associated with the Jar file containing the classes).
The virtual machine searches for and loads classes in this order: The classpath tells Java where to look in the filesystem for files defining these classes. Similar to the classic dynamic loading behavior, when executing Java programs, the Java Virtual Machine finds and loads classes lazily (it loads the bytecode of a class only when this class is first used).