Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java main method args

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java main method args

    I have a little question which confuses me. In the main method the args array seems to be created wrong from which i have been taught.

    in the main method to declare the args array im sure you all know it is String[] args

    but from what i have learned, an array is made with String args[]

    why is this different in the main method?

    thanks


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java main method args

    Either syntax is valid. From the array tutorial (http://download.oracle.com/javase/tu...ts/arrays.html ):
    You can also place the square brackets after the array's name:

    float anArrayOfFloats[]; // this form is discouraged

    However, convention discourages this form; the brackets identify the array type and should appear with the type designation.
    PS- Thousandth post!
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java main method args

    I see, many thanks for your answer. Sorry if this has been posted before I didnt know what to search for. Gz on 1,000th post

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java main method args

    Quote Originally Posted by mattxo View Post
    I see, many thanks for your answer. Sorry if this has been posted before I didnt know what to search for. Gz on 1,000th post
    No problem. The Java tutorials are a great resource for this kind of question- I typed in "java arrays" to find that tutorial.

    Also, you could use varargs with the main method:

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

    I'll leave that for you to google. :p
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Paint program adding classes to main method class
    By Maxfmc in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 15th, 2011, 07:01 PM
  2. Creating a scaleUp main method in a new class
    By Brainz in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 16th, 2010, 08:58 AM
  3. Replies: 2
    Last Post: March 26th, 2010, 11:22 AM
  4. how to execute a simple display without a main method
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: January 13th, 2010, 07:28 AM
  5. adding main method to a code
    By IDK12 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 31st, 2009, 08:52 PM