Programming Structure of JAVA


Every language has fixed program structure which must be followed to develop program in that language. Java has also a definite program structure which are as follows.
Ø  Documentation Section                            -           Optional
Ø  Package Declaration Section                    -           Optional
Ø  Import Section                                          -           Essential
Ø  Interface Declaration Section                   -           Optional
Ø  User-defined Class Declaration Section   -           Optional
Ø  Main Class Declaration Section               -           Essential
Documentation Section :-
                In this section, we write the Commented Statements. It represents some extra information about our program or statement.
                        Any statement written within either of two symbols i.e. // or /* …….....*/ is called Commented Statement.
a.       // :- It can comment single line.
              Ex:-     //…………………..
                          //…………………..
                          //…………………..
b.      /*……….*/ :- It can comment multiple lines.
              Ex:-     /*………………
                          ………………...
                          ……………….*/
Commented statements are ignored by the compiler thus, it cannot be seen at run-time.
Package Declaration Section :-
                In this section, we create user-defined package.
                Package is a collection of several Classes.
Import Section :-
                In this section, We include the pre-defined packages and Classes. So, we could use the pre-defined methods.
                As we known that, class is a container of holding different methods and package is a container of holding different Classes.
The syntax of importing a package and Classes is as follows :-
                import java.packagename.classname;
                import. java.packagename.*;
                import java.packagename.classname.methodname;
Here, java is superpackage.
The list of Some pre-defined API package are as follows –
  1. java.lang.*;       -     Standard package (By default imported).
  2. java.io.*;
  3. java.util.*;
  4. java.net.*;
  5. java.awt.*;
  6. java.applet.*;
  7. javax.swing.*;


Interface Declaration Section :-
         In this section, we create an Interface. “Interface” is just Class like entity which is used to implement the multiple Inheritance.

User-defined Class Declaration Section :-
            In this section, we can create any number of users defined Classes.

Main Class Section :-
          It is essential part of Java program. In this section, We create the main class. A Class, in which main( ) method reside, is called Main Class.
The syntax of create a main Class is as follows :-
                Class <Classname>
                {
                        public static void main(String args[ ])
                        {
                                    …………………
                                    …………………
                        }
                }

Post a Comment

0 Comments