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?

Why the program getting error if we don't use String args[] in main(), even in the case of not..

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 ?    5 Yes 0 No

Post New Answer

More J2SE Code Interview Questions

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

0 Answers   Aricent,

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  

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   Microsoft, Google,

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 Can I Trace A Java Program . Please Give Me Step by Step Process

1 Answers   IBM,

write a program in java to find the moving average of all prime numbers between 2 and 100.

0 Answers  

How can we get the details for printing the employee details at run time using JDBC connectivity? can u provide the coding for that? Its urgent?

2 Answers  

Write a java program to display multiplication table in a Frame.

1 Answers  

is public static void main() work in java?is "String arg[]" needed as argument?

4 Answers   Tech Mahindra,

write a c program which takes 20 numbers in an array as input from user and rearrange them in two different array defining even or odd

0 Answers  

Is it possible to define marker interface in java.If possible then how to define user defined marker interface?

1 Answers   Tech Mahindra,

inner join,outerjoin,trigger,stored procedure explain with code snippets?

1 Answers   IBM,