This discussion is archived
4 Replies Latest reply: Feb 5, 2008 9:06 PM by 807601 RSS

why is the array symbol in the main method?

807601 Newbie
Currently Being Moderated
We are talking about arrays in class, and I had made a comment about an array symbol means a list will follow, but then I thought about the main method. I was just wondering if anyone had a quick and simple explanation as to why the main method always includes this symbol?
Thanks.
  • 1. Re: why is the array symbol in the main method?
    807601 Newbie
    Currently Being Moderated
    Because the main method signature in Java is defined to take an argument of an array of Strings.

    So the real answer is "because that is the way it is". However there is a practical application to this which is that you can always feed arguments to a Java program via the command line/shell prompt at runtime.
  • 2. Re: why is the array symbol in the main method?
    807601 Newbie
    Currently Being Moderated
    Thanks. I kind of figured it was just the way it is for a reason. With that in mind, any other time you see an array symbol would it only occur because an array will follow or are there other practical reasons for including the symbol without the array, perhaps for later use?

    Yes im new to programming : ) im just trying to understand concepts and logic.....I hope these questions aren't too silly or simple.
  • 3. Re: why is the array symbol in the main method?
    807601 Newbie
    Currently Being Moderated
    Stephanie739 wrote:
    Thanks. I kind of figured it was just the way it is for a reason. With that in mind, any other time you see an array symbol would it only occur because an array will follow or are there other practical reasons for including the symbol without the array, perhaps for later use?
    Umm no. [] always means you are declaring the type of the variable as an array.

    and [aroundsomething] where something is an literal number or variable means you are accessing an element of that array
  • 4. Re: why is the array symbol in the main method?
    807601 Newbie
    Currently Being Moderated
    Thank you.