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

Explain about main thread in java?

1043


What are java packages? What is the significance of packages?

960


How is java created?

898


What is xslt in java?

939


How do you execute a thread in java?

911


can java object be locked down for exclusive use by a given thread? : Java thread

1036


What's the default access specifier for variables and methods of a class?

1061


What are generic methods?

920


How hashmap increases its size in java?

936


What do you understand by copy constructor in java?

886


What are the important features of Java 11 release?

1064


What is the indent key?

993


What are different access specifiers in java?

956


What is the use of jtable?

1070


What is the main difference between java platform and other platforms?

1005