I just installed Java on a Mac for the first time (jdk 10.0.2 SE) and I'm on macOS 10.13.6. I just created a basic Hello World program in my home directory, compiled it and ran it, but I have nothing set on my CLASSPATH environment variable except for the current directory "." My question is how am I able to compile and run this program? How is it finding the classes from the Java library? I've always assumed I need to set this variable, and I have it set to my jdk installation directory in Windows.
WHY DO WE SET THE CLASS-PATH?
well this is an riveting question.
it is self explanatory as
CLASSPATH is an environment variable and contain
paths to the jar files and path to various packages.
Perhaps ,the reason behind successful execution of your code is that the JVM checks the current directory first for the perception of jar files and then follows the classpath .So your current directory has those files.
OH!You may wonder then why would we set the classpath .Setting the classpath overrides that by default path.
Happy Learning :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.