why we use string args in main method in java

When you finish your code, you will turn it into a file with the extension. java, which can be run by double clicking it, but also throughout a console (terminal on a mac, cmd. exe on windows) which lets the user do many things. One thing is they can see console messages (System. out. print or System. out. println) which they can't see if they double click. Another thing they can do is specify parameters, so normally you would use the line
java -jar MyCode. jar on Mac (notice that mac is less clunky) to run code, but to specify parameters you would use java -jar MyCode. jar parameter1 parameter2 These parameters stored in the args array, which you can use in your program is you want to allow the user to control special parameters such as what file to use or how much memory the program can have.


If you want to know how to use an array, you could probably find a topic on this site or just google it. Note that any number of parameters can be used.


When you finish your code, you will turn it into a file with the extension. java, which can be run by double clicking it, but also throughout a console (terminal on a mac, cmd. exe on windows) which lets the user do many things. One thing is they can see console messages (System. out. print or System. out. println) which they can't see if they double click. Another thing they can do is specify parameters, so normally you would use the line java -jar MyCode. jar on Mac (notice that mac is less clunky) to run code, but to specify parameters you would use java -jar MyCode. jar parameter1 parameter2 These parameters stored in the args array, which you can use in your program is you want to allow the user to control special parameters such as what file to use or how much memory the program can have.


If you want to know how to use an array, you could probably find a topic on this site or just google it. Note that any number of parameters can be used.

  • Autor: Roto2
  • Comments: 0
  • Views: 0