• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main method signature..

 
subhasish nag
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why we need to pass String array as an argument in main method instead of int or float or char type of array?
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because it is what the user types in, and that can be any String. It could be char[] or String (not String[]) as well but then you'd have to merge or split it yourself into the separate options.

If you need it to be ints or floats you can always parse the arguments yourself.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This because the JVM searches for that string array syntax only , while executing an .java program..

like
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because a String (or an array of them) can be parsed into ints or floats. the same is not true for the reverse.
 
camilo lopes
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in java 5 is possible use vargs in main.

is some that use [].
 
Campbell Ritchie
Sheriff
Pie
Posts: 49793
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by camilo lopes:
in java 5 is possible use vargs in main.
Probably best to stick to the familiar form (String[] args), though.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic