Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is the use of :: in java?

962


Why is stringbuffer called mutable?

938


Can we use string in switch case in java?

999


What is the main use of java?

1102


State the difference between strings and arrays.

1146


What is thread life cycle in java?

1010


Can we synchronize static methods in java?

1041


What is the size of string?

1014


What is difference between next () and nextline () in java?

939


What is an example of a constant variable?

1017


What are the two main uses of volatile in Java?

1012


What are different data structures in java?

967


Why put method is used?

965


What are java annotations?

1071


Where can I find jdk in my computer?

921