| Author |
All Java projects must use main method?
|
André Asantos
Ranch Hand
Joined: Nov 23, 2009
Posts: 234
|
|
All Java projects must use main method?
André AS
|
André AS
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Are all Java projects stand-alone applications?
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Bob Livingston
Greenhorn
Joined: Apr 06, 2010
Posts: 4
|
|
|
Yes, all java programs must have a main method. The static main is the first method called in any java program. It does not matter where it occurs it just must occur.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9948
|
|
Bob,
the original post asked about all java PROJECTS, not programs. I have worked on many PROJECTS that didn't have a main.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Bob Livingston wrote:Yes, all java programs must have a main method.
Define "Java program". Is a web application also a Java program? Or an applet?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56192
|
|
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Shine Tom
Greenhorn
Joined: Sep 17, 2012
Posts: 19
|
|
fred rosenberger wrote:Bob,
the original post asked about all java PROJECTS, not programs. I have worked on many PROJECTS that didn't have a main.
Hello Fred, Can you tell me why many java PROJECTS doesnt contain a main function. Please also tell me when there is no main method, how is the application executed.
Many Thanks,
Shine
|
 |
Jelle Klap
Bartender
Joined: Mar 10, 2008
Posts: 1409
|
|
Applets don't use a main method to initialize, they provide an init() method.
Likewise, Servlets don't require a main method - they too provide life-cycle methods that are invoked by a servlet container / application server.
|
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
|
 |
Shine Tom
Greenhorn
Joined: Sep 17, 2012
Posts: 19
|
|
|
Thanks for the update. Alos one more doubt, what about in the case of eclipse plugins ? do they need a main method??
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 5874
|
|
Shine Tom wrote:Thanks for the update. Alos one more doubt, what about in the case of eclipse plugins ? do they need a main method??
No. Which a quick Google search would have told you.
Also, libraries don't need a main().
Also, any of these projects that don't need a main() could still have one, or several, for testing purposes, or if they're capable of being run in more than one context. This is somewhat unusual, but not unheard of.
|
 |
Jelle Klap
Bartender
Joined: Mar 10, 2008
Posts: 1409
|
|
No, much like a Servlet an Eclipse plug-in provides life-cycle methods, wether its target runtime environment is Eclipse itself or an OSGi framework (Equinox). This is typically how plugins work. There's actually a pretty neat JavaRanch journal entry on adding plugins to a Java application, written by Ulf Dittmer.
Edit: Dude seriously? Nice timing
|
 |
Shine Tom
Greenhorn
Joined: Sep 17, 2012
Posts: 19
|
|
Thanks Jeff & Jelle..
|
 |
 |
|
|
subject: All Java projects must use main method?
|
|
|