Explain Java Command Line Arguments?

The way of providing input at the time of exection is known as command line arguments.

Command line arguments are parameters that are supplied to the application program at the time of involving it for execution.

We can write Java programs that can receive and use the arguments provide in the command line.

public static void main (String args [ ])

args is declared as an array of strings.

Any arguments provided in the command line are passed to the array args as its elements.

We can simply access the array elements and use them in the program as we wish.

The following example demonstrates how command line arguments are  used in Java.

class ComLineTest
{
  public static void main (String args [ ] )
{
   int count, i = 0 ;

   String str ;

   count = args.length;

   System.out.println(“Number of arguments – "+count);

   while (i < count)
   {
      str = args [i] ;

      i = i + l ;

      System.out.println(i + “ : “ “java is” + str+”!\n");
    }
  }
}


Javac ComLineTest.java 

Java ComLineTest simple object oriented distributed robust

o/p : Numbers of arguments = 4

1 : Java is simple !    

2 : Java is object oriented !

3 :Java is distributed ! 

4 :Java is robust !

Related

Java 8919925826942151206

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item