If a java source file is dependent on an external JAR file, we need to provide the path of the external dependency to the java compiler:
javac -cp [path-to-external-JAR] foo.java
jar cvf foo.jar foo.class
Again, when we need to execute this jar file, we need to provide the path of the external dependency to the JVM:
java -cp [path-to-external-JAR]:foo.jar foo
The compiler needs the reference because it has to check that the classes and methods you’re calling or overriding exist, and can be called/overridden.
The JVM needs them because it has to execute the instructions inside these classes and methods.