why we write public static void main (String args[])
in core java plz explain briefly??????????????????
Answers were Sorted based on User's Feedback
Answer / nilay
because in JAVA everything is within class and should be
called with classname(static methods) or with instance of
that class. but main is the first method to be called when
no instances are in memory so that is why it is static and
is called like <classname>.main() by System class. and it
must be public because it is called from outside enviornent
of current class file. String[] is for the command line
arguments that you pass when you run your java program
by "java .classfile arg1 arg2" so all arguments are
received here and for multiple arguments it is an array of
strings. it does not return anything so it's return type is
void.
Is This Answer Correct ? | 17 Yes | 0 No |
Answer / sreenivas p
JVM looks for the main method(from where it starts
execution) with the same signature(public static void
main(String args[])) if it coud not find throws
NoSuchMethodError.
valid signatures are:
public static void man(String args[])
static public void main(String a[])
Invalid signatures
static void main()
public static main(String args[]) etc..[treats these
are all as general methods ]
Is This Answer Correct ? | 16 Yes | 3 No |
we write public because it can be called from outside the envornment and as we know that by using public keyword we will be able to access all the codes from outside,static is used because the JVM(java virtual machine which is also called as the interpreter calles the main function when there is no declaration of class instances so if we dont use static then the interprter will not check for it ,we use string and its a kind of class.It is also known as the commad line argument.
Is This Answer Correct ? | 3 Yes | 0 No |
What are the different tags provided in jstl?
Write the program numbers into words.For example 2345==two thousand three hundred fourty five
Can multiple catch statements be used in exceptions ?
What do you understand by copy constructor in java?
i need source code for income tax program using java inheritance
What is the difference between Stream Reader and Stream Writer?
Is upper case in java?
Name few "optional" classes introduced with java 8 ?
watz the difference between abstract class and interface? Which one u ill choose as a designer?
What is the differnence between String Buffer and String builder despite having knowledge that String builder is faster than String Buffer and last one is threadsafe.please tell another important difference.
What is the latest version of java?
What is string literal in java?