Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

How Java Source File Structure is written in a program ?.

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 or more. These import statements introduce type or static member names in the source code. Its mandatory to place all import declarations before actual class declarations in Java source code.

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.
 
© 2021 Learn Java by Examples Template by Hubberspot