Question: I have a simple Java theory question. If I write a class that contains a main() method along with some other methods, and within that main method invoke an instance of the class (say new Class()), I'm a bit confused why a recursion doesn't occur. Let's say I'm writing a graphing program, where the other methods in the class create a window and plot data; in the main method I call an instance of the class itself, and yet only one window appears. That's great, and it's what I wanted, but intuition suggests that if I create an instance of a class from within itself, some sort of recursion should occur. What prevents this? Here is an example (in my mind, I'm wondering what prevents unwanted recursion):

```
     public class example{
         method1(){create Jpane}
         method2(){paint Jpane}
         method 3(){do some computations}

         public static void main(String[] args){
            new example(); // or create Jblah(new example()); 
         }
      }

```

Answer: 
I think you're confusing the `main` method - which is just the entry point of the program - with a *constructor*.

For example, if you wrote:

```
public class Example {
    public Example() {
        new Example(); // Recursive call
    }

    public static void main(String[] args) {
        // Will call the constructor, which will call itself... but main
        // won't get called again.
        new Example(); 
    }
}

```

Then that *would* go bang.
Recursion isn't a bad thing. I suspect you are asking why there isn't an infinite recursion.

The big concept you are missing is that when you call new Example() you are allocating memory and then invoking just one method (the constructor). The `main()` is only invoked at the start of the whole program unless you explicitly call it.

--- edited to add

```
public class MyMainClass {
  public static void main(String arg[]) {
    Calculator c = new Calculator();
    int x = c.factorial(5);
  }
}

class Calculator {

  Calculator() { }

  public int factorial(int x) {
    if (x > 1) return x * factorial(x - 1);
    else return 1; // WARNING: wrong answer for negative input
  }
}

```

Since factorial doesn't use any instance variable, it could have been declared `static` and called as `Calculator.factoral(5);` without even using `new`, but I din't do that since showing off `new` was the whole point of the example.