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

No main-method

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This code does compile but a runtime it gives:

Am I right when I say the absence of a main method gives a runtime-error? (Apart from applets)
TIA, Erik Dark
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you try to run a class that has no main method, then the class is initialized (static block is executed, thus the output) but the main method cannot be found and a NoSuchMethodError is thrown.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public static void main(String [] args) should be thought of as a "contractual agreement" between the programmer and the developers of the Java langauge.
They agreed to start execution of your program at a well defined point in your code, and you need only provide the REQUIRED interface. So by not providing a main method that meets the "contract", you are "violating" your end of the agreement when you ask the Java language to RUN your code.
It's like telling someone to pull an object out of a glass box, but not providing any entry point to that box.
Macon
 
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good way to put it!
-Dale
 
reply
    Bookmark Topic Watch Topic
  • New Topic