Results 1 to 14 of 14

Thread: Main Method

  1. #1
    maya700 is offline Member
    Join Date
    Jun 2010
    Posts
    45
    Rep Power
    0

    Default Main Method

    Does a main method in java have a return type?

    Thank you.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,530
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by maya700 View Post
    Does a main method in java have a return type?

    Thank you.
    What does your test book say about it?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    maya700 is offline Member
    Join Date
    Jun 2010
    Posts
    45
    Rep Power
    0

    Default

    Well my text books says that the generally the return type of main method is void., but i did some searching on net and came across a site that says that the default return type of main method is int. Can i get an example of that please??

    Thank you

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by maya700 View Post
    Well my text books says that the generally the return type of main method is void., but i did some searching on net and came across a site that says that the default return type of main method is int. Can i get an example of that please??

    Thank you
    Why don't you write two examples codes and compile on your PC?

  5. #5
    maya700 is offline Member
    Join Date
    Jun 2010
    Posts
    45
    Rep Power
    0

    Default

    i wrote a sample code and it threw me a runtime error.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  7. #7
    maya700 is offline Member
    Join Date
    Jun 2010
    Posts
    45
    Rep Power
    0

    Default

    class Testmain

    {

    public static float main(String[] args)


    {


    return 23.4f;


    }


    }

    This is my code and it is showing some runtime exception

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  9. #9
    maya700 is offline Member
    Join Date
    Jun 2010
    Posts
    45
    Rep Power
    0

    Default

    Exactly like tht.

  10. #10
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,530
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by maya700 View Post
    Exactly like tht.
    So please tell us so and donīt make us guess; be as exact as possible if you want us to be able to help you. So, that site you've read was dead wrong: the JVM wants the return type of the main method to call to be void. It also wants it to have one parameter which must be an array of Strings so the JVM can pass the command line arguments to it; anything else is considered an error by the JVM and it throws an Exception (as you noticed).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    maya700 is offline Member
    Join Date
    Jun 2010
    Posts
    45
    Rep Power
    0

    Default

    Thanks a Ton !!!

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    Quote Originally Posted by maya700 View Post
    Well my text books says that the generally the return type of main method is void., but i did some searching on net and came across a site that says that the default return type of main method is int. Can i get an example of that please??

    Thank you
    Was that site talking about C/C++ by any chance?

  13. #13
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,530
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by maya700 View Post
    Is this valid declaration of multi dimensional array??

    int [[,]] a = new int [[5, 5]] ;

    Thank you.
    What does your text book have to say about this? You made this up yourself didn't you? Any previous exposure to any form of Basic or any non-C like language is not going to help you. If you had tried to compile this syntactic nonsense you would''ve known that this is not a valid declaration of a multi dimensional array.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  14. #14
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,530
    Blog Entries
    7
    Rep Power
    20

    Default

    I noticed that you also started a new thread for this question; closing this one.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Running main method class from another main class
    By tlrocketman in forum New To Java
    Replies: 3
    Last Post: 12-06-2010, 08:30 AM
  2. Calling The main method from another method
    By SwissR in forum New To Java
    Replies: 3
    Last Post: 07-27-2010, 11:03 AM
  3. Help with main method
    By eliCanzee in forum JDBC
    Replies: 4
    Last Post: 01-06-2010, 09:12 AM
  4. calling method from main method
    By bob_bee in forum New To Java
    Replies: 4
    Last Post: 10-02-2009, 05:30 PM
  5. Main method here to :S:S hlp pls
    By eliCanzee in forum AWT / Swing
    Replies: 6
    Last Post: 05-27-2009, 04:45 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
  •