Ad Code

Responsive Advertisement

JAVA PROGRAM STRUCTURE

 

Important terminologies in Java

Program, Class and Methods are the important terms essential to code a Java program. These terms can be easily understood by comparing Java with a supermarket.

Package

A super market comprises multiple sections and each section contains several varieties of products. Similarly, the various sections in the Java code are comprised together in a package. Java can be used in developing applications similar to Youtube. While using Youtube, several features like pause, search element, play option should be present. All these components are coded within a package.

Class

Generally, supermarkets are larger in length and when the items are not arranged in an organized manner, it becomes quite difficult to find them. Hence, they are partitioned based on varieties like biscuits, soaps, etc. Similarly, while developing complex projects several lines of code will be present and it becomes quite difficult to alter a particular part of the code. Hence Class is used to partition the entire package into sections.

Methods

While considering biscuit section alone, multiple biscuit varieties are present. Hence, they are partitioned based on the companies in supermarkets. Similarly, a class in Java is ordered and sectioned as methods. In simple terms, methods (biscuit varieties) are present within class (biscuit section) and all the classes are embedded in a single package (supermarket).



Structure of a Java program

Java programs are saved with .java extension file to enable our computer to realize it’s a Java code. The presence of package, class and methods is compulsory and must be used in a standard format.

package com.xoxowaves;

public class main

{

public static void method (string [] args)

{

/*code written here*/

}

}

This is the standard format of a Java program. The package keyword is used first and it must be used with com. format. Inside package, a class should be defined as public which means it can be accessed by anyone. ‘main’ can be replaced with any other name but be sure the class name and the file name (.java file) should be the same. In default, when the class name is not mentioned, it’s taken as main. Method is present within the class.

Working of the Java code within the compiler

The .java file is programmed to run in a compiler which further converts the file into .class file which is then processed as the output. This operation is done in order to achieve platform independency. Suppose, if the Java code is programmed in a Windows system, the same program can be used in Mac OS also. To achieve this criteria, .class file is generated by the compiler.


 

PREVIOUS                                                                         NEXT                                                                                                                                                                                                                                                                                                                                   

Post a Comment

1 Comments