Strings and Unicode
Strings and Unicode: String is an immutable sequence of UTF-16 code units; length counts code units, so a supplementary character occupies two chars but one code point.
CKTIS / Java
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Strings and Unicode: String is an immutable sequence of UTF-16 code units; length counts code units, so a supplementary character occupies two chars but one code point.
Deterministic testing: A deterministic test arranges input, executes one behavior, and checks an observable result; a unit test isolates the contract of a small unit.
Time and zones in Java: The java.time API separates an Instant on the timeline, a Duration, a LocalDate, and a ZonedDateTime governed by ZoneId rules.
Type conversions in Java: Java performs implicit widening conversions, while primitive narrowing and reference casts require explicit syntax; boxing connects a primitive with its wrapper.
Type erasure gives `ArrayList<String>` and `ArrayList<Integer>` the same runtime class, but reflection can still read a type argument from a field declaration.
Java type system: Java has a static, nominal type system that distinguishes primitive from reference types and derives subtyping from declared inheritance and interface implementation.
Compare instances of value-based classes such as LocalDate using equals, not reference identity. Treat equal values as interchangeable and never use them as synchronization locks.
Variables and scope in Java: A Java variable has a declared or inferred type, scope, and lifetime; variables include fields, parameters, local variables, and array components.
Virtual threads in Java: A Java 21 virtual thread is a lightweight Thread implementation scheduled by the JVM for very large numbers of concurrent, mostly blocking tasks.
Use `BigDecimal.ZERO` with `compareTo` to check whether a discount amount is numerically zero, regardless of its scale.
Choose how `ByteBuffer` lays out multibyte values, use the same byte order to write and read them, and distinguish the buffer default from the platform’s native order.
Integer.MIN_VALUE and Integer.MAX_VALUE define the lower and upper bounds of Java's int type. Learn their values and the difference between int overflow and a calculation performed as long.
Use TimeUnit.MILLISECONDS to tell the timed poll and offer overloads of a blocking queue to interpret the timeout argument in milliseconds.
`TimeUnit` provides seven units from nanoseconds to days. Choose the unit that matches an amount, or convert different amounts to a common unit.
NumberFormatException signals that text cannot be converted to the requested numeric type. With Integer.parseInt, the cause can be either invalid notation or a value outside the int range.
UnsupportedOperationException means that the requested operation is not supported. It commonly occurs when attempting to modify an unmodifiable list, such as one created with List.of(...). The solution is to choose an object that supports the required operation, not merely catch the exception.
The abstract keyword: The abstract keyword marks an incomplete class that cannot be instantiated with new, or a bodyless method that a concrete subclass must implement.
The assert statement: The assert statement checks an internal assumption and throws AssertionError on failure, optionally carrying the value of the expression after the colon.
The break statement: An unlabeled break statement exits the nearest loop or switch statement, while a labeled break transfers control beyond its labeled block or loop.
case labels in switch: A case label selects a switch branch by constant, enum value, String, or type pattern; Java 21 can also handle null explicitly.
The catch clause: A catch clause handles an exception thrown from its associated try when the exception’s run-time type is assignable to the declared catch parameter type.
class — class declaration: The class keyword starts a class declaration, a named reference type with fields, methods, constructors, initializers, and member types.
const — reserved unused keyword: const is a reserved but unused Java keyword; it declares no constant and cannot be used as an identifier.
continue — advance to the next iteration: continue ends the current iteration of a while, do, or for loop and transfers control to that loop’s continuation point.