[Java beginner] Command line arguments ... I don't know ~

On the command line ~, the number of command line arguments ~,

Even if an issue like this is given, "I don't understand the meaning! ]. So I googled it and looked it up! Let's Google it!

Q.1 What are command line arguments?

Conclusion: The first information passed when starting a program

It has a reputation for being convenient because it brings the file information without you having to write the code one by one.

Roughly speaking, the most frequently set command line arguments are file information, and it seems that characters and numbers are also OK. If you specify the path of the folder that contains the necessary data when setting, you can get the information of the contents of the folder </ b> Yes.

Q.2 Where is the command line argument information passed?

Conclusion: Argument part of main method

public class sample{       
   public static void main(String[] args){ 
   }                      //String[]args part
}

The first call from the java virtual machine (VM) seems to be "public static void main (String [] args)" </ b> and is received as a String type array.

By the way, it seems that the variable name does not have to be "args".

Q.3 Can the main method not receive argument values from other places?

Conclusion: The main method arguments are for command line arguments only

main method Since it is called first in the program, you cannot pass arguments in the method as shown below </ b>. So it seems necessary to pass the information as a command line argument.

public class sample{       
   public static void main(String[] args){ 
     hello("Hello","Kakizaki");
   } 

  public void hello(String a, String b){
    System.out.println(a + "," + b + "Mr.")   //Result: Hello,柿崎Mr.
  }                   
}

It seems that there are many situations where you will be in trouble if you do not know it. I also take care. See you again

Recommended Posts