Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java basic question

Tags:

java

public static void main( String arg[] )

In the above statement, can I use an int array in place of the String array? What happens if I don't put anything in the parenthesis, i.e if I use an empty parenthesis?

like image 393
pradeep Avatar asked Feb 07 '11 05:02

pradeep


2 Answers

When you compile the code with the changes that you mentioned, it will compile successfully. When you try to run, JVM checks for the main method with String array as arguments. Since there is no main method with String array as argument, your code will not execute successfully and it throws NoSuchMethodError.

like image 54
R K Avatar answered Sep 19 '22 19:09

R K


No, I think you can't use int array instead of String array.because the argument int is used by the operating system to pass an integer value specifying the number of command-line arguments entered by the user. so you must follow the following pattern.

public static void main(String[] args)

public static void main(String args[]) 
like image 22
Rameswari Avatar answered Sep 19 '22 19:09

Rameswari