General Format of Java

General format of JAVA program 


General Format of Java

import statements 
global declaration 
class name
    
        public static void main (String args []) 
            
                    statements ------------- 
            }
    }    
 

  1. Import Statement: - Java provide us different library classes. These classes are different packages, so, if we want to use them we have to import them by using import statement.                               Eg: - import java.awt. *; import java.awt.button; 
  1. Global declaration: - In this section we can define classes & interface (user define data type) we can not define global variable & function like C & C++. 
  1. Function main:- This is the entry point of our program execution of the program being with function main. Java is complete object – oriented language. So even function main must be defined with in class.

  • void: - Indicates that this function main doesn’t return any value. 
  • static: -Indicates that this function can be called without creating object of that class.
  • public: - Indicates that the function is accessible. 
  • String args[]: - It is an array of string object containing command line argument.

Output statements: - 

  1. System.out.println (value): Will print the value & new line character. 
  2. System.out.print (value): Will print the value on console. 
  3. System.out.printf (“format String”,arg1,…): Will print the formatted String on console            
    For eg: 
            class test 
              
                    public static void main (string args [ ]) 
                      
                            System.out.println (“Welcome to JAVA”); 
                      
              

Post a Comment

Previous Post Next Post