Java main method explanation.
Java main method
For the basic programmers in java as well as for the interviews having the knowledge about the structure of main method is a must. Let us have a look at simple java program that will give an output of a sentence:
Class FirstProgram
{
public static void main(String args[])
{
System.out.println(”First java program”);
}
}
As shown in the above example the name of the java class is FirstProgram and there is java main method that has the print statement to give the output on command line.
Java main method as shown here is:
Public: Can be accessed outside the class and package.
Static: Can be accessed by the interpreter without creating object and there is only one reference to point to main method.
Void: Returns no datatype.
Argument: Java main method accepts arguments from command line called command line arguments in the form of array.
Java main method is the starting point of your application and triggers the execution of your program.










3 Responses
good
Reminds me of the time when I first learned C with the famous “Hello World” program…:)
Thanks for posting. I did not know mucvh of Java before this!!
Nice… I love java!
http://www.triond.com/users/sourav