Explain Java Command Line Arguments?
https://www.computersprofessor.com/2016/05/explain-java-command-line-arguments.html
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 !
|