Compilation unit in Java
When writing a Java source code file, this file ends with .java and is called is the compilation unit.
1. There can be one public class in the compilation unit, and there can only be one public class. As the interface for the outside world to access the class, the name of the class must be the same as the file name.
2. There may be no public class in the compilation unit, but there must be a class with the same name as the file name.
3. There can be some additional classes in the compilation unit, and these classes are in the package access permissions.
Code Organization
1. When compiling (javac) a .java file, each class in the compilation unit (i.e. .java file) will have An output file .class file, each output file has the same name as each class in the .java file.
2. A Java executable program is a set of .class files that can be packaged and compressed into a Java document file (JAR file). The Java interpreter is responsible for finding, loading and interpreting these files.
Java interpreter running process
1. Find the environment variable CLASSPATH (set through the operating system, or not set, the general compilation environment will set it for you), CLASSPATH contains one or more directories used to find the root directory of .class files.
2. Starting from the root directory, the interpreter obtains the name of the package and replaces each period with \
3. The obtained path is connected to the different items in CLASSPATH. Explain The programmer searches these directories for the .class file [2] related to the class name you created.
The above is the detailed content of What is a compilation unit in java. For more information, please follow other related articles on the PHP Chinese website!