jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes args.length of main Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "args.length of main" Watch "args.length of main" New topic
Author

args.length of main

ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 375
public static void main(String[] args) {


if(args.length == ???)....


}


Question --- Does those -cp, -classpath, etc counted in the args string array ? or does java automatically ignore these key words when it counts "args" ? It seems these key words are not counted as I tried, but want to confirm.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

ben oliver wrote:...Does those -cp, -classpath, etc counted in the args string array ? or does java automatically ignore these key words when it counts "args" ? It seems these key words are not counted as I tried, but want to confirm.

When invoking from the command line, the format is...

java [-options] class [args...]

The String array passed to main will include only Strings supplied as [args...]. If none are supplied, then args.length will be zero.

[-options] are not included in that String array.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Victor Thomas
Greenhorn

Joined: Oct 31, 2010
Posts: 9
Yup!

I don't rightly know the mechanism behind it, but if you use *nix you all would see that them there options <ie -h , -al, --version, etc> on various utilities aint counted as arguments to the executable.
Victor Thomas
Greenhorn

Joined: Oct 31, 2010
Posts: 9
damn sheriff beat me to the draw ...
 
Don't get me started about those stupid light bulbs.
 
subject: args.length of main