Reputation: 23770
I have this file in my Home Directory on OSX:
public class TestClass {
public static void main(String[] args){
System.out.println("Hello World");
}
}
and in Bash I am running:
Korays-MacBook-Pro:~ koraytugay$ javac TestClass.java
Korays-MacBook-Pro:~ koraytugay$ java TestClass
Hello World
But I am wondering how the virtual machine instance running loads System from the CLASSPATH as my CLASSPATH environmental variable has no values:
Korays-MacBook-Pro:~ koraytugay$ echo $CLASSPATH
Well it returns an empty row. Nothing. When echo $PATH I will see:
Korays-MacBook-Pro:~ koraytugay$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
And java itself is in:
Korays-MacBook-Pro:~ koraytugay$ whereis java
/usr/bin/java
So in Windows java will look for the directories of CLASSPATH as far as I know. How does it work in OSX? How can Java load classes without the CLASSPATH variable?
Upvotes: 0
Views: 2329
Reputation: 2280
In addition to the classpath, the bootstrap classloader loads the core libraries from /jre/lib and /jre/lib/ext (link).
You can check the classpath at runtime like this:
System.out.println(System.getProperty("java.class.path"));
Upvotes: 1