public class FactorialRec { public static int factorial(int n) { if (n == 1) { return 1; } return n * factorial(n-1); } public static void main(String[] args) { System.out.println(factorial(0)); } } // > java FactorialRec // Exception in thread "main" java.lang.StackOverflowError // at FactorialRec.factorial(FactorialRec.java:9) // > java FactorialRec 2>&1 > /dev/null | grep -c 'at FactorialRec.factorial' // 1024 // > java FactorialRec 2> /dev/stdout 1> /dev/null | grep -c 'at FactorialRec.factorial' // 1024