Possible Duplicate:
how to use (String [] [] args) in java
Can we use public static void main(String [] [] args)
in Java for 2d arrays?
Possible Duplicate:
how to use (String [] [] args) in java
Can we use public static void main(String [] [] args)
in Java for 2d arrays?
There are three possible ways you can define the parameters of the main method:
Classic Java Style
public static void main(String[] args)
C Style
public static void main(String args[])
New-school (post JDK1.5) Java style
public static void main(String ... args)
All of these are equivalent, and the VM will only start your class if it finds a method with one of these signatures.
Actually, they are not quite equivalent, there is one small difference: When accessed via reflection, Method.isVarArgs()
will only return true for the last method. But they still all have an equal signature (name, parameter types, return type, visibility)
No you can't. How would you specify command-line arguments to fit in a 2d array? The main(..)
method is invoked by the java runtime which passes the command-line arguments specified when the program is invoked.
Sure, you can declare your own main method that takes a 2d array, but it won't be executed automatically by the JVM on startup, because it looks for a method with a signature:
public static void main(String[] args)
See the Hello World tutorial for more information on the main method.
The two main facts pointed out in other questions:
So if you really want to have an entry point that accepts a 2D array, you should do this:
public static void main(String[] args) {
String[][] args2d;
// some crazy code that parses args and initializes args2d with a 2D array
main(args2d);
}
public static void main(String[][] args) {
// your actual entry point here
}
Note that you don't have to declare the second method public in this case, but you still can do it if you really want to.
no you can't.because main(String[] args) method is special method for JVM and it's looking for
main method with this signature :
public static void main(String[] args) {
}
No two dimensional array will not work.When you are using String args[] means you are going to send array of string arguments to the compiler but you cant use a two dimensional array. You are going to get Class not found exception.But the file will compile.