• 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

in which class main() method resides in java API?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually i am confused with the main() method.coz,from where we inherit this method?.I think it should be inside any one of the Java API class,from where we inherit.Please help me to know this in detail.

Thanks in advance.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The main method is not inherited from anywhere. You have to supply a main method in order for your application to run. If you don't supply a main method you will get an error when you try to run your application.
 
jayanandan thiagarajan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you.
So it is written inside the interpretor that to see the main() in all classes while executing.
am i right?
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What sort of application are you thinking of? Standalone app -- in this case you must be typing something like this on the command line:

>java MyClassWithAMain

or you are using a bat file (or equivalent) that is doing this for you.

If you are thinking of an applet, the "main" is part of the code that IE or Netscape has embedded in it (the plugin) and you never see it.

If you are thinking of a web app, again the "main" is part of the framework and you never see it, or write it.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by jayanandan thiagarajan:
thank you.
So it is written inside the interpretor that to see the main() in all classes while executing.
am i right?



Yes. When you run
java MyClass
Java will look for a method with the signature
public static void main(String [] args)
in the MyClass.class file. If it doesn't find it, it will fail.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it is NOT required to have a main() method in every class. you can write an application with dozens or hundreds of classes, but only one has to have a main() in it - the one you call to start your program.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And the fact that the JVM looks for main() on the specified class when starting up is the only magic thing about main. It's really a perfectly normal static method with no magic powers of its own.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you wish for an class to be a starting class then yes it must have a main(String[] args)
this does not apply to an applet
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic