This is the code for the instantiation of the args array: Main(String[] args)
Java treats this like: String[] args = the command line parameters Method parameters are initialized by the values passed into the method. So args is instantiated when the function is called, not later on. "*When the method *or constructor *is invoked *(ยง15.12), *the values of the actual argument expressions initialize newly created parameter variables*, each of the declared Type, before execution of the body of the method or constructor. The Identifier that appears in the DeclaratorId may be used as a simple name in the body of the method or constructor to refer to the formal parameter." http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.4.1 Tommy P.S. I got this info from http://javadude.com/articles/passbyvalue.htm 2009/6/25 Surbhi Mittal <[email protected]>: > > > As you know that main is the method having array of Strings "args" as > parameter to this method. the parameters to any method are not instantiated > but their values are passed from the place where they are called. > > When you pass the values from command line, these values are handled as a > new array of values and passed to the args parameter of main method by the > java interpreter. > > > On Thu, Jun 25, 2009 at 8:57 AM, javanew2 <[email protected]> wrote: >> >> Hi all, >> >> In week 3's "Command-line Arguments" presentation the "args" array is >> discussed and the code below is used in an example. >> >> Week 3's "Java Arrays" lesson discussed the process of declaring an >> array and then instantiating an array. In this command line arguments >> lesson there is no mention of instantiation of the "args" array. >> What is the explanation for not having to instantiate this "args" >> array? >> Is this special instance of an array not need to be instantiated or is >> Java just "handling" this in the background? >> >> Thanks >> >> >> ***************************** >> ***************************** >> ***************************** >> To print the array of arguments, we write: >> public class CommandLineSample >> { >> public static void main( String[] args ){ >> >> for(int i=0; i<args.length; i++){ >> System.out.println( args[i] ); >> } >> } >> } >> ***************************** >> ***************************** >> ***************************** >> >> >> > > > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en -~----------~----~----~----~------~----~------~--~---
