kirran

Monday, May 28, 2012

welcome to hello word program

Here let us c the how a basic java program works


class HelloWorld                            // here classname is hello world
{
   public static void main(String args[])
   {
      System.out.println("Hello World");
   }
}
 
 
Basic structure of java program is 
 
class classname                          
{
   public static void main(String args[])
   {
      statement 1;
      statement 2;  
      statement 3; 
      statement 4;  
 
 } 
 } 
 
 WHATEVER I SPECIFIED IN RED COLOR ,IT IS MUST FOR ANY A JAVA PROGRAM.
 
public: public is an access specifier,it can be available anywhere.
public functions are everywhere available.Jvm can be able to call correspondence 
main() function.
 
static: whenever we mention static keyword ,according to java it can be 
called by classname.Static functions are common functions,they can be called 
without the helpof object.according to java,JVM can be able to call main function
 with the help ofclassname.
  
void: whenever the main function execution is completed
 
In c/c++ it has to return a value to the os,since application is directly 
interacting with os .If main function is not returning a value ,
the os is unable to understand the program memory and it is ready to clean up .
That's why to cleanthe memory ,main function has to return a value in c/c++.
 
Best example is,my mom kept food for me,in the middle i went out what should
my mom think ? similarly os also unable to understand .This problem will be 
identified at large projects in real time,memory is not handling properly,
that is chance of system performance down.
 
but in java ,we will go for void after complication of program ,JVM will take care .
so no chance of memory wastage. 


 
 
main() : main is a name of a function,where program execution is started.

main is the starting point of the program execution and it is ending point 
of program execution.

Every program execution is done inside the stack memory.

when main() is started,stack memory is started,when main is completed stack memory 
also completed.
 

No comments:

Post a Comment