Java Source File Structure
A simple source file is considered to be a Java File, if it follows some rules and regulations. The Java Source file maintains a order and various elements that occur in that source file should follow the order. Java Source File structure should follow rules and order as follows :
1. Java source file should start with a package declaration. The package declaration is optional for Java source file. If the package declaration is default than the package declaration is optional.
2. After the package declaration there comes a section of import declarations. Import declarations can be zero ormore. These import statements introduce type or static member names in the source code. Its mandatory to place all import declarations
3. After import statements comes the type declarations statements. These statements have type declarations which are considered top-level. There can be any number of such type declarations, generally consisting of class , interface and enum etc. The order of type declarations is not mandatory.
4. The Java source file should have one and only one public class. The class name which is defined as public should be the name of Java source file along with .java extention.
For more of such hot topics read my other posts here :