Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

In Java why we write public static void main(String args[])
why not main()?

Answer Posted / gowrishankar

The Main method is the method in which execution to any java
program begins.
A main method declaration looks as follows:

public static void main(String args[]){
}


The method is public because it be accessible to the JVM to
begin execution of the program.

It is Static because it be available for execution without
an object instance. you may know that you need an object
instance to invoke any method. So you cannot begin execution
of a class without its object if the main method was not
static.

It returns only a void because, once the main method
execution is over, the program terminates. So there can be
no data that can be returned by the Main method

The last parameter is String args[]. This is used to signify
that the user may opt to enter parameters to the java
program at command line. We can use both String[] args or
String args[]. The Java compiler would accept both forms.

Command line argument
Any number of arguments can be passed to the java program
through command line. While running the program any things
written after the name of the class are the command line
arguments. Arguments are delimited by the space.
This sample code prints all the command line arguments to
the console.
public class CmdLn{

public static void main(String[] args) {
System.out.println("d");
for (int i = 0; i < args.length; i++)
System.out.println(args[i]);
}

}


Java CmdLn arg1 arg2 arg3 arg4
Output:
arg1
arg2
arg3
arg4



so,if we simply give the main() function program wont work
without the access specifier.

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How does regex work?

907


What is a class component?

1114


Give example to differentiate between call by value and call by reference.

971


Can we create object of inner class in java?

882


Can you access the private method from outside the class?

906


Can a abstract class be declared final?

944


Difference between a class and an object?

966


How to restrict a member of a class from inheriting by its sub classes?

1284


What is rule of accessibility in java?

962


Does a class inherit the constructors of its superclass in java programming?

1009


What is the base class in java from which all classes are derived?

920


What is an inner class in java?

907


why doesn't java run on all platforms?

978


How will you load a specific locale?

925


What is tcp and udp?

951