• Post Reply Bookmark Topic Watch Topic
  • New Topic

max no of arguments for main method in java  RSS feed

 
Dinesh Kumar Ramakrishnan
Ranch Hand
Posts: 87
AngularJS Chrome Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I got an interview question how many arguments you can pass to the main method from command line ? i don't know the exact answer for the question. kindly share your answers here

 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently this question has been asked before. here and here

You may want to check out this a bit more detail
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What a strange interview question. I think I'd be tempted to give the answer "more than anyone would ever sensibly want to use".
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the links given above are a bit off-topic, but there was some discussion on this in http://www.coderanch.com/t/630844/java/java/command-line-parameter-limit
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:I think the links given above are a bit off-topic, but there was some discussion on this in http://www.coderanch.com/t/630844/java/java/command-line-parameter-limit

The only trouble with that thread is that it seems to assume that "command line" arguments are necessarily "typed in", when they could actually come from a script or BAT file that does some globbing.

@Dinesh: I've no idea about Windows; but I'm pretty sure that most *n[iu]xes these days allow upwards of 1 million characters in a command string. The limit on older versions of Solaris used to be 64K.

That said, if you're even anywhere near an 8K limit, you might want to re-think your "invocation strategy".

Winston
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would answering this question indicate to the interviewer?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Harry wrote:What would answering this question indicate to the interviewer?

Dunno, but maybe some familiarity with OS's.

However, I agree with Matthew: it's a very strange question.

Winston
 
Dinesh Kumar Ramakrishnan
Ranch Hand
Posts: 87
AngularJS Chrome Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Matthew yes very strange question almost he asked every candidate on the interview panel
@Winston thanks for the info
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Harry wrote:What would answering this question indicate to the interviewer?


Either the interviewer is asking a silly question, or they don't actually expect a 'right' answer but want to hear the reasoning the candidate gives. Obviously there are going to be platform dependent limitations here (no idea what they are), but from a purely Java perspective you could say that the arguments are placed into an array, so what is the maximum size an array can be? Not sure if the JLS gives a specific limit, but the array has a size which is a positive signed-int, so that would limit the number of parameters to about 2^31.

But if anyone get's anywhere near the actual limit then I don't ever want to work on that system!
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the Java perspective there's only one parameter, which is an array of Strings.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!