The role of claspath in Java

zhaozj2021-02-16  44

What is CLASSPATH? What is its role?

It is an environment variable for the Javac compiler.

Its role is related to IMPORT, PACKAGE keyword.

When you write Improt Java.util. *, When you face the Import keyword, you know that you want to introduce the class in the java.util this package; but how do the compiler know that you put this package in å? So you first have to tell the compiler in the location of this package; how to tell it? That is to set ClassPath :) If java.util this package is in the C: / JDK / Directory, you have to set the C: / JDK / this path to the classpath! When the compiler faces import java.util. * This statement, it will look up the directory specified by the classpath and check if the subdirector Java / Util exists, and then identify the compiled file (.class file) that the name is consistent. If you don't find it, you will report an error!

ClassPath is a bit like the setting of the include path in the C / C compiler, isn't it? How does it work when the C / C compiler encounters an incrude ? Oh, in fact, the reason is almost! Search the incrude path, review the file!

When you develop a package yourself, then you want to use the classes in this package; natural, you have to set this package to the classpath!

ClassPath's settings, a tricky thing for Java's beginners. So Sun makes Java2's JDK smarter. You will find that after you installed, even if you don't set ClassPath, you can still compile the basic Java program and execute.

By Jeny_man (CUGB) 18:27 1999-11-17

转载请注明原文地址:https://www.9cbs.com/read-27713.html

New Post(0)