Command Line Arguments in Java means to pass or input value as argument from command prompt to java program for specific purposes. Using command line arguments we can make java program as command. In other words we can say that it is way to input the value for the program before executing it.
When we use java program as command line argument then the argument written on command prompt can be receive by class’s main() function during run-time as:–
String args in Java
This parameters will receive all the arguments written on command prompt as command line arguments as string type and hence conversion required accordingly.
- Int x=12;
Integer y=x; //wrong before version 5
Integer y=Integer.valueOf(x) //right in all versions
- Integer x=12;
int y=x; //wrong before version 5
int y=Integer.valueOf(x).intvalue() // right in all versions
Autoboxing and Unboxing in Java
This feature was introducing in java version 5 and later. This feature allow us to store a data type value into corresponding wrapper class object and vice-versa without any conversion.
Autoboxing in Java
When java converts automatically the data type value into corresponding wrapper class process is called autoboxing.
Example of Autoboxing in Java
Input Value
Autoboxing in Javaimport java.util.ArrayList; import java.util.List; public class autoboxingandunboxinge { public static void main(String[] args) { List<Integer> list = new ArrayList<>(); for(int i = 0; i< 20; i++){ list.add(i); } System.out.println(list); char c = 'a'; Character ch = c; System.out.println(ch); } }
Let’s run the code
Output Value
Unboxing in Java
When java converts automatically the wrapper class into corresponding data type process is called unboxing.
Example of Unboxing in Java
Unboxing in Javapublic class autoboxingandunboxinge { public static void main(String[] args) { Integer x=10; int y = x; System.out.println(y); } }
Let’s run the code
Output Value
If you have any queries regarding this article or if I have missed something on this topic, please feel free to add in the comment down below for the audience. See you guys in another article.
To know more about JAVA Wikipedia please click here .
Stay Connected Stay Safe, Thank you
0 Comments