aspose file tools*
The moose likes Beginning Java and the fly likes main method argument!!! 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 argument!!!" Watch "main method argument!!!" New topic
Author

main method argument!!!

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi All,

why we always giving String arg[] in main method

can any one tell me?

Thanks & Regards,
seetharaman.v
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

one more question

how many times the finalize will call ?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

So you can pass arguments to your program. Try writing a basic app, somehting like:


and run it with some parameters (e.g. "java TestApp foo bar "), see what it does.
[ May 27, 2008: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
amitabh mehra
Ranch Hand

Joined: Dec 05, 2006
Posts: 98
Originally posted by seetharaman venkatasamy:
one more question

how many times the finalize will call ?


never more than once for any object
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Paul Sturrock ,


i mean..

why we can not give like this

public static void main(int[] args){}

we always used to give public static void main(String[] args){} why?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
There's no guarantee that you'll get something that fits an "int" from the command line. Strings, on the other words, can be used for anything you can type on the command line.


Ping & DNS - my free Android networking tools app
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

THANKS ULF
K Sathya Narayanan
Greenhorn

Joined: Feb 15, 2007
Posts: 28
hi
even you can use
public static void main(){}//complies ok instead of public static void main(String[] args){}

but when you try to execute it will result in a runtime exception.
The complier expects the main() method to have the following attributes
1 must be public and static,the order in which it is typed is not a error

static public void main(String[] args) {}//ok

2. must return void as return type and have a string[] as argument
as of java 5. , you can use main(String...data) instead main(String[] data)

The String[] passed in the main function delas with the command line arguments. so you may overload the main function , but the main function with the above attributes only will be called by the compiler. even if the program may not use the command line arguments but still string[] must be passed as argument.

HTH
K Sathya Narayanan
vinayak katkar
Greenhorn

Joined: May 28, 2008
Posts: 2
hi
arguments given to the main are called as command line arguments
when we want to give the file name,string name at the runtime we use the command line argument .


�Knowledge is the food of the soul.�<br /> <br /><br />To get free knowledge,ebook links, free pdf ,and new technology discussions visit the following link <br /><a href="http://vinayakkatkar.blog.co.in" target="_blank" rel="nofollow">http://vinayakkatkar.blog.co.in</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: main method argument!!!