Two Laptop Bag*
The moose likes Beginning Java and the fly likes Why Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why " main() "  is a Watch "Why " main() "  is a New topic
Author

Why " main() " is a 'public static' method..??

vivek a naik
Greenhorn

Joined: May 15, 2008
Posts: 9
Why is it necessary to add "Public static " modifiers in main() method.

is it just because we dont have to create an object to call it..??
Jitendra Jha
Ranch Hand

Joined: Jan 28, 2007
Posts: 91
static methods are class methods and do not need an object to run..
we also know that methods(non-static) are called from an object.
when we execute a java program,main is loaded first
since no object(of the particular class) is present at that time hence not having "static" would not help us in running the program...
[ May 26, 2008: Message edited by: Jitendra Jha ]

Jitendra
SCJP1.5
SCWCD1.5
vivek a naik
Greenhorn

Joined: May 15, 2008
Posts: 9
Thanks Jitendra.

I think O.S calls the main method implicitly.
is main a "Callback" method..?
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334
No not exactly. JVM will call the main method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why " main() " is a 'public static' method..??
 
Similar Threads
Static Variable Problem
can't run
java
Main method question
What is the main usage of "String[] args" in public static void main(String[] args)?