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
Explain about main thread in java?
What are java packages? What is the significance of packages?
How is java created?
What is xslt in java?
How do you execute a thread in java?
can java object be locked down for exclusive use by a given thread? : Java thread
What's the default access specifier for variables and methods of a class?
What are generic methods?
How hashmap increases its size in java?
What do you understand by copy constructor in java?
What are the important features of Java 11 release?
What is the indent key?
What are different access specifiers in java?
What is the use of jtable?
What is the main difference between java platform and other platforms?