Java Program Structure
A
java program may contain many classes of which only one class define a main
method. Classes contain data member and data methods that operate on the data
members of the class. Methods may contain data type declarations and executable
statements.
A Java program consists of different sections. Some of them are
mandatory but some are optional. The optional section can be excluded from the
program depending upon the requirements of the programmer.
A
java program may contain one or more section and they are:-
1. Documentation Section
2. Package Statement
3. Import Statement
4. Interface Statement
5. Class Definitions
6. Main Method Class
o Documentation Section- The documentation section comprise asset of comment lines giving the name of program, the author and other detail which the programmer would like to refer to all later stage. Comments must explain why and what of classes and how of algorithms. This would greatly help in maintaining the program..
In addition to the two style of comments discussed
earlier. Java also used third type of style of comment /**……*/Known as documentation section. This form is used
for generating documentation
automatically.
o Package Statement- The first step allow in java file is Package statement. This statement is declare as package name and informs the compiler that the classes defined here belong to this package.
Example:
Package
student;
The package statement is optional. That is, our
class do not to be part of package.
o
Import Statement- The next thing after
package statement(but before any class definition) may be a number of Import statements. This is similar to
the #include statement in C.
Example:
import student.test;
This statement instructs the interpreted to load the
test class contained in the package student. Using import statement we can have
access to classes that are part of other name
packages.
o
Interface Statement- A interface is like a class
but include a group of method declarations. This is also an optional section and is used when we wish to implement
the multiple inheritance feature in the program.
o
Class Definitions- A java program may contain
multiple class definitions. classes are the primary and essential element of a
java program. These classes are used to map the object of real-world problem.
the number classes used depends on the complexity of the problem.
o
Main Method Class- Since every java stand along
requires a main method as its starting point, this class is the essential part
of java program. A simple java program may contain only this part. The main
method of this class create object of various classes and establish
communication between them.
/* Simple program in java to
print hello.*/
java program structure |
Output:
java program |
No comments:
Post a Comment