This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Main Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Main Method" Watch "Main Method" New topic

Main Method

Willie Toma
Ranch Hand

Joined: May 11, 2001
Posts: 78
Is this correct:
The main method is necessary, but if it isn't there the compiler inserts one.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Willie,
The statement is totally incorrect!
Main method is only needed if you want to run the class.
The compiler could care less if it exists or not.
If it doesn't exist the JVM will throw an exception saying it can't find it.
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
If you changed the words "main method" to "constructor" that statement would be correct. If your class has no constructor the compiler will put a no-parameters constructor there. Of course it will be sort of a trivial constructor - but it will be there.
PS: MOST classes do not have main methods. Classes that do have main methods are often refered to as drivers because they are the starting point of an application.
Applets run with no main at all - the browser kicks things off instead.
[This message has been edited by Cindy Glass (edited December 07, 2001).]

"JavaRanch, where the deer and the Certified play" - David O'Meara
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Main Method
It's not a secret anymore!