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:–

CLA

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.

args
  • 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

import 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);
   }
}
Autoboxing in Java

Let’s run the code

Input Value

Output Value

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

public class autoboxingandunboxinge   {
   public static void main(String[] args) {
      Integer x=10;
      int y = x;
      System.out.println(y);

   }
}
Unboxing in Java

Let’s run the code

Input Value

Output Value

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


Basic Engineer

Hey Readers! We have more than fifteen years of experience in Software Development, IoT, Telecom, Banking, Finance and Embedded domain. Currently we are actively working on Data Science, ML and AI with multiple market leaders worldwide. Happy Reading. Cheers!

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *