Java — What happens if we change main(String[] args) to main(Integer[] args)?

Java — What happens if we change main(String[] args) to main(Integer[] args)?

Let us first understand why we need these arguments and then try changing the data type of arguments.

When we run the java program from command prompt we can pass the arguments to the jar file using these args seperated by space which takes as array of String arguments.

what if I have to pass Integer values?

we also can pass integers in the arguments. Internally it takes everything as String but it can be type-casted later.

OK. Now let me try running the program changing my argument type

public class basicjava {
public static void main(Integer[] args) {}
}

There is no run time error. Great!! Now lets run the program.

OOPS!! Got an error

Error: Main method not found in class com.javasample.basicjava, please define the main method as:public static void main(String[] args)or a JavaFX application class must extend javafx.application.Application

Main method not found. This is because JVM does not consider this method as the main method even if the argument type is different. It just takes it as normal method and not the main() method.