Search This Blog

Loading...

Saturday, December 13, 2008

Java Source File Structure and Declaration rules

Java Source File Structure and Declaration rules

Package Declaration:

Package declaration is optional; if source file contains the package declaration then it comes first. There can be at most only one package declaration per source file. This package declaration is applicable to all the classes in the source file.

Import statements:

Import statements are optional; if source file contains import statement then import statements comes after the package declaration and before the class declaration. If there is no package declaration then import statements comes first in the source file. These import statements are applicable to all the classes in the source file.

Class Declaration

Class declaration comes after the package declaration and import statements.

  1. Java source file can contain only one public class
  2. Java source file can have more than one non public classes
  3. If there is a public class then name of the public class must match with the name of the class

Comments:

Comments and white spaces can appear before, after or in between the above declarations.

0 comments:

Template by - Abdul Munir | Daya Earth Blogger Template