Saturday, October 25, 2008

JAVA PROGRAM STRUCTURE




Java program may contain many classes of which only one class
defines a main methos. Classes contain data members and
methods that operate on the data members of the class.Methods
may contain data type declarations and executable statements.
To Write a Java program we first define classes and then put
them together.A Java program may contain one or more sections

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 help
in maintaining the program.In the addition to the two styles of comments
discussed earlier, Java also uses a third style of comments/**....*/
known as documntation comment.This form of comment is used for generating
documentation automatically.

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;

Import Statements


The next thing after a package statement may be a number of
import statement This is similar to the #include statement in C. Example
import student.test;
This statement instructs the interpreter to load the test class
contained in the package student.Using import statements,we can
have access to classes that are part of other named packages.

Interface Statement


An interface is like a class but incudes a group of method declarations.
This is also an optional section 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 methos as
its starting point,this class is the essential part of a Java
program.A simple Java 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 termiates and the control passes back to the operating system.