Prerequisite : Packages in Java
This post targets at telling what the CLASSPATH environment variable if responsible for. While programming in Java, we many times use import statements. An example is:
What does this import means? It makes the Menu class available in the package org.company 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 contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.
- How is CompileTime classpath different from RunTime classpath in Java?
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java.util.concurrent.Phaser class in Java with Examples
- Java.util.concurrent.RecursiveTask class in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java.util.concurrent.RecursiveAction class in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java.util.LinkedList.peek() , peekfirst(), peeklast() in Java
- Java.util.LinkedList.offer(), offerFirst(), offerLast() in Java
- Java lang.Long.byteValue() method in Java with Examples