• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

signature of main() method....

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is it mandatory that the signature of main() method should be as shown below in order to run the application:

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


OR is it ok even if the signature is like this:

public static void main(String... args) { }

And also i wanted to know the difference between the two method signatures........?
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Naveen,
String... didn't exist prior to Java 5 meaning older code must use the first form.

Since String... and String[] compile to the same thing, newer code can use either form. I tend to use String... because it's faster to type.
 
Naveen Megharaj
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which means at present both method signatures are valid and legal isn't it........? if this questions is asked in SCJP exam what should i do........?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer it.
 
Sheriff
Posts: 22802
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:I tend to use String... because it's faster to type.


Really? ... is 3 characters while [] is 2 located directly next to each other on most keyboards. I also tend to use ... though.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as a method with single parameter is concerned not much difference is involved. However few good points can be consider in case of ELLIPSIS(...)

1) There can be ONLY ONE ellipsis parameter in the method and which MUST be the last parameter. There in no such restriction for String[] version
2) It can be analysed using int printf(String,...) method of C Programming in which it can accept variable number of arguments. like printf("%d",1);printf("%d%f",1,1.0);
3) Elipsis provide a way to define single method defination for variable argument calls with ZERO TO 'N' number of arguments of same or type that can be IMPLICITLY CASTED to that parameter.
4) Ellipsis version comes with 5.0 version.
5) Ellipsis provides more freedom as compare to array[] version.

No hard rules which to use when.
 
Naveen Megharaj
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot to all the repliers..........
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Fundu Varun"

Welcome to the Ranch.
Please check your private messages for an important administrative matter.
 
Jeanne Boyarsky
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:

Jeanne Boyarsky wrote:I tend to use String... because it's faster to type.


Really? ... is 3 characters while [] is 2 located directly next to each other on most keyboards. I also tend to use ... though.


Yes. But it is faster to touch type the same character three times than two different characters. Also, the dot character is in a position easier to reach while touch typing than the [] because I have to move my finger a good distance to get to the "]". Which often requires me to look at the keyboard further reducing speed.
 
I brought this back from the farm where they grow the tiny ads:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic