Structure of Java Program

141 views.

Specifying the package name in a program is optional. A java program can contain at most one package statement. The package statement should be the first executable statement in program.

Specifying the import statement in a java program is optional. A java program can contain any number of import statements. The import statements should be specified after the package statement and before the class.

A java program can contains any number of classes and every class can contain variables and methods, which are together called as member of the class. A class can contain any number of methods.

Execution of java is done by JVM and begins from main method, whose syntax must be as follows

access specifier             modifier                     return type           method name     parameter

public                             static                             void                         main                 (string[] args)

The main method can obtain any number of statements and every statement must be terminated by a semicolon.

 

A Java program can contains any number of comments, and they can be specified anywhere in the program. The comments are non executable statements.

 

Leave a Reply