0

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?

1 Answer 1

1

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"));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.