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() doubts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main() doubts" Watch "main() doubts" New topic

main() doubts

Mahesh Barik

Joined: Aug 14, 2006
Posts: 15
can anyone tell me to which to class main() belongs,as we know for each method there is a particular main() as a method it should be under a class that would be predefined.

Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

It belongs to the class you want to execute. It can be any class.

[My Blog]
All roads lead to JavaRanch
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
This is predefinied by the JVM.
marc weber

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Mahesh Barik: main() as a method it should be under a class that would be predefined...

A "main" method is not predefined for any particular class. It can be included in any class you decide to put it in. What is predefined is the way main (with the proper signature) is used as an entry point...

"A Java virtual machine starts execution by invoking the method main of some specified class..." (JLS - 12.1 Virtual Machine Start Up).
[ October 10, 2006: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: main() doubts
It's not a secret anymore!