A Java application consists of several classes, which can be in one source file or distributed among several source files.
A Java application has a main class, which is the class that contains the main method. The Java application starts execution from the main method of the main class.
When writing a Java application, you can write several Java source files, save the Java source files involved in the application in the same directory, compile them separately, and obtain the bytecode files required by the Java application, and then run them Main class.
A Java program can store the classes it uses in different source files, or it can store the classes it uses in one source file. Classes in one source file can be used by multiple Java programs.
From a compilation perspective, when the program needs to modify a certain class, it only needs to recompile the source file where the class is located, and there is no need to recompile the source files where other classes are located, which is very beneficial to system maintenance.
Notice:
Although there can be multiple classes in a Java source file, it is still recommended to write only one class in a Java source file.