Why we r using String args[] in main() even though v r not
passing any arguments in command line?

Answers were Sorted based on User's Feedback



Why we r using String args[] in main() even though v r not passing any arguments in command line?..

Answer / mehtaashish

First of all an in appropriate main method will not cause any
compile time error, it results in a runtime exception. The
reason for this is that the main method's signature is written
as such in Java specification. And all the interpreters and
compiler and constructed while keeping language specification
in mind. So whenever we try to run a program JVM looks for
"public static void main(String args[])" for starting
execution. And if it does not find any main method, it throws
the "NoClassDefFoundException".

Is This Answer Correct ?    2 Yes 3 No

Why we r using String args[] in main() even though v r not passing any arguments in command line?..

Answer / abcd

First of all an in appropriate main method will not cause any
compile time error, it results in a runtime exception.
i think reason is ase all know java program can run usingg
the same name as class name."String args[]" takes program
name as first argument that's why it gives run time exception.

Is This Answer Correct ?    0 Yes 6 No

Post New Answer

More J2SE Code Interview Questions

we compile any program bu c:/>javac prog.java and run as c:/>java prog Here what's the meaning of c in javac. We have java Interpreter but not compiler.Then why we have to use javac. Please answer this question?

2 Answers  


Program to print map of India in java.

2 Answers  


Why the program getting error if we don't use String args[] in main(), even in the case of not getting any arguments from command line?

1 Answers  


Is there any static classes are in java give some examples

0 Answers  


In java, why do we set thread priority, when we know that there is no guarantee by which a thread should be execute?

0 Answers   Google, Microsoft,






how to create a (*)pyramid using java codes???

5 Answers   Infosys,


what are the other loops except for for,while,do while and until?

0 Answers   Aricent,


I am trying to pass the string firstName from a Servlet called SampleServet. I am running this on eclipse and it tells me that "the value for annotation attribute must be a constant expression. I don't understand why it is giving me this error. @PersonAnnotation(name = SampleServlet.firstName) public class AnnotationClass{

0 Answers  


How to create and run runnable jar file of a Java Project.

4 Answers   HCL, TCS, Tech Mahindra, US Consulate, Wipro,


write a program that will ask the user to enter a number n and display the product of all numbers from 1 to n.

1 Answers  


Why we r using String args[] in main() even though v r not passing any arguments in command line?

2 Answers  


For printing a message we use System.out.println in normal programs. We use String msg="text....."; Can't we use String msg=" " in normal programs and System.out.println("........") in applets. Please answer this question?

0 Answers  


Categories