Results 1 to 2 of 2
  1. #1
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Posts
    1,694
    Blog Entries
    430
    Rep Power
    10

    Default Input parameter of Main method

    Main method takes a string array as the input argument. Lets do some experiments with it.
    Java Code:
    public class MainClass {
      public static void main(String[] args) {
        System.out.println("No. of argumetns are: " + args.length);
           for(int i= 0;i < args.length;i++)
              System.out.println("Argument " + i + " is : " + args[i]);
        }
    }
    String delimiter is a space character.

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default is args[] always non-null

    Looking at the code, which I will probably put in several places in my code, I get two questions:
    1. Is args[] always non-null/
    2. One would expect this code does not drop into the for loop if there are no command line parameters. If so, this would be a handy tool for checking if anything provided on command line.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Similar Threads

  1. Calling main method
    By eva in forum New To Java
    Replies: 7
    Last Post: 11-06-2009, 02:37 PM
  2. A query about main method
    By mew in forum New To Java
    Replies: 2
    Last Post: 12-24-2007, 10:44 AM
  3. Private main method
    By bugger in forum New To Java
    Replies: 1
    Last Post: 12-21-2007, 10:45 AM
  4. main method
    By eva in forum New To Java
    Replies: 5
    Last Post: 12-19-2007, 10:25 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
  •