• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main method argument!!!

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

why we always giving String arg[] in main method

can any one tell me?

Thanks & Regards,
seetharaman.v
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one more question

how many times the finalize will call ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
amitabh mehra
Ranch Hand
Posts: 98
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THANKS ULF
 
K Sathya Narayanan
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic