title: StackOverflowError computing factorial of a BigInteger?
body: <p>I am trying to write a Java program to calculate factorial of a large number. It seems <code>BigInteger</code> is not able to hold such a large number.</p>
  
  <p>The below is the (straightforward) code I wrote.</p>
  
  <pre><code> public static BigInteger getFactorial(BigInteger num) {
        if (num.intValue() == 0) return BigInteger.valueOf(1);
  
        if (num.intValue() == 1) return BigInteger.valueOf(1);
  
        return num.multiply(getFactorial(num.subtract(BigInteger.valueOf(1))));
    }
  </code></pre>
  
  <p>The maximum number the above program handles in 5022, after that the program throws a <code>StackOverflowError</code>. Are there any other ways to handle it?</p>