BigDecimal.compareTo — Compare decimal values
`BigDecimal.compareTo` compares numeric values without treating different scales as different values. Test its result against zero for ordering or numeric equality.
CKTIS / Java
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
`BigDecimal.compareTo` compares numeric values without treating different scales as different values. Test its result against zero for ordering or numeric equality.
Use this `divide` overload to set the quotient’s scale and choose a rounding rule. The result has the requested scale even when the division is exact.
Read decimal text without converting through `double`, calculate exactly, choose a scale and rounding rule, and compare numbers independently of their scale.
Multiply two `BigDecimal` values exactly, or round the product using the precision and rounding mode specified by a `MathContext`.
Set the scale of a `BigDecimal` while preserving its value or explicitly choosing how to round. The call does not change the original object.
Subtract two `BigDecimal` values exactly, or round the difference using a `MathContext`. Neither operand changes.
Use `toPlainString()` to write a `BigDecimal` without exponent notation. Parsing the resulting text restores the numeric value, but not always the original scale.
Learn the three `BigDecimal.valueOf` overloads in Java 21 and why converting a `double` with the factory can differ from passing it to the constructor.
Choose between immediate operations, timed waits, and waits with no timeout. Learn how to inspect the queue and why its head is not always the oldest item.
Get an independent copy of the bytes written in memory and learn why this stream remains usable after `close()`.
Write six bytes into a 32-byte direct buffer and see how `flip()`, `compact()`, and `clear()` change the range available for reading or writing.
Wrap an existing byte array without copying it, distinguish capacity from limit, and read a byte at a chosen index without moving the buffer’s position.
ByteOrder describes the byte ordering of multibyte values. Learn the difference between BIG_ENDIAN and LITTLE_ENDIAN and how to select data interpretation explicitly in ByteBuffer.
Character.charCount(int codePoint) returns the number of char units needed to represent a code point in UTF-16: either 1 or 2. The method does not validate its argument, so its result does not establish that a value is a Unicode code point.
CharacterCodingException is a checked exception in java.nio.charset that extends IOException. It signals a failure when converting between characters and bytes and provides a common catch type for malformed input and unmappable characters.
Check whether one Unicode code point is a letter, even when its UTF-16 representation takes two `char` code units.
This method returns a single `char`. Use it to uppercase the first UTF-16 code unit of a string, not to uppercase an arbitrary Unicode code point or a whole grapheme.
Drain the actual bytes returned by a UTF-8 encoder, then inspect the consumed CharBuffer through a read-only view with its own cursor.
Convert windows-1250 bytes to UTF-8 by decoding them into Unicode characters and then encoding those characters again. Choose how the decoder handles each kind of error.
ChronoUnit.DAYS.between(start, end) returns the number of complete days as a long. For LocalDate, it calculates the calendar-date difference; an end before the start produces a negative result.
Read repeatable annotations as an array and test for a marker annotation. Distinguish inherited lookup from lookup restricted to the class declaration.
When you have the target type in a `Class<T>` variable, use `cast` to get a reference of type `T` to the same object. Use `isInstance` to check a non-null value before casting.
Look up a constructor by its exact parameter types, then create an object in a separate step. The example uses the public no-argument StringBuilder constructor without bypassing access checks.
Read the declared types of a direct superclass and interfaces, and see why the runtime class of an ordinary `ArrayList<String>` cannot reveal the `String` argument.