Prerequisite : Packages in Java

This post is targeted at telling what the CLASSPATH environment variable is responsible for. While programming in Java, we many times use import statements. An example is:


What does this import mean? It makes the Menu class available in the package to our current class. Such that when we call

 Menu menu = new Menu() 

The JVM knows where to find the class Menu. Now, how will the JVM know this location? It is impractical for it to go through every folder on your system and search for it. Thus, using the CLASSPATH variable we provide it the place where we want it to look. We put directories and jars in the CLASSPATH variable.
Let’s say the above package resides in the directory dir. The complete path of the Menu class file would be dir/org/company/Menu. We’ll specify only the directory dir in our classpath variable, as rest information regarding the path is provided by the import statements. Similar for jar, if you create a jar and mention its path in the variable, the VM will look inside the jar file and find the class.

Hope it clears 🙂

Note : CLASSPATH is explained in more detail in Packages in Java


This article is contributed by ekta1994. If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Improved By : velociraptoryuzi

Article Tags :
Practice Tags :


Please write to us at to report any issue with the above content.