Link to home
Start Free TrialLog in
Avatar of william007
william007

asked on

Level of stack allowed by java

Does java specify how many level of stack is allowed? or it is machine dependent?

I try this function, it only allows me up to n=6955, n=6966 will cause stack overflow.
    public static double fact(double n){
        if(n==0) return 1;
    }


   
Avatar of Venabili
Venabili
Flag of Bulgaria image

Is it the factorial?
    public static double fact(double n){
        if(n==0) return 1;
       return fact(n-1)*n;
    }

or you mean another function. Because what you posted won't even compile :)
Avatar of william007
william007

ASKER

Exactly Venabili, thanks for catching that:)
ASKER CERTIFIED SOLUTION
Avatar of Venabili
Venabili
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And of course the last one had to read "the stack size" and not the "stack trace"...
:) Sorry about this
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The stack and the heap are separate, and there's nothing an explicit call to run the garbage collector will do that the VM wouldn't have done on its own when space got tight.
I stand corrected.
Thanks:)