• 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

max no of arguments for main method in java

 
Ranch Hand
Posts: 98
Angular Framework Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4568
9
  • Likes 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the links given above are a bit off-topic, but there was some discussion on this in https://coderanch.com/t/630844/java/java/command-line-parameter-limit
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 https://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
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What would answering this question indicate to the interviewer?
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 98
Angular Framework Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Matthew yes very strange question almost he asked every candidate on the interview panel
@Winston thanks for the info
 
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the Java perspective there's only one parameter, which is an array of Strings.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic