Why Do We Use "Public Static Void Main(String[] A)" In Java?

14

14 Answers

Anonymous Profile
Anonymous answered
"main" method is declared as "public" to provide access to the JVM to call that method without being a member of that class..!

"main" method is declared as "static" to allow the JVM to call main without creating object..!

"main" method in java is designed not to return anything to the JVM,  hence the return type of the main function is "void"...!

We write String s[] -->By default java take's each argument as string...!
Rinav Gangar Profile
Rinav Gangar answered
Public static void main (String args[])

The public keyword is an access specifier, which allows the programmer to control the visibility of class members. 

When a class member is preceded by public, then that member may be accessed by code outside the class in which it is declared.

In this case, main( ) must be declared as public, since it must be called by code outside of its class when the program is started. 

The keyword static allows main( ) to be called without having to instantiate a particular instance of the class. 

This is necessary since main( ) is called by the Java interpreter before any objects are made.

The keyword void simply tells the compiler that main( ) does not return a value. 

As you will see, methods may also return values. 


As stated, main( ) is the method called when a Java application begins. Keep in mind that Java is case-sensitive. Thus, Main is different from main. 

It is important to understand that the Java compiler will compile classes that do not contain a main( ) method. But the Java interpreter has no way to run these classes. 

So, if you had typed Main instead of main, the compiler would still compile your program. However, the Java interpreter would report an error because it would be unable to find the main( ) method. 


Any information that you need to pass to a method is received by variables specified within the set of parentheses that follow the name of the method. These variables are called parameters. 

If there are no parameters required for a given method, you still need to include the empty parentheses. 

In main( ), there is only one parameter, albeit a complicated one. String args[ ] declares a parameter named args, which is an array of instances of the class String. Objects of type String store character strings.

In this case, args receives any command-line arguments present when the program is executed

Hope It Helps,

any further assistance, msg me... 

Anonymous Profile
Anonymous answered
When compared to C and C++ we compiled the programs where the compiler resides. In java we can compile the program from any where through out the system.That's why we declare the main as PUBLIC, however it states that it acces the class members. More over we use the STATIC keyword to call the Main() without creating the object by JVM. And the VOID defines the no return type to the JVM. Last but not the least the parameter STRING A[] which takes the run time input.
Anonymous Profile
Anonymous answered
Public is a access specifier and to access from any part of the programm
static is acces or invoked without any references or objects .
Void main is inbuild keyword to jvm to run from there as a starting point
string srg[] - it will take all values in the form of strings in one by one ,
Anonymous Profile
Anonymous answered
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.
Anonymous Profile
Anonymous answered
Because public is a access specifier and static is the keyword that executes instantly when java program run ...we can access  the main () in the another class if we need....so we declared it as a public
Joann Dsouza Profile
Joann Dsouza answered
A static function can be invoked without creating an object of the class. Since the main function is the one that begins execution of the program, it can be made into a static function so it can be invoked anywhere.
Shumaila Sadia Profile
Shumaila Sadia answered
Public is used so that to make the method available outside the class also while static is used so that class instance can access the method. On the other hand, by using void the application is not required to return a value while this is understood that application need an entry point that is provided by main().
 
 
John Peter Profile
John Peter answered
The main program must be invoked without being called. Only static functions can be called without creating the instance to the classes. So we are declaring it as static.
Anonymous Profile
Anonymous answered
Public:
Its a class access specifier, that show that main() access can be access out side of class...
Void :
Shows there is no return type...
Main() :
Its the boss function....

Answer Question

Anonymous