Why Do We Use (String[] Arg) In Main Function In Java?
Pl i need the answer because i searched in many websites but i didn't get clear explanation.....
3 Answers - Sort by: Date | Rating
This is where java sticks the array of arguments from the command line (if there is one)...
Example... If you have a program and to invoke it you call the following:
Java helloWorld -s -h -f:c:\test.txt
Arg would contain the following values:
Arg[0] = "-s"
Arg[1] = "-h"
Arg[2] = "-f:c:\test.txt"
This is primarily used for command-line applications.
Example... If you have a program and to invoke it you call the following:
Java helloWorld -s -h -f:c:\test.txt
Arg would contain the following values:
Arg[0] = "-s"
Arg[1] = "-h"
Arg[2] = "-f:c:\test.txt"
This is primarily used for command-line applications.
0
0
Because it helps in accepting values for variables unless you want to use data input output functions(which is not that simple).
0
0
If you run java from command line then you pass in arguments with the program that you can use later on in the code. Arguments in this case are just values that you want passed into the code.
Example:
Student.java John Taylor
//in this case arg[0] = John arg[1] = Taylor
public static void main(String[] args){
//the following will print to the screen John Taylor
System.out.println(arg[0] + " " + arg[1]);
}
Example:
Student.java John Taylor
//in this case arg[0] = John arg[1] = Taylor
public static void main(String[] args){
//the following will print to the screen John Taylor
System.out.println(arg[0] + " " + arg[1]);
}
0
0
- How To Make An Application By Using Java Program?
- What How The Step For Make Library Management?
- In Which Process We Can Start Java?
- Define The Concept Of Java Byte Code?
- How To Run Remote Method Invocation In More Machine?
- How To Run Java Remote Method Invocation In More Machine?
- How To Make A Java Program That Will Ask The User To Input A Number And Display All The Even Number And The Sum Of All Even Numbers Based On The Inputted/ Given Numbers?
- Is A Static Variable An Instance?
- How To Compile And Run Java Package?
- What Does Literati-on Mean?
- What Is Abstract Class In Details?
- What Is Meant By Remote Method Invocation In Java?
- What Is Meant By Package In Java?
- What Is Meant By Servlet In Java?
- When Was Java Released?
- What Is Latest Technologies In Java?
- Write A Program Using Do…..while Loop To Calculate And Print The First M Fibonacci Numbers?
- What Is The Difference Between Reference &instance Variable?
- Why Java Is Slow?
- What Is The Drawback Of Ms Access?
- What Is Replaced In Place Of Pointers In Java?
- What Replaces Pointers In Java?
- How Many Types We Create Object In Java?
- I Signed Up Promo Code 505124 For 12 Months My Bill Said For 6 Months Who Fix This Error?
- What Is The Expansion Of Java?
- Why Should We Give String Arguments In Java Main Method
- Why Do We Use "Public Static Void Main(String[] A)" In Java?
- Why Do We Use (main())function In Java? Why Not Static Block Function?
- What Is A String In Java?
- What Is String Means In Java?
- Who Invented String In Java And When?
- How To Sort A String Array In Java?
- Program In Java To Accept A String And Find No. Of Characters Present In The String?
- Program In Java To Accept A String And Find The Number Of Blank Spaces In The String?
- Program In Java To Accept A String And Find No. Of Special Character And No. Of Digits?

New Comment - Comments are editable for 5 min.