Results 1 to 6 of 6
  1. #1
    Hype is offline Member
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Default Clarification on main method

    Hi

    I was taught that a java application executes from the main method which is:
    public static void main (String [] args) {

    Does the following code also qualify as the start of execution:
    public static void main(String str[]) throws Exception {
    if (str.length == 0)

    Doesn't every java app have to have the first main method I listed?

    What is the meaning of the second code I listed?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    Do you mean can the main() method be declared as throwing an exception? The best way to find out would be to run and compile a test.

    You might also try "public static void main(String... args)".

  3. #3
    Hype is offline Member
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Default

    It's the public static void main (String [] args){ specifically that I believed had to be in every complete and working java application...?

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    Oh I see!

    You can use any (legal) variable you like. And you can use the yucky "String arr[]" form.

    All the JVM has to say about it is "The Java virtual machine starts execution by invoking the method main of some specified class and passing it a single argument, which is an array of strings. This causes the specified class to be loaded (2.17.2), linked (2.17.3) to other types that it uses, and initialized (2.17.4). The method main must be declared public, static, and void". (5.2 Virtual Machine STartup)

  5. #5
    Hype is offline Member
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Default

    Ok great info. Thanks

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

Similar Threads

  1. Calling The main method from another method
    By SwissR in forum New To Java
    Replies: 3
    Last Post: 07-27-2010, 12:03 PM
  2. Struts Clarification
    By vinothkumarrvk in forum Web Frameworks
    Replies: 0
    Last Post: 02-26-2010, 03:24 PM
  3. need clarification in this statement.
    By Unsub in forum New To Java
    Replies: 5
    Last Post: 02-26-2010, 02:16 PM
  4. calling method from main method
    By bob_bee in forum New To Java
    Replies: 4
    Last Post: 10-02-2009, 06:30 PM
  5. HELP! need clarification
    By ptsofathrty in forum New To Java
    Replies: 1
    Last Post: 12-16-2008, 09:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •