Examples

Page 12 of 50

Browse code examples

javaSnippet

Class Name Forms For Diagnostics

Compare getName, getSimpleName and getCanonicalName across a plain class, a nested interface, an array and an anonymous class whose canonical name is null.

javaSnippet

CyclicBarrier Broken Barrier Reset

One timed-out await puts a CyclicBarrier into the broken state: later awaiters get BrokenBarrierException immediately, and reset() clears it for the next round.

javaSnippet

Longest Common Prefix Scan

Scan column by column to keep only the characters every string shares, so grouped keys like deploy-api and deploy-web reduce to their deploy- stem.

javaSnippet

Math Abs Integer Min Overflow

Math.abs(Integer.MIN_VALUE) does not throw: the documented contract returns the same negative value, so widen to long or guard the boundary before negating.

javaSnippet

Multi Catch Exception Types

One multi-catch clause handles NumberFormatException and DateTimeParseException together; the types must be unrelated or the compiler rejects it.

javaSnippet

String Intern Canonical Pool

String literals share one pooled instance, a new copy is equal but not identical, and intern() returns the canonical pooled instance for the same content.