In this topic, you will learn about, Java Program Structure.
A java program may contain one or more sections as shown below.
- Documentation Section: In this section comments are written. Comments include the name of the program, author of the program, date of the program, etc. Java also supports a special type of comment called documentation comment(/** …*/) other than a single line and multi-line comments.
- Package Statement: In this section, a new package is created. To create a package, a package statement is used.
- Import statement: In this section packages are imported. The package is a collection of classes and methods. To use any predefined function or a class, a related package is imported. For example, for doing input-output, import java.io.*; statement is used.
- Interface Statement: It is like a class but its variables are final and methods are abstract. In java, we cannot create a new class from two or more existing classes but we can create a new interface from two or more existing interfaces.
- Class Definition: Class can be defined as a user-defined data type that can hold data as well as functions. It is used to represent real-world objects.
- Main Method Class-As like C and C++, Java also used the main method. As we know that in java, we cannot create any things without a class. So unlike C++, main() method is also created in a class. The class contains the main method is called main() method class.