| Author |
concept in main()
|
Soumya Padhiary
Greenhorn
Joined: Jan 10, 2013
Posts: 20
|
|
i know that, in java main method is called by JVM as thread.
but when i mentioned main method in a progrme, like below, it successfully run:
class{
public static void main(String... args)
{
System.out.println("in main");
}
}
instead of String[], is it acceptable ?
what is the differencr between (String... s) and (String[] args) ?
please give answer ,
thanks in advance .
|
 |
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
|
|
|
Its called varargs, equivalent to Java array, added in Java 5.
|
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
|
 |
Manish Dubey J
Greenhorn
Joined: Oct 08, 2011
Posts: 9
|
|
Hi Soumya,
""what is the differencr between (String... s) and (String[] args) ?""
This is a different concept of 'varargs'. It has nothing to do with main method!
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Soumya Padhiary wrote:
what is the differencr between (String... s) and (String[] args) ?
with String[] argument you need pass the appropriate argument as new String[]{"values"}
with String... you no need to, compiler do array creation and appropriate method call.
here even method call with no argument is possible as compiler insert zero size appropriate array .
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
Soumya Padhiary wrote:instead of String[], is it acceptable ?
Yes. Section 12.1.4 of the Java Language Specification states:
JLS wrote:
Finally, after completion of the initialization for class Test (during which other consequential loading, linking, and initializing may have occurred), the method main of Test is invoked.
The method main must be declared public, static, and void. It must specify a formal parameter (ยง8.4.1) whose declared type is array of String. Therefore, either of the following declarations is acceptable:
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
|
Start reading about varargs here. You are allowed [] or ... in the main method, as it says here.
|
 |
 |
|
|
subject: concept in main()
|
|
|