Java Programming Thoughts-Chapter 6 Access Control

1. The package contains a set of classes, which are organized together under a single name space.

2. When writing a java source code file, this file is usually called a compilation unit. Each compilation unit must have a suffix of .java. In the compilation unit, there can be a public class, and the name of the class must be the same as the name of the file. Each compilation unit can only have one public class, otherwise the compiler will not be accepted. If there are additional classes in the compiler unit, these classes will not be visible in the world outside the package. This is because they are not public classes, and they are mainly used to provide services for the main public classes. It should be noted that although it is not very commonly used, it is possible to have no public classes in the compilation unit at all. In this case, you can name the file as you like.

3. When compiling a java file, each class in the java file will generate a .class file. A java executable program is a set of .class files that can be packaged and compressed into a java document file (jar package is generated after compression). The java interpreter is responsible for finding, loading and interpreting these files.

4. The first part of the package name is generally the Internet domain name in the reverse order of the creator. If you follow convention, Internet domain names should be unique.

      The running process of the java interpreter is as follows: First, find out the environment variable CLASSPATH. CLASSPATH contains one or more directories and is used as the root directory for searching for .class files. Starting from the root directory, the interpreter obtains the package name and replaces each period with a backslash to generate a path name from the CLASSPATH root. The obtained path will be connected with the items in the CLASSPATH. The interpreter looks in these directories for the .class files related to the name of the class you want to create.

5. There is no conditional compilation function like C language in java.

6. There are four permissions in java, private, protected, private, and package permissions. Note that in addition to providing access permissions for subclasses, protected also provides package access permissions.

7. There are only two types of access permissions, public and package access permissions

Guess you like

Origin blog.csdn.net/xiaoan08133192/article/details/108477203