This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Args[] array in main method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Args[] array in main method" Watch "Args[] array in main method" New topic
Author

Args[] array in main method

Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 84
Hi all,



I never really thought about the args[] array in the main method until now and it struck me that it must be auto intiialised in size based on the number of arguments you pass to the command line. i.e. 3 arguments passed and the args[] array is created with 3 elements and its size is 3. Is this a correct assumption?

Also, if no arguments are passed, how come a test on this args[] arry being null returns false?




I'm aware that all arrays have their element intiailsed to the defaults of the type e.g. 0 for int, howver, if no arguments are passed then is the args[] array not just a null array with no elements? Can someone shed some light or point me in the direction of more information on this 'special' case?


Thanks,

Colm
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
The arg array is always an array of Strings. If no arguments are passed then the size of the arg array is zero. But the array is still created. It just doesn't have any elements in it.
Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 84

Thanks for that reply. It was something I never really dwelled on before but definitely makes sense.

Regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Args[] array in main method
 
Similar Threads
Marcus exam 3 # 26
SCJP5.0 passed!!
problem with local array statement
Sun Cirtification
Generics Question