Results for “Java”
Small, practical examples. Search by task or narrow things down below.
Display an integer as unsigned
Java: Use unsigned conversion methods when interpreting a fixed-width bit pattern.
Java✓ Tested
Distinguish an own property from an inherited one
JavaScript: Object.hasOwn avoids depending on an object’s possibly shadowed hasOwnProperty method.
JavaScript✓ Tested
Divide decimal values with controlled precision
Java: Choose both scale and rounding for a quotient that does not terminate in base ten.
Java✓ Tested
Divide negative integers with floor rounding
Java: floorDiv and floorMod provide consistent floor-based quotient and remainder.
Java✓ Tested
Divide using a fractional number
Java: Use a floating-point operand to preserve the fractional part of a division.
Java✓ Tested
Divide using a fractional number
JavaScript: Use a floating-point operand to preserve the fractional part of a division.
JavaScript✓ Tested
Drop the fractional part toward zero
JavaScript: Math.trunc differs from floor for negative inputs.
JavaScript✓ Tested
Encode a form query parameter
Java: URLEncoder uses application/x-www-form-urlencoded rules, including plus signs for spaces.
Java✓ Tested
Encode and decode Base64 bytes
Java: Convert through UTF-8 explicitly before and after Base64 encoding.
Java✓ Tested
Explain a calculation with a comment
Java: Keep the code executable while documenting why a fixed input is used.
Java✓ Tested
Explain a calculation with a comment
JavaScript: Keep the code executable while documenting why a fixed input is used.
JavaScript✓ Tested
Extract all regex matches with their groups
JavaScript: matchAll requires a global regular expression and returns an iterator of matches.
JavaScript✓ Tested