Java Program Structure

In this tutorial you will learn about the Java Program Structure and its application with practical example.

Java Program Structure

In Java, like any other programming language, we have a specification available for program structure, every java program consists of the following building blocks –

Table Of Contents

java-structure

 

Documentation Section:- Documentation section is generally meant to include a set of comments, that is used to provide information about the program written as the name of a program, the utility of the program, date of creation, date of last modification, author name, licensing or copyrights information and any other information that programmer wish to put for the references.

Example:

Package Statement:- This is the section used for package declaration, the package statement declares a package name and notifies the compiler that the classes defined here will belong to this package.

Example:-

Import Statements:- The import statements are used to import packages that contain all of the required classes, and interfaces. java.lang.*; the package is imported by default and this package is known as the default package.

Example:-

Interface Statement:- An Interface is like a class that usually contains a group of method declarations. It’s an optional section and can be used when we want to implement multiple inheritances within a program.

Class Definition:- The classes are used to map real-world entities into programming. The Classes are the key building block of any Java program. A java program may include several class definitions.

Main Method Class:- A java program may include multiple classes, but there can be only one class that will define the main method.

Main Method Definition:- This is the most vital part of each and every java program, it is mandatory for the java program to have a class with a primary method definition. There can be only one class that will define the primary method. The Java program execution starts with the main method. Java program can not be executed without the main method. The main method is responsible for the execution of all the user-defined statements, functions, and library functions. The main method is further structured into – variable declaration, function declaration, and user-defined executable statements.

In this tutorial we have learn about the Java Program Structure and its application with practical example. I hope you will like this tutorial.