Wednesday 27 July 2011

Structure of JAVA program

 A JAVA program may contains many classes of which only one class defines a main method. Classes contain data members and methods that operated on the data members of the class. Methods may contain data type declaration and executed statements. To write a Java program, we first define classes and then put them together. A Java program may contain one or more sections as shown in figure.



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.

Package Statement:
               The first statement allowed in a Java file is a package statement. This statement declares a package name and informs the compiler that the classes defined here belong to this package.

Example:
            Package student;          
            The package statement is optional.

Import Statements:
               The next thin after a package statement (but before any class definitions) may be a number of import statement. This is similar to the # include statement in C.

Example:
Import student.test;

Interface Statements:
               An interface is like a class but includes group method declarations. This is also an optional section and is used only when we wish to implement the multiple inheritance features in the program.

Class Definition:
               A Java program may contain multiple class definitions. Classes are the primary and essential elements of a Java 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.

Main Method Class:
               Since every Java stand alone program requires a main method as its starting point, this class is the essential part of a Java program. A simple program may contain only this part. The main method creates objects of various classes and establishes communications between them. On reaching the end of main, the program terminates and the control passes back to the operating system.




0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More