aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main method signature.." Watch "main method signature.." New topic
Author

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
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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

like


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

Joined: Oct 02, 2003
Posts: 11419
    
  16

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
http://www.camilolopes.com/ About Java - Update every Week.
Guide SCJP - tips that you need know http://blog.camilolopes.com.br/livrosrevistaspalestras/
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39416
    
  28
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: http://aspose.com/file-tools
 
subject: main method signature..