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 get () in java?
How do you start a thread?
Explain how to convert any java object into byte array.
What is double data type?
What are actual parameters?
What happens if we override only equals?
Is ++ operator thread-safe in java?
Write a program to find the whether a number is an Armstrong number or not?
Are true and false keywords?
What is the static block?
Is java platform independent?
Is 0 true or false?
Java is Pass by Value or Pass by Reference?
What’s the difference between the methods sleep() and wait()?
Why map is used in java?