what happens if i do not provide String array as an argument to method?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ambikasd
    New Member
    • Sep 2007
    • 12

    what happens if i do not provide String array as an argument to method?

    hi,

    please tell me what if I do not provide the String array as the argument to the method?

    thanks

    ambikasd
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by ambikasd
    hi,

    please tell me what if I do not provide the String array as the argument to the method?

    thanks

    ambikasd

    When JVM runs the class file then JVM looks for that particular signature.
    [code=java]void main(String [])[/code]
    Actually your mail function will never get call and your program never gets started.

    Kind regards,
    Dmjpro.

    Comment

    • praveen2gupta
      New Member
      • May 2007
      • 200

      #3
      Originally posted by ambikasd
      hi,

      please tell me what if I do not provide the String array as the argument to the method?

      thanks

      ambikasd
      Hi
      It will depend on your mathod what it accepts and in which squence of data Types. Your question is very vast. post your method so that we can more clerify it.

      Comment

      • Nepomuk
        Recognized Expert Specialist
        • Aug 2007
        • 3111

        #4
        Originally posted by ambikasd
        hi,

        please tell me what if I do not provide the String array as the argument to the method?

        thanks

        ambikasd
        Which method do you mean? If it's the main method
        [CODE=java]public static void main(String[] args)[/CODE]then you won't be able to run it without the String array. However, you don't have to give it any arguments.

        If you have a simple "Hello World" Program, it would look like this:
        [CODE=java]
        public class HelloWorld {
        public static void main(String[] args) {
        System.out.prin tln("Hello World!\n");
        }
        }
        [/CODE]You would compile it with
        Code:
        javac HelloWorld.java
        and run it with
        Code:
        java HelloWorld
        However, running
        Code:
        java HelloWorld These are arguments
        will result in the same - your program will have the array {"These", "are", "arguments" }, but it just doesn't care about it.

        Any other function only can have a String array as arguments, if you define it so. (Which you will only do, if you need it.)

        Greetings,
        Nepomuk

        Comment

        • ambikasd
          New Member
          • Sep 2007
          • 12

          #5
          Originally posted by praveen2gupta
          Hi
          It will depend on your mathod what it accepts and in which squence of data Types. Your question is very vast. post your method so that we can more clerify it.
          Hi,


          My method is

          public static void main(String args);

          What happens in this case?

          thanks,

          ambikasd

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by ambikasd
            Hi,


            My method is

            public static void main(String args);

            What happens in this case?

            thanks,

            ambikasd
            That is not the method signature (and name) the jvm is looking for so your class
            can not be run as the starting point of your program.

            kind regards,

            Jos

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by ambikasd
              Hi,


              My method is

              public static void main(String args);

              What happens in this case?

              thanks,

              ambikasd
              Try it and see what happens. Don't you have the JDK installed.
              Last edited by r035198x; Sep 13 '07, 10:32 AM. Reason: added have

              Comment

              Working...