permaculture playing cards
The moose likes Beginning Java and the fly likes main method signature.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main method signature.." Watch "main method signature.." New topic

main method signature..

subhasish nag
Ranch Hand

Joined: Apr 25, 2008
Posts: 101
why we need to pass String array as an argument in main method instead of int or float or char type of array?

Thanks,<br />Subhasish
Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

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.

How To Ask Questions How To Answer Questions
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2904

This because the JVM searches for that string array syntax only , while executing an .java program..


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

because a String (or an array of them) can be parsed into ints or floats. the same is not true for the reverse.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
camilo lopes
Ranch Hand

Joined: Aug 08, 2007
Posts: 202
in java 5 is possible use vargs in main.

is some that use [].

Brazil - Sun Certified Java Programmer - SCJP 5 About Java - Update every Week.
Guide SCJP - tips that you need know
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
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.
I agree. Here's the link:
subject: main method signature..
jQuery in Action, 3rd edition