• iconJava Online Training In Andhra Pradesh and Telangana
  • icon9010519704

Opening Hours :7AM to 9PM


Java CommandLine Arguments
Command line arguments are used to read the values from keyboard(pass the values while running of the program)

class Addition
{
public static void main(String args[])
{
System.out.println("Before converting "+(args[0]+args[1]));
}
}

Output
Java Addition 12 12
Before Converting 1212
In the above example addition of two number are concated because CommandLine Arguments are by default strings.To overcome this problem Wrapper classes are introduced.
Wrapper class
Wrapper classes are used to convert the string format to appropriate Primitive Datatypes.

Wrapper classes
Constants Wrapper Class Datatype Method
Integer Byte byte x=Byte.parseByte(args[0])
Short short x=Short.parseShort(args[0])
Integer int x=Integer.parseInt(args[0])
Long long x=Long.parseLong(args[0])
Floating point Float float x=Float.parseFloat(args[0])
Double double x=Double.parseDouble(args[0])
Character Character char x=args[0].charAt(0)
String String String x=args[0]

class Addition
{
public static void main(String args[])
{
System.out.println("Before Converting "+(args[0]+args[1]));
int x,y,z;
x=Integer.parseInt(args[0]);
y=Integer.parseInt(args[1]);
z=x+y;
System.out.println("After Converting "+z);
}
}


OUTPUT:
Java Addition 12 12
Before Converting 1212
After Converting 24