Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

All Java projects must use main method?

 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All Java projects must use main method?

André AS
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are all Java projects stand-alone applications?
 
Bob Livingston
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12147
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bob,

the original post asked about all java PROJECTS, not programs. I have worked on many PROJECTS that didn't have a main.
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64980
86
IntelliJ IDE Java jQuery Mac Mac OS X
 
Shine Tom
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shine Tom
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1952
7
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeff & Jelle..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic