• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

args.length of main

 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
damn sheriff beat me to the draw ...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic