Wednesday, October 20, 2021

Structure of a Java program

Java is an object-oriented programming, platform-independent, and secure programming language that makes it popular. 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 Java program in detail. In this section, we have discussed the basic structure of a Java program. At the end of this section, you will able to develop the Hello world Java program, easily.

A typical Structure of a Java program would contain the following elements:

  • Package declaration
  • Import statements
  • Comments
  • Class definition
  • Class variables, Local variables
  • Methods/Routines/Behaviors

The below picture would show the above mentioned elements that make out the structure of Java program.

Package Declaration

Classes in java could be placed in different directories/packages based on the module they are used in or the functionality it provides. For all classes that belong to a single parent source directory, path from source directory is considered as package declaration.

Structure of a Java program

Import Statements

There would be classes written in other folders/packages of your working java project and also there are many classes written by individuals, companies, institutions, enthusiasts etc., which could be useful in our program. To use them in a class, we would need to import the class that we intend to use. Many classes could be imported in a single program and hence multiple import statements could be written.

Class Name

A name should be given to class in java file. This name is used while creating an object of the class, in other classes/programs.

Variables

Variables are the means of storing the values of parameters that are required during execution of the program. Variables declared with modifiers have different scopes, which define the life of a variable. We shall see in detail about the modifiers like global, local, static and private at Variables in Java.

Main method

Execution of a java application starts from “main” method. In other words, its an entry point for the class or program that starts in Java Run-time.

Method/Routine/Behavior

This is a room for a set of instructions which form a purposeful functionality or a routine that would be required to run multiple times during the execution of the program. To not repeat the the same set of instructions when the same functionality is required, the instructions are enclosed in a method. A method’s behavior could be exploited by passing variable values to the method (also called arguments of a method).

3 comments:


  1. Thanks for this information. it is helpfull and worthy
    Laptop Repair Center offers quality service for your laptop at a reasonable cost. We offer doorstep support, 24*7 onsite support, repair all brand laptops, have an expert team for onsite support, and much more. for more contact us on 7291903784
    laptop repair center in Delhi

    ReplyDelete
  2. thank u for this valuable information..very helpful
    Family Chaat is one of the best selling north indian food booth such as Pani Puri, Aloo Tikki Chaat, Bhalla Papari, Gol Gappa Chaat, Cholay Tikki, Papri chaat, Samosa cholay, Samosa chaat, Raj kachori chaat, Pao Bhaji, Vada Pao, and Samosa Bada Pao. Family Chaat is made available to every customer with unique flavor, quality taste, and hygiene and we are the best chaat provider in India.
    street food indian

    ReplyDelete
  3. i found it very helpful. thank u

    Mast Banarasi Paan is one of the best selling paan such as Rajwadi paan, Laddu paan, Choclate Paan, Fire paan, Silver paan. Mast Banarasi Paan is made available to every customer with unique flavor, quality taste, and hygiene and we are the best paan provider in India.
    banarasi paan

    ReplyDelete