• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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: 22818
132
Eclipse IDE Spring 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: 13091
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: 22818
132
Eclipse IDE Spring 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: 67752
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..
 
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic