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.

For more of such hot topics read my other posts here :

Visit my new website

Article Written By jontymagicman

I am DInesh Varyani.

Last updated on 26-07-2016 113 0

Please login to comment on this post.
There are no comments yet.
How To Pass Input From A Console To A Java Program ?.
What Do We Mean By Annotations In Java Programming Language ?.