Junilu Lacar wrote:Think of it as the main door to the house...
I rather like that analogy: A Java program is a house, and classes are the rooms... Neat.
@Steven: Another thing that's worth remembering: in Java, classes are
components; but the actual
unit of execution (ie, a "program") is normally a
jar, which can contain many classes. However, it only has
one start point (stored in its manifest), so any given
jar only needs one class with a
main() method.
However, as Junilu says, there's nothing to stop you putting it in more than one class if you want.
I don't want to overload you too much at this stage, but one other thing to remember about
main() is that it's a
static method.
And
static methods can only call other
static methods, which leads a lot of beginners to start making everything
static.
My advice: DON'T - It's a very restrictive way to program.
Java works best when you have
objects and use their instance (ie, non-
static) methods, so in your
main() method, create an object as fast as you can and use
its methods.
You can find one way to do this in the
MainIsAPain page; but it's just one way, there are lots of others.
HIH
Winston