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
Can an interface have a class?
What is the preferred size of a component in java programming?
How do you use substring in java?
What are the different types of collections in java?
What are design patterns and please explain?
What is use of inner class in java?
What does the “static” keyword mean? Can you override private or static method in java?
What is unicode full form?
What is a method header?
How to perform selection sort in java?
What is JVM and is it platform independent?
What are the characteristics of Final,Finally and Finalize keywords.
What are the escape sequences in java?
What is the full form of jpeg?
how its run?