Results 1 to 6 of 6

Thread: main method

  1. #1
    eva
    eva is offline Member
    Join Date
    Dec 2007
    Posts
    49
    Rep Power
    0

    Default main method

    Hi,

    I am new to Java and new to this forum as well.

    The signature of main method is

    Java Code:
    public static void main(String[] args) {
    ...
    }
    It takes a String array as input. But when I run the application, I do not supply any arguments to my application. Even then program runs fine. How this is done?

    - PEACE

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    The (java) virtual machine (jvm) will read the arguments that follow the ".java" on the command line and you can use these in the main method. If there are no arguments and/or if you do not use them it is okay. It's an option for input to an application. It is often used in a way that allows running an app with different paramaters/data without having to compile each time. If an app is designed to require arguments it usually will announce this in the console each time you run it without arguments.

  3. #3
    coe11n is offline Member
    Join Date
    Dec 2007
    Posts
    13
    Rep Power
    0

    Default

    hardwired


    what is the porpouse for _[]_ arrays in the main method

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    You can enter more than one argument on the command line. The arguments will be treated as an array. "[]" is the array operator. "args" is (declared as) a String array.

  5. #5
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default

    eva there is a real great book for beginners from david eck
    ( free on the net)
    i just red it and it explains all
    http://math.hws.edu/eck/cs124/downloads/javanotes5.pdf

    willemjav

  6. #6
    eva
    eva is offline Member
    Join Date
    Dec 2007
    Posts
    49
    Rep Power
    0

    Default

    Thanks hardwired for the explanation.
    A big thanks to willemjav for the link.

    - PEACE

Similar Threads

  1. Calling main method
    By eva in forum New To Java
    Replies: 7
    Last Post: 11-06-2009, 02:37 PM
  2. Input parameter of Main method
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 07-12-2008, 07:24 PM
  3. A query about main method
    By mew in forum New To Java
    Replies: 2
    Last Post: 12-24-2007, 10:44 AM
  4. Private main method
    By bugger in forum New To Java
    Replies: 1
    Last Post: 12-21-2007, 10:45 AM
  5. The main method in java...
    By lenny in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 07:21 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
  •