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
Define how does a try statement determine which catch clause should be used to handle an exception?
What is lifetime variable?
what happens when a thread cannot acquire a lock on an object? : Java thread
How do you check whether the list is empty or not in java?
How do you create immutable object in java?
What is the basic concept of java?
How to check if a list is sorted in java?
What is instanceof keyword?
What is namespace in java?
What is var keyword ?
How can we make string upper case or lower case?
What is parsing a sentence?
What is anti pattern in cyber security?
What is jdbc api?
What is return keyword in java?