Java Programming/Large numbers

The integer primitive type with the largest range of value is the, from -263 to 263-1. If you need greater or lesser values, you have to use the  class in the package. A  object can represent any integer (as large as the RAM on the computer can hold) as it is not mapped on a primitive type. Respectively, you need to use the  class for great decimal numbers.

However, as these perform much slower than primitive types, it is recommended to use primitive types when it is possible.

BigInteger
The  class represents integers of almost any size. As with other objects, they need to be constructed. Unlike regular numbers, the  represents an immutable object - methods in use by the   class will return a new copy of a.

To instantiate a, you can create it from either byte array, or from a string. For example:

cannot use the normal Java operators. They use the methods provided by the class.

It is possible to convert to a, but the may not be large enough.

BigDecimal
The  class cannot handle decimal numbers. The  class represents a floating point value of arbitrary precision. It is composed of both a, and a scale value (represented by a 32-bit integer).

Googol = 10100