Results for “Java”
Small, practical examples. Search by task or narrow things down below.
Validate a finite numeric value without coercion
JavaScript: Number.isFinite rejects numeric strings as well as NaN and infinity.
JavaScript✓ Tested
Validate a required argument
Java: Use requireNonNull with a useful message at an API boundary.
Java✓ Tested
Validate a whole ASCII identifier
JavaScript: Use an anchored expression without the multiline flag and reject a trailing line break explicitly.
JavaScript✓ Tested
Visit every item in a collection
Java: Print each element in the collection’s original order.
Java✓ Tested
Visit every item in a collection
JavaScript: Print each element in the collection’s original order.
JavaScript✓ Tested
Visit files recursively
Java: Close the stream returned by Files.walk and sort relative paths for stable output.
Java✓ Tested
Wait for multiple promises
Use Promise.all to collect JavaScript results in input order.
JavaScript✓ Tested
Write a UTF-8 file
Write a Java string to a file using an explicit text encoding.
Java✓ Tested
Write a UTF-8 file
Use the built-in Node.js filesystem API to save text.
JavaScript✓ Tested
Write and read binary bytes
Java: Use the byte-oriented Files methods when text encoding should not be involved.
Java✓ Tested
Write and read typed binary fields
Java: Data streams use a matching write/read order and fixed encodings for Java primitive values.
Java✓ Tested
Convert epoch milliseconds to whole seconds
TypeScript: JavaScript Date stores milliseconds while many APIs use Unix seconds.
TypeScript✓ Tested