Pin It

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.
Please Give Us Your 1 Minute In Sharing This Post!
Related Posts Plugin for WordPress, Blogger...
© 2012 Learn Java by Examples Template by Hubber Spot