blog header

Structure of Java Program

Structure of Java Program


Java is an object-oriented programming language that operates independently of the platform and is also a secure programming language.
These unique features of Java make it the most popular programming language for high-end software development.
There are a few important points to remember with respect to Java Programming.

•    Java is a case-sensitive language.
•    The class names in Java are defined with the first letter in capitals. Ex: MyProgram. Each word within the class name starts with a capital letter.
•    The method name in Java starts with a lower case. If the method name consists of several words each word after the first word starts with a capital letter.
•    Statements in Java are used to perform a single task. They always end with a semicolon.

The various sections of a Java program include:

•    Documentation
•    Package statement
•    Import statement
•    Interface statement
•    Class Definition

•    Main Method class


It is used to improve the readability of the program. This section consists of comments that help programmers to understand the functionality of that particular statement or method while debugging the code. It is easy for the programmers to review the errors and make changes accordingly.
The comments can be placed by the developer at any place in the code as it gives a better understating of the various statements. The compiler does not process these comments and hence these comments do not delay the processing speed.

There are three ways of including comments in a Java program

•    Single-line: It starts with a // 
•    Multi-line: The multi-line comment is embedded within a /* and */
•    Documentation comment: It starts with a /** and ends with*/

Package Statement

Declaring a package is optional for a Java program. The package should always be declared after the documentation section. A Java program can have only one package statement. A package is always declared before any class and interface declaration. It is necessary to declare the package as the Java class is placed in different packages and directories based on their functionality.

Import statements

The package contains many predefined classes and interfaces. The import statement is used to access any predefined class or interface in the program. For using any class or interface the import keyword is used, it is written before class declaration and after package statement.

The import statement is used to use a specific class that contains methods or functions necessary to process the Java program. It may be used to import a single class or the all the classes within a package.

The syntax for the import statement is as follows:

import class name; or 
import package name;
Interface section

Interface is a class that is used for a group of method declarations. The Interface section in a Java program is used for implementing multiple inheritances within a program. The difference between an interface and a class is that interface contains of constants and method declarations.
Interfaces cannot be instantiated but can only be implemented by classes or extended by other interfaces. The Interface keyword is used to create an interface. Implements keyword is used for using the Interface in the Java program. For using the Interface with other interfaces, extends keyword is used.

Class Definition

Class is an integral part of every Java program. More than one class definition may be included in a Java program. For defining a class in a Java program the class keyword is used. The class acts as the blueprint in a Java program. Information about user-defined methods, variables, and constants. There is at least one class in Java that has the main() method.

A class consists of variables and methods that operate on fields. A class consists of a collection of variables and methods.
The variables used in a class store the values of the parameters used during the execution of a program. These variables are defined using modifiers with different scopes based on their functionality in a program. 

Main Method

The Java program starts with the execution of the Main method. It is an essential part of every Java program. The execution of a Java program starts with the Main method. The various objects are created and the methods are called in the main method.
The syntax for the main method is as follows:
Public static void main(String args[])
The methods contain the set of instructions that needs to be performed. These instructions are executed at the runtime and perform the specified task.



Submit to our newsletter to receive exclusive stories delivered to you inbox!

We'll never share your email with anyone else.

Related Category Courses


Sign in to your account

Sign in to your account

Welcome back! Login with your data that you entered during registration.

Don't have an account? Sign up

Forget Password

We will send a password reset link on your email.

Create Account

Create Account

Use your email for registration.

Already on Sign in