Java SE 17 (1Z0-829) study materials
Java SE 17 (1Z0-829) study resources

Java SE 17 (1Z0-829): Handling date, time, text, numeric and boolean values

Java SE 17 (1Z0-829) · Work through your exam, one topic at a time.

All guide sections

Handling date, time, text, numeric and boolean values

Scope of the objective

This domain tests API selection and immutability more than memorized method lists. You must know String, StringBuilder, text blocks, wrapper classes, BigDecimal, and the java.time types, and predict results when operations cross leap years or daylight-saving transitions.

Text and numbers

  • String is immutable; concat, replace, strip, repeat, and indent return new objects. strip() removes Unicode whitespace, while trim() only removes characters <= U+0020. isBlank() checks whitespace-only content, and lines() splits on line terminators.
  • Text blocks start with """ followed by a line break; incidental indentation is removed, and \s preserves a trailing space.
  • Integer.valueOf caches -128..127, so == can be true for small boxed values and false outside the cache; use equals. Unboxing a null wrapper throws NullPointerException.
  • BigDecimal.equals compares scale as well as value; compareTo compares numeric value only. Double.NaN != Double.NaN.

Dates and times

LocalDate, LocalTime, and LocalDateTime are immutable and zone-free; ZonedDateTime and Instant are timeline types. Duration is time-based (hours/minutes/seconds), while Period is date-based (years/months/days). DateTimeFormatter.ofPattern uses MM for month and mm for minute.

Worked example

ZonedDateTime t = ZonedDateTime.of(2024,3,10,1,30,0,0, ZoneId.of("America/New_York")); t.plus(Duration.ofHours(1)) is 03:30 EDT because the clock jumps forward. t.plus(Period.ofDays(1)) is 2024-03-11T01:30 EDT because a period adds a calendar day and keeps local time.

Traps

Using Period for elapsed hours, calling LocalDateTime.now() when a zone is required, formatting with yyyy instead of uuuu for ISO week years, and assuming String methods mutate the receiver.