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

Nesting of for loops in java

Nesting of loops, i.e., one for statement with in another for statement is allowed in Java. For ex:–two loops can be nested as follows. The nesting may continue up to any desired ...

Method Overloading in Java

In java it  is  possible to create  methods that have  the same but  different  parameter lists  and  different definitions . This is called  method ...

Explain different levels of access modifier available in java for protection.

It is possible to inherit all the members of a class by a subclass using the keyword extends. However, it may be necessary in some situations to restrict the access to certain variabl...

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