Programming Structure in Java

September 10th, 2006 Admin Posted in Programming Structure in Java No Comments »

Programming Structure in Java

Programming Structure in Java

1. Documentation Section

The documentation section comprises a set of comment lines giving the name of the program,the author and other details, which the programmer would like to refer to at a later stage. Comments must explain why and what of classes and how of algorithms. This would greatly helpful in maintaining the program. In addition to the two styles of comments discussed earlier. Java also uses a third style of comment /**….*/ known as documentation comment. This fom of comment is used for generating documentation automatically.

2. Package Statement

The first statement allowed in a java file is a package statement. This statement declares a package name and informs the copyright that the classes defined here belong to this package.

Ex:-

Package classroom;

The package statement is optional.i.e our classes do not have to be part of a package.

3. Import Statements

There are number of import statement,it is similar to the #include statement in C.

Ex:-
import student.test;

This statement instructs the interpretor to load the test class contained in the package student. Using import statement,e can access to classes that are part of other part of other named packages.

4. Interface Statements

An interface is like a class but includes a group of method declarations. This is also an optional section and this is used only when we wish to implement  the multiple inheritence feature in the program.

5. Class Definitions

A java program may contain multiple class definitions. Classes are the primary and essential elements of a program. These classes are used to map the objects of real-world problems.The number of classes used depends on the complexity of the problem.

6. Main Method Class

Every Java stand-alone program requires a main method as its starting point,this class is the essentail part of a java program. A simple java progarm may contain only this part. The main method creates objects of various classes and establishes communication between them. On reaching the end of main,the program terminates and the control passes back to the operating system.

AddThis Social Bookmark Button