Login Register






main() method filter_list
Author
Message
main() method #1
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!

Reply

RE: main() method #2
the [] marks an array Wink

=> 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
double free()

Bitcoin Donations:
1FseigF4RPRwfDoa6XGFQmhGxmDc7Pya4r

Reply

RE: main() method #3
Thanks for the help! I appreciate it.

Reply

RE: main() method #4
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)
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: main() method #5
@Deque do we hav to put space between (string...args)?

Reply

RE: main() method #6
@Deque do we hav to put space between (string...args)?

Reply

RE: main() method #7
(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.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: main() method #8
(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.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: main() method #9
(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.

Reply