• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String args[]

 
jack worthing
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
can anybody please help me
what is the difference between

and why do we need it when we dont need to enter any command-line arguements

Thankyou
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12024
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is no difference - they both mean the same thing. an array of Strings named 'args'.

when you type "java MyClass", java knows to look for the MyClass object, and to run the static method name 'main' that takes a String array as it's only argument.

You certainly can write other methods names 'main' that take different (or no) parameters, but java will ALWAYS look for and run the one with the String array. You would have to call any others explicitly within your code, just like any other method.
 
Rob Spoor
Sheriff
Pie
Posts: 20399
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only difference is programmer preference. I, and many with me, prefer "String[] args" over "String args[]" because it makes it much clearer that the variable type is "array of string". With the second form, the array part is much further away from the String part.
 
Minal Silimkar-Urankar
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"int array[]"

is C style of array declaration, people who worked in C a lot are comfortable with C style of array declaration.

"int[] array"

is java style of array declaration.
 
jack worthing
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankyou
i got it now
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add few lines var-args are also permitted from java 5



is same as

 
jack worthing
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankyou
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic