Java All about Java Programs |
Advertisement |
|
Thread Tools | Display Modes |
|
(#1)
|
|
||||
CLASS 3: What Is public static void main(String[ ] args) -
>>
Show Printable Version
Email this Page
04-01-2014, 09:17 AM
What Is 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 can 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. 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. Syntax: public static void main(String[ ] args) { }
➳ bE driveN wiTh puRpOse, Be r313n71355 in your alιgnмenт; with excellence. pAy n0 mInd to the ∂ιsιмραssισηε∂ เ๓ק๏tєภt ђคtєгร ♬ ☣ .. нoolιgan ☠
|
Sponsored Links |
|
Bookmarks |
Tags |
args, mainstring, public, static, void |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Distributing From CM to Public | ĶįňĢ őf ĻōVęŘ | Political Issues Of Pakistan | 28 | 03-16-2013 02:15 PM |
~!~ [ Public Ads That Makes You Think... ] ~!~ | ~!~hasnain~!~ | Pics And Images | 8 | 04-04-2012 11:55 AM |
Public Transportation in Cuba | Aslam | Pics And Images | 4 | 12-29-2011 10:08 AM |
! pUBLIC TOILET ! | Hussain | Funny Sms | 17 | 11-09-2011 06:20 PM |
New Robot Arm Uses Static Cling to Grab Objects in Zero-G, From Satellites to Space Junk | eXquisite Inception | Space & Aviation | 2 | 10-15-2011 03:17 AM |