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

Final variables and methods in Java

final variables and methods( ): All methods and variables can be overridden by default in subclass. If we wish to parent the sub classes from overriding the members of the super class, we can decl...

Differences between String class and String Buffer class?

Differences between string class and string buffer class: String objects are immutable and string buffer objects are mutable. Methods to manipulate the data are not available in string class. th...

Write about Variable size arrays in Java?

Variable size array: Java treats multidimensional array as “arrays of arrays”. it is possible to declare a two–dimensional array as follows: int x[ ] =new int[3][ ]; x[0]=new...

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