• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

main method argument!!!

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
one more question

how many times the finalize will call ?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THANKS ULF
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic