Search code examples
java-8bigdecimal

Differences of implementations from IBM and Oracle of java BigDecimal in java 8?


Can anybody explain me the differences of implementations from IBM and Oracle of java BigDecimal, in java 8?

I know that the IBM implementation of BigDecimal (com.ibm.math.BigDecimal) is deprecated and I want to move to the Oracle implementation (java.math.BigDecimal), but I'd like to know the main differences between the 2 versions (starting at version java 8).

Thanks.


Solution

  • IBM donated their code to Java 5.

    The BigDecimal implementation in OpenJDK is a continuation and evolution of that original IBM implementation. Notice the IBM copyright notice in the source code of OpenJDK. Perhaps the change history on that file might interest you.

    Since their donation, I know some serious improvements were made, though I cannot remember the details. There were talks given at JavaOne conferences addressing these improvements, bug fixes, and math-related issues.

    To migrate is utterly simple:

    • Change your import statements.
    • Know that any serialized objects cannot be read between the two implementations (being identified as coming from two different classes).

    To quote IBM:

    Enhanced BigDecimal

    From Java™ 5.0, the IBM® BigDecimal class has been adopted by Oracle as java.math.BigDecimal. The com.ibm.math.BigDecimal class is reserved for possible future use by IBM and is currently deprecated. Migrate existing Java code to use java.math.BigDecimal.

    The new java.math.BigDecimal uses the same methods as both the previous java.math.BigDecimal and com.ibm.math.BigDecimal. Existing code using java.math.BigDecimal continues to work correctly. The two classes do not serialize.

    To migrate existing Java code to use the java.math.BigDecimal class, change the import statement at the start of your .java file from: import com.ibm.math.; to import java.math.;.