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.
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.
nice info .. thnks
Posted by
N!T!N |
9:39 PM
Yes Indeed Nice & Detailed info! Thanks :)
Posted by
Mudasser Arshed |
10:53 PM
This comment has been removed by the author.
Posted by
Unknown |
2:01 AM
really nice info.....my doubt got clarified..thanks
Posted by
Unknown |
2:04 AM
this didn't help at all. why don't programmers speak in ways i can understand...
Posted by
oneofthree |
7:35 AM
The keyword static allows main( ) to be called without having to instantiate a particular instance of the class.
Wht u understand by the given statement..???
Wht u understand by the instance of the class????
Kindly reply me asap vishalb1204@gmail.com
Posted by
Vishal |
9:05 AM
It was nice n detailed........thnks
Posted by
Unknown |
8:41 PM
thanks for this useful info
Posted by
Unknown |
9:06 AM
Thanks men, i was a c++ guy and was wondering what the hell all these details were, i think this will give me a headstart with java, edu
Posted by
jumbeb |
10:05 PM
it's good info
Posted by
chandu |
3:08 AM
Nice information!!!
Posted by
Unknown |
2:44 AM
Thank U...
Posted by
chiri |
4:24 AM
really nice
Posted by
Unknown |
1:19 AM
Well framed!!!
Posted by
Unknown |
11:00 PM
i gives very important info.
Posted by
Pankaj Mishra |
11:10 PM
excelent information
Posted by
azaman4u |
5:02 AM
Im a beginner for JAVA.
This is so useful and easily to understand. thanks for the info =)
Posted by
-JesSie- 。◕‿-。 |
6:57 AM
this is what many books hane failed to write,indeed a great note.
Posted by
harshal |
10:54 AM
nice piece if info.
thanx...
Posted by
Anonymous |
9:24 PM
it was a very useful info..thanks
Posted by
Unknown |
9:43 AM
thanks nic info:)
Posted by
prince2810 |
6:56 AM
It is very useful for java learners..............thanQ
Posted by
Unknown |
12:10 AM
It is very useful for java learners..............thanQ
Posted by
Unknown |
12:11 AM
It is very useful for java learners..............thanQ
Posted by
Unknown |
12:11 AM
good one dude..!!
Posted by
Unknown |
9:36 PM
good details dude.
Posted by
Shikku |
3:11 AM
why execution of prograam start from main method?and why main is public
Posted by
Hazaribagh Jharkhand |
8:07 PM
why execution of prograam start from main method?and why main is public
Posted by
Hazaribagh Jharkhand |
8:07 PM
informative blog......keep it up
Posted by
anand |
1:17 AM
nice....
but I cant understand that why we cant pass arguments as 'int' or 'char' or anyother and only 'String' ?
Please reply on shashwat.mehta91@gmail.com
Posted by
Shashwat Mehta |
2:27 AM
thanks for the info..it would be more helpful if i come to know the use of 'String args[]'...
Posted by
equestionpapers |
7:34 AM
thanks for the info...it would be more helpful if i come to know the use of 'String[] args'
Posted by
equestionpapers |
7:35 AM
y string s used in command line,instead of string while we use int,float we are getting error report,why?
Posted by
VannaNilavan |
8:04 PM
copied from complete reference book of herbert....but thx.....Read books guys
Posted by
ykey |
11:42 PM
it is very use full to understand the necessity of public before main method. Thank you:>>
Posted by
jailani |
1:52 AM
use full information for java beginners
Posted by
sumit mishra |
6:05 PM
really nice information for java beginners..
Posted by
boopathyspeaks |
12:41 AM
really nice for java beginners..thanks..:)
Posted by
boopathyspeaks |
12:42 AM
it becomes more easier 4 the beginers of java candidates.....
Posted by
Rishi |
9:24 AM
Very well explained.
Posted by
Sylvester |
1:09 PM
Very well explained.
Posted by
Sylvester |
1:10 PM
I will thank u only if u will give the answer of my ques. Is "public static void main(String [] args)" user defined or pre defined??????
Posted by
arif hussain |
5:38 AM
Click to view meaning of public static void main(String args[]) in details.
Posted by
Unknown |
7:09 PM