• Post Reply Bookmark Topic Watch Topic
  • New Topic

main method signature..  RSS feed

 
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?
 
Sheriff
Posts: 21135
87
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.
 
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
 
lowercase baba
Bartender
Posts: 12565
49
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.
 
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 [].
 
Marshal
Posts: 56608
172
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!