0% found this document useful (0 votes)
20 views

CMD Line Arg

The document discusses command line arguments in Java programs. Command line arguments allow values to be passed to a Java program when it is run. These arguments can be accessed via the args parameter of the main method. The example program prints the first command line argument passed to it when run. To run the program, it must be compiled with javac and then executed with java along with any command line arguments.

Uploaded by

isayashpbende26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

CMD Line Arg

The document discusses command line arguments in Java programs. Command line arguments allow values to be passed to a Java program when it is run. These arguments can be accessed via the args parameter of the main method. The example program prints the first command line argument passed to it when run. To run the program, it must be compiled with javac and then executed with java along with any command line arguments.

Uploaded by

isayashpbende26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

class CommandLineExample{

public static void main(String args[]){


System.out.println("Your first argument is: "+args[0])
;
}
}
compile by > javac CommandLineExample.java
run by > java CommandLineExample sonoo
Output: Your first argument is: sonoo
Java Command Line Arguments

The java command-line argument is an argument i.e. passed at the time of running
the java program.
The arguments passed from the console can be received in the java program and it
can be used as an input.
So, it provides a convenient way to check the behavior of the program for the
different values. You can pass N (1,2,3 and so on) numbers of arguments from the
command prompt.

Simple example of command-line argument in java


In this example, we are receiving only one argument and printing it. To run this java -
program, you must pass at least one argument from the command prompt.

class CommandLineExample{
public static void main(String args[]){
System.out.println("Your first argument is: "+args[0]);
}
}
compile by > javac CommandLineExample.java
run by > java CommandLineExample sonoo
Output: Your first argument is: sonoo
Example of command-line argument that prints all the values
class A{
public static void main(String args[]){

for(int i=0;i<args.length;i++)
System.out.println(args[i]);

Int x=Integer.parseInt(args[2]);
Int y=Integer.parseInt(args[3]);
Int z= x+y;

}
}
compile by > javac A.java
run by > java A sonoo jaiswal 1 3 abc
Output: sonoo jaiswal 1 3 abc
Primitive Type Wrapper class

boolean Boolean
char Character
byte Byte
short Short
int Integer
long Long
float Float
double Double

You might also like