JAVA program structure.
Hello programmers,
Today we are discussing the JAVA Program Structure. A JAVA program may contain many classes of which only one class defines the main method. Classes contain data members and methods that operate on the data members of the class.
![]() |
Java Program Structure |
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 as shown in the 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. A comment must explain why and what of classes and how of algorithms. Comments /**** .......... */ known as documentation comments.Package Statement:
The first statement allowed in a Java file is the package statement. This statement declares a package name and informs the compiler that the classes defined here belong to this package.Example.
com.amolsoftwares.www.demoapp; OR package student;
Import Statements:
The next thing after the package statement (but before any class definitions) may be a number of import statements. This is similar to the #include statement in C programming language.Example.
import student.test; OR import java.util.*; OR import java.util.io;
Interface Statements:
An Interface is like a class but includes a group of method declarations. This is an optional section and is used only when we wish to implement the multiple inheritance feature in the program. The interface is the new concept in JAVA and we discussed later.Class Definitions:
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.Example.
public class myClass
{
// class definition is here
}
Main Method Class:
Since every Java standalone program requires a main method as its starting point, this class is an essential part of the Java program. A simple Java program may contain only this part. The main methods create objects of various classes and establish communications between them. On reaching the end of main, the program terminates and the control passes back to the operating system.Example.
public static void main(String[] args)
{
//code of statements
}
0 Comments