In Java why we write public static void main(String args[])
why not main()?
Answer Posted / angela
when we run java program, jvm internally calls "main" method.
jvm is built in such a way that it searches for the entire
signature of "main" method i.e public static void
main(String a[])
Example program :
----------------------
class Demo
{
public static void main(String a[])
{ }
}
String a[] -> is used to pass values at runtime.
(c:/>java Demo hai)
public -> providing accessibility for outside code (jvm).
static -> without creating an object calling "main" method
with the class name
c:/>javac Demo.java
c:/>java Demo
(here java internally calls jvm and passes class name
Demo, then jvm loads Demo class and calls Demo.main()
without creating object )
void -> does not return any value because jvm simply calls
main() method and does not have a variable to assign return
value.
| Is This Answer Correct ? | 23 Yes | 1 No |
Post New Answer View All Answers
What is the use of :: in java?
Why is stringbuffer called mutable?
Can we use string in switch case in java?
What is the main use of java?
State the difference between strings and arrays.
What is thread life cycle in java?
Can we synchronize static methods in java?
What is the size of string?
What is difference between next () and nextline () in java?
What is an example of a constant variable?
What are the two main uses of volatile in Java?
What are different data structures in java?
Why put method is used?
What are java annotations?
Where can I find jdk in my computer?