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

How to create Date method to set the date in Ms Access

0 Answers  


Is there any static classes are in java give some examples

0 Answers  


how to store and retrive a set of values without using an array

8 Answers   FCS, HCL, Maximus,


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  


does anyone know the code to display a triangle using a applet?

1 Answers  


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

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


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

1 Answers  


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

5 Answers   Infosys,


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

1 Answers   Tech Mahindra,


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

0 Answers  


what is runtime class?

0 Answers   MAQ,


how to print a message to console without using main() function?(do not use even static blocks also.)

14 Answers   Google, Zoho,


Categories