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

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

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


How Can I Trace A Java Program . Please Give Me Step by Step Process

1 Answers   IBM,


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

1 Answers   Tech Mahindra,


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

5 Answers   Infosys,


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 program that will ask the user to enter a number n and display the product of all numbers from 1 to n.

1 Answers  


Is there any static classes are in java give some examples

0 Answers  


write a program that inputs two real numbers then exchanges their values.

7 Answers   Infosys,


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

1 Answers  


write a program in java to solve a system of n-variabled simultaneous equations using the guassian elimination method. let the maximum possible value of n be 100. run the program using hypothetical values for a set of 10- variables simultaneous equations. print out the program, the input equation and the results generated by the program.

0 Answers   TCS,


1+(2*3)+(4*5*6)+(7*8*9*10)+... specified input value

1 Answers   MAQ,


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  


Categories