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

What is a Package? What are its Uses?

Package: One of the main feature of OOP is its ability to re use the code the code already created. One way of achieving this is by extending the classes and implementing the Interfaces. If ...

Explain about Thread priority in Java?

 In Java, each thread is assigned as priority which affects the order in which it is schedule for running.  The Threads of the same priority are given equal treatment by the Java sch...

Explain Thread exceptions?

Sleep method is enclosed in a try blocked followed by a catch block. This is necessary because the sleep( ) throws an exception, which should be caught .if we fail to ...

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