Flashcards

Quick study sessions to strengthen memory and retain key concepts.

Flashcard Study

Java: BigDecimal and Money

Front

When to avoid BigDecimal for performance?

In high-frequency low-precision scenarios. BigDecimal is slower than primitive types, so in scenarios needing high-frequency calculations with low…

View Card →
Flashcard Study

Java: BigDecimal and Money

Front

How to convert BigDecimal to a plain string?

Use toPlainString to avoid scientific notation. `toPlainString` converts a BigDecimal to a string without scientific notation, crucial for…

View Card →
Flashcard Study

Java: BigDecimal and Money

Front

Why does stripTrailingZeros on BigDecimal matter in practice?

Removes unnecessary zeros but may change scale. The `stripTrailingZeros` method removes unnecessary zeros from a BigDecimal's fractional part,…

View Card →
Flashcard Study

Java: BigDecimal and Money

Front

Why specify a rounding mode for BigDecimal division?

Avoids ArithmeticException and ensures predictable results. Dividing BigDecimals without a rounding mode can throw an ArithmeticException if the…

View Card →
Flashcard Study

Java: BigDecimal and Money

Front

How to handle BigDecimal scaling for currency?

Use setScale for consistent decimal places. When working with currencies, consistent scale (i.e., number of decimal places) is…

View Card →
Flashcard Study

Java: BigDecimal and Money

Front

What is domain correctness in financial code?

Ensuring values accurately represent real-world amounts. Domain correctness means that your code accurately models real-world financial scenarios, prioritizing…

View Card →
Flashcard Study

Java: BigDecimal and Money

Front

Why avoid equals for BigDecimal comparison?

Equals checks scale; compareTo checks value. Using `equals` to compare two BigDecimal values considers both value and scale,…

View Card →
Flashcard Study

Java: BigDecimal and Money

Front

How do you construct a BigDecimal for currency?

Use String or BigDecimal.valueOf(double) for precise construction. Constructing BigDecimal using a double can lead to precision errors due…

View Card →
Flashcard Study

Java: BigDecimal and Money

Front

Why use BigDecimal over float/double for money?

BigDecimal provides precise control over decimal calculations. Floating-point types like float and double can introduce rounding errors in…

View Card →
Flashcard Study

Java: BigDecimal and Money

Front

Why does money code usually prefer `BigDecimal` over `double`?

`BigDecimal` avoids floating-point surprises in financial calculations. Money logic often needs exact decimal reasoning. `double` is convenient for…

View Card →