File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes main() is the entry point Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main() is the entry point" Watch "main() is the entry point" New topic

main() is the entry point

Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
Hi All,

I am a bit confused here.

main() is the entry point for all applications. main() is the static method. So as is expected a static method can call from within another static method or static variable.

So my question is

methods called from within the main() method must be static. Variables called must be static.

So does it not mean that everything will have to be static ?

Regards,<br />Arnab
Dave Salter
Ranch Hand

Joined: Jul 20, 2005
Posts: 293

Methods called from within main() do not have to be static if they belong to a class that you have instantiated within main().

So, you can instantiate classes within main() and call methods on them.
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

often, one of the first things you'll see in Class A's main method is a creation of an object of type A... i.e. within main you'll see

A myA = new A();

now you can call A's non-static methods within main, on a



There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

I think a simple example here is worth 1000 words.

GenRocket - Experts at Building Test Data
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
oh ok.. Thanks
I agree. Here's the link:
subject: main() is the entry point
It's not a secret anymore!