Classpath is a parameter that helps Java compiler and JVM to look for user-defined class, interfaces, and packages. There are two ways by which you can set classpath-
Before we learn how to set classpath, let's understand JVM, JRE, and JDK.
JDK stands for Java Development Kit. It contains JRE plus all the tools required to compile and debug applications written in Java. It is designed for a particular platform, and this is the reason we have separate installers for each operating system.
JRE stands for Java Runtime Environment. It is a subset of JDK. It does not contain tools required to develop Java programs. It is only used to run Java program. If you are having JRE installed on your computer, then you can execute programs written in Java. It contains JVM and all the necessary libraries required to run Java program.
JVM stands for Java Virtual Machine. It converts bytecode into a form that machine can understand. Even though Java is platform independent, but JVM is platform dependent. It is responsible for performing following functions-
To set classpath on a command line, you can follow any one of the following methods-
javac -classpath c:\myassignment test.java java -classpath c:\myassignment test
There is another way of setting classpath, all you need to do is just follow the below steps-