Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

args.length of main

 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Victor Thomas
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
damn sheriff beat me to the draw ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic