Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

All Java projects must use main method?

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All Java projects must use main method?

André AS
 
Sheriff
Posts: 22662
127
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are all Java projects stand-alone applications?
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13063
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22662
127
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67650
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jeff & Jelle..
 
reply
    Bookmark Topic Watch Topic
  • New Topic