Tutorial Addendum On Java - Beheading Of Java Programs

ios appcolt educationappsios financeappsios
 31 December 18:00   




Execution Access Point



As mentioned in the antecedent section, a Java appliance program haveto accept


a starting chic with a appropriate adjustment alarm main() as the beheading access point.


The main() adjustment haveto be authentic as follows:




accessible changeless abandoned main(String a) {


// account block






Note that the main() adjustment is a chic method, authentic as "static". So if it


is alleged by the JVM, no instance of the starting chic will be created.



The constant of the main() adjustment is an arrangement of "String", which contains the


additional arguments afterwards the chic name altercation in the "java" command line.


Let s use the afterward Java program to allegorize how those arguments are


passed into the main() method:






* CommandLine.java


* Absorb (c) 2002 by Dr. Yang




class CommandLine {


accessible changeless abandoned main(String a) {


System.out.println("Number of arguments = "+a.length);


for (int i=0; i<a.length; i++) {


System.out.println(" a = "+a);










After accumulation the class, assassinate it with the afterward command line:




c:j2sdk1.4.1_01injava -cp . CommandLine aliment milk assistant apple








Number of arguments = 4


a = bread


a = milk


a = banana


a = apple




4 arguments are defined in the command band afterwards the chic name.


The JVM put them in an arrangement of 4 elements and canyon the arrangement as


a constant to the main() method.



Execute it afresh with a hardly altered command line:




c:j2sdk1.4.1_01injava -cp . CommandLine "bread milk" "banana apple"


Number of arguments = 2


a = aliment milk


a = assistant apple




This time, bifold quotes are acclimated to create two amplitude belted words as


a individual argument.




Tags: array, bread, method, banana, command, public, string, arguments

 class, method, arguments, command, execution, banana, commandline, bread, array, static, string, , main method, command line, bread milk, bread milk banana, commandline bread milk, void main string, static void main, public static void,

Share Tutorial Addendum On Java - Beheading Of Java Programs:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Article In : Computers & Technology  -  java