Q: | What if the main method is declared as private? | |
A: | The program compiles properly but at runtime it will give "Main method not public." message. | |
Q: | What if the static modifier is removed from the signature of the main method? | |
A: | Program compiles. But at runtime throws an error "NoSuchMethodError". | |
Q: | What if I write static public void instead of public static void? | |
A: | Program compiles and runs properly. | |
Q: | What if I do not provide the String array as the argument to the method? | |
A: | Program compiles but throws a runtime error "NoSuchMethodError". | |
Q: | If I do not provide any arguments on the command line, then the String array of Main method will be empty or null? | |
A: | It is empty. But not null. | |
Q: | What environment variables do I need to set on my machine in order to be able to run Java programs? | |
A: | CLASSPATH and PATH are the two variables. | |
Q: | Can I have multiple main methods in the same class? | |
A: | No the program fails to compile. The compiler says that the main method is already defined in the class. | |
Q: | Do I need to import java.lang package any time? Why ? | |
A: | No. It is by default loaded internally by the JVM. | |