Using the Java programming language, we can develop a wide variety of applications. So, before diving in-depth, it is necessary to understand the basic structure of the java program.
A typical structure of a Java program contains the following elements:
- Documentation Section
- Package Declaration
- Import Statements
- Interface Section
- Class Definition
- Class Variables and Constants
- Main Method Class
- Methods and Behaviours
The documentation section is important but optional for a Java program. It includes basic information about a Java program. The information includes the author's name, date of creation, version, program name, company name, and description of the program.
There can be only one package statement in a Java program. It must be defined before any class and interface declaration.
3. Import Statements
The import statement represents the class stored in the other package. We use the import keyword to import the class. It is written before the class declaration and after the package statement.
4. Interface Section
We use the interface keyword to create an interface. An interface is slightly different from the class. It contains only constants and method declarations.
5. Class Definition
In this section, we define the class. It is a vital part of a Java program. Without the class, we cannot create any Java program. We use the class keyword to define the class. The class is a blueprint of a Java program.
6. Class Variables and Constants
In this section, we define variables and constants that are to be used later in the program. In a Java program, the variables and constants are defined just after the class definition. The variables and constants store the values of the parameters.
7. Main Method Class
In this section, we define the main() method. It is essential for all Java programs. Because the execution of all Java programs starts from the main() method. In other words, it is an entry point of the class. It must be inside the class. Inside the main method, we create objects and call the methods.
8. Methods and behaviour
In this section, we define the functionality of the program by using the methods. The methods are the set of instructions that we want to perform.