![]() |
|
main() method - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Java, JVM, & JRE (https://sinister.li/Forum-Java-JVM-JRE) +--- Thread: main() method (/Thread-main-method) |
main() method - ART33R - 01-09-2014 Hello, I have started to program in Java and enjoy it. I Have a quick question i will ask. Something I notice is that people put "[]" in different place in the main () method, for example: "public static void main (Strings[] args) {". (Without quotes) The question is: What happens if you move the "[]" in main () method, for example at the left of args? Like this: "public static void main (String args []) {" (Without quotes) Does it make any difference? Appreciate your response! RE: main() method - upsurt - 01-09-2014 the [] marks an array ![]() => http://www.tutorialspoint.com/java/java_arrays.htm Code: dataType[] arrayRefVar; // preferred way.
or
dataType arrayRefVar[]; // works but not preferred way.string[] args means you'll have an array of args, not only one. so you can pass multible args to you program -> myprog.exe -arg1 -arg2 -arg3 -arg4 -argn RE: main() method - ART33R - 01-10-2014 Thanks for the help! I appreciate it. RE: main() method - Deque - 01-10-2014 It doesn't make a difference for the compiler if you write String[] args or String args[]. But the official Java convention is to put the [] to the type, because it belongs semantically there (the [] doesn't belong to the name of the parameter, because it says something about the type: "a string array named args", NOT "a string named args array"). So this should be done: Code: public static void main(String[] args)This is a good way too: Code: public static void main(String... args)RE: main() method - Yusadolat - 04-25-2014 @Deque do we hav to put space between (string...args)? RE: main() method - Yusadolat - 04-25-2014 @Deque do we hav to put space between (string...args)? RE: main() method - Deque - 04-25-2014 (04-25-2014, 03:24 PM)Yusadolat Wrote: @Deque do we hav to put space between (string...args)? There are two possibilities you can find the answer to this question yourself. 1. Write it this way and try to compile it. 2. Look into the language specification. The first is probably faster. Good luck. RE: main() method - Deque - 04-25-2014 (04-25-2014, 03:24 PM)Yusadolat Wrote: @Deque do we hav to put space between (string...args)? There are two possibilities you can find the answer to this question yourself. 1. Write it this way and try to compile it. 2. Look into the language specification. The first is probably faster. Good luck. RE: main() method - Banadmin - 06-11-2015 (04-25-2014, 03:24 PM)Yusadolat Wrote: @Deque do we hav to put space between (string...args)? You, it would require spaces because String is an object type and args is the object. |