File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes main() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main()" Watch "main()" New topic


Sanjay Izardar

Joined: Apr 18, 2011
Posts: 19
where the main() is defined.
and what is the use of static keyword in public static void main(String argument[])
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
main is used in that class from which you want your project or file to be started

More over we use the STATIC keyword to call the Main() without creating the object by JVM
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

You define the main() method yourself, in whatever class you like. When you start a Java program, Java will look for a public static void main(String[] args) method - that's where your program starts running, as Aditi already mentioned.

For the meaning of "static", see this tutorial page: Understanding Instance and Class Members.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Mittal Vishal

Joined: Nov 13, 2006
Posts: 21
Static methods are known as class methods. They belong to the class in which they are declared, and are not part of any instance of the class.
So to invoke them, object of the class is not required.
That's why main method is declared as static so that JVM can invoke it
Nico Van Brandt
Ranch Hand

Joined: Mar 31, 2011
Posts: 66

Note that both are correct:

Oracle Java SE6 Certified Programmer
Oracle Java EE5 Certified Web Component Developer
I agree. Here's the link:
subject: main()
It's not a secret anymore!