While practicing some questions on hackerrank, some of the solutions had argh instead of args (which I have used mostly). Also, I got to know that there is another such argument that can be passed to main() function and that is argv. Thus in all there are three different arguments that exist:
args
argh
argv
Could you please tell me the difference between all three and how and when to use them?
And here is the code:
class Solution{
public static void main(String []argh){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int i = 0; i < n; i++){
String name = in.next();
int phone = in.nextInt();
// Write code here
}
while(in.hasNext()){
String s = in.next();
// Write code here
}
in.close();
}
}
Please note that I am not asking for the solution to the above question. I have already solved it and made a successful submission but what I wanted to know was what difference would it make by adding argh instead of args?
thanks in advance!
Java function signatures are validated based on their return and arguments types, but never check for the name of the arguments. This means that
public static void main(String... parameters) { /* [...] */ }
is a valid main
function.
It also means that you don't have to use the same argument names as an interface when implementing its functions, or as a class you extend when overloading its functions.