Basic java program structure; Was: Problems with multidimensional arrays and global variables  
Author Message
Don Freeman





PostPosted: 2005-2-12 7:03:00 Top

java-programmer, Basic java program structure; Was: Problems with multidimensional arrays and global variables <top posting seemed more appropriate for this post>.

Being a Java newbie and having been struggling with the basic concepts of
the structure of a java program (as well as "static") I would like to say
that this is the best example I have seen so far of the basic form of a java
program. Nice, simple and after reading it I think I finally understand
what is going on. I have read far too many books and examples that seem to
enjoy obfuscating the concept they are trying to explain with way too many
extraneous details.

Thank you.
Don Freeman

If this group has a FAQ I nominate the following for entry:

"Carl" <email***@***.com> wrote in message
news:fS8Pd.3241$email***@***.com...

> In short, static members do not belong to an object. You do not need to
> create an object to access the members. The main() method must be static
> since it will be the first method called and there will not yet have been
> a chance for you to create any objects. IMO, the main method should then
> proceed to operate on OBJECTS, unless you have a good reason for using
> static.
>
> A simple class example would be as follows:
> // code -->
> public class Foo {
>
> // this can be accessed by any of Foo's methods
> private int someVariable;
>
> // This gets called when a new Foo object is created.
> public Foo(){
> // do initial setup
> }
>
> public void runProgram(){
> // start doing your processing
> }
>
> public static void main(String[] args) {
> // process args[]
>
> Foo foo = new Foo(); // create an instance of the Foo class.
> foo.runProgram(); // start running the Foo class.
> }
> }
> // <-- end code