SaveMyCert
Log in
5 of 5 free questions left today·for 30 a day
1Z0-831 · Domain 1

Handling Date, Time, Text, Numeric and Boolean Values practice questions

Handling Date, Time, Text, Numeric and Boolean Values is worth 11% of the 1Z0-831 exam — the 2nd-heaviest of the 10 domains. Primitives and wrappers, expressions and casting, String/StringBuilder and text blocks, and the Date-Time API. Oracle publishes no domain weights; weight approximates the objective share, with a floor for every section. 6 fully worked examples are further down this page, answers included.

Exam weight
11%
the 2nd-heaviest of the 10 domains
Questions
105
across 3 topics
Free, no account
5/day
a free account allows 30 a day
Explanations
Every option
right and wrong

Build a practice session

5 free questions left today.

Domains

How many?

Mode

Ready when you are

10 fresh questions drawn across 1 of 10 domains, in Learn mode.

Focused review

Every question you answer incorrectly, and every question you flag while practising, is saved here automatically. Finish a session and you can come back to re-drill just those.

6 sample Handling Date, Time, Text, Numeric and Boolean Values questions, fully explained

Questions from the 1Z0-831 bank mapped to domain 1, with the answer key and the reasoning behind every option. None of them repeat the examples on the main 1Z0-831 practice page.

Question 1Handling Date, Time, Text, Numeric and Boolean Values

Given:public class Main { public static void main(String[] args) { short s = 100; s += 32700; System.out.println(s); } }What is the result?

Choose one.

  • a
    It prints 32800

    The sum is 32800 only as an int. Compound assignment casts it back to short, and 32800 does not fit in a short, so it wraps.

  • b
    Compilation fails

    s = s + 32700 would fail, but compound assignment includes an implicit cast to the left-hand type, so this line compiles.

  • c
    It prints -32736 Correct

    s += 32700 means s = (short) (s + 32700). The int sum 32800 is above Short.MAX_VALUE (32767), so the implicit cast keeps the low 16 bits and the value wraps to 32800 - 65536 = -32736.

  • d
    An exception is thrown

    Integer overflow in Java never throws by itself; the narrowing cast just discards the high-order bits. Only methods such as Math.addExact throw on overflow.

The concept

A compound assignment E1 op= E2 is equivalent to E1 = (T) ((E1) op (E2)), where T is the type of E1.

Why that’s the answer

The addition is done in int (32800), and the hidden cast to short keeps only the low 16 bits, giving -32736. The tempting answers either forget the hidden cast (compile failure) or forget that the cast can overflow (32800). Narrowing never throws.

How to reason it out
  1. Rewrite s += 32700 as s = (short) (s + 32700).
  2. Compute the int sum: 32800.
  3. Compare with the short range -32768 to 32767: it does not fit.
  4. Wrap: 32800 - 65536 = -32736.

Exam tip: op= hides a cast to the variable's type, so it compiles where the long form fails, and it can overflow silently.

Java Primitives, Wrapper Classes, Operators and Casting (1Z0-831) — the lesson that teaches this.

Question 2Handling Date, Time, Text, Numeric and Boolean Values

Given:public class Main { public static void main(String[] args) { int i = 300; byte b = (byte) i; double d = -7.9; int j = (int) d; System.out.println(b + " " + j); } }What is the result?

Choose one.

  • a
    It prints 44 -8

    -8 would be rounding down (Math.floor). A floating-point to int cast truncates toward zero, so -7.9 becomes -7.

  • b
    It prints 44 -7 Correct

    (byte) 300 keeps the low 8 bits: 300 - 256 = 44. (int) -7.9 truncates toward zero, giving -7.

  • c
    It prints 127 -7

    Narrowing an int to byte does not clamp to Byte.MAX_VALUE; it discards the high-order bits, so 300 becomes 44.

  • d
    It prints 127 -8

    Neither cast clamps or rounds down: (byte) 300 keeps the low 8 bits (44, not Byte.MAX_VALUE), and (int) -7.9 truncates toward zero (-7, not the floor -8).

The concept

Explicit numeric casts: integer narrowing keeps the low-order bits, and double-to-int truncates toward zero.

Why that’s the answer

300 in binary is 1_0010_1100; a byte keeps the low eight bits 0010_1100, which is 44. A floating-point to integer cast drops the fraction, moving toward zero, so -7.9 becomes -7. Clamping (127) and flooring (-8) are what a reader expects from other languages or from Math methods, not from a cast.

How to reason it out
  1. (byte) 300: subtract 256 until the value is in -128..127, giving 44.
  2. (int) -7.9: drop the fraction toward zero, giving -7.
  3. Remember neither cast clamps or rounds.
  4. Concatenate with the space: 44 -7.

Exam tip: Integer casts wrap; double-to-int casts truncate toward zero.

Java Primitives, Wrapper Classes, Operators and Casting (1Z0-831) — the lesson that teaches this.

Question 3Handling Date, Time, Text, Numeric and Boolean Values

Given:public class Main { public static void main(String[] args) { int a = -7; int b = 2; System.out.println(a / b + " " + a % b); } }What is the result?

Choose one.

  • a
    It prints -3 -1 Correct

    -7 / 2 is -3.5 truncated toward zero, so -3. The remainder satisfies (a / b) * b + a % b == a: -3 * 2 + (-1) = -7, so a % b is -1.

  • b
    It prints -4 1

    That pair comes from flooring division (Math.floorDiv and Math.floorMod). The / and % operators truncate toward zero instead.

  • c
    It prints -3 1

    The quotient is right, but the remainder takes the sign of the dividend (-7), so it is -1, not 1.

  • d
    It prints -4 -1

    Integer division does not round down for negative numbers; it truncates toward zero, so the quotient is -3.

The concept

Integer / truncates toward zero, and % returns a remainder with the sign of the dividend.

Why that’s the answer

Java's / on int discards the fraction toward zero, and % is defined so that (a / b) * b + (a % b) == a. With a = -7 and b = 2 that gives -3 and -1. The floor-based pair -4 and 1 belongs to Math.floorDiv and Math.floorMod.

How to reason it out
  1. Compute -7 / 2 = -3.5 and truncate toward zero: -3.
  2. Use the identity (a / b) * b + a % b == a.
  3. Solve: -6 + r = -7, so r = -1.
  4. Note the remainder sign follows the dividend.

Exam tip: / truncates toward zero and % takes the dividend's sign; Math.floorDiv and floorMod round down.

Java Primitives, Wrapper Classes, Operators and Casting (1Z0-831) — the lesson that teaches this.

Question 4Handling Date, Time, Text, Numeric and Boolean Values

Given:public class Main { public static void main(String[] args) { double x = 5 / 2; double y = 1.0 / 0; System.out.print(x + " " + y + " "); System.out.println(1 / 0); } }What is the result?

Choose one.

  • a
    2.5 Infinity is printed, then an ArithmeticException is thrown

    The division 5 / 2 happens in int before the result is assigned to a double, so it is 2, widened to 2.0, not 2.5.

  • b
    2.0 Infinity is printed, then an ArithmeticException is thrown Correct

    5 / 2 is int division (2), widened to 2.0. 1.0 / 0 is floating-point division and gives Infinity. The last line divides int by int zero, which throws ArithmeticException after the first print has run.

  • c
    2.5 Infinity Infinity is printed and the program ends normally

    5 / 2 is int division, so x is 2.0, not 2.5; and 1 / 0 divides two ints, which throws ArithmeticException instead of returning Infinity.

  • d
    2.0 Infinity Infinity is printed and the program ends normally

    1 / 0 has two int operands, so it is integer division, which throws ArithmeticException rather than returning Infinity.

The concept

Integer division by zero throws ArithmeticException; floating-point division by zero gives Infinity (or NaN for 0.0 / 0).

Why that’s the answer

The type of a division is decided by its operands, not by the variable that receives it. 5 / 2 is int arithmetic, so the fraction is lost before widening. 1.0 / 0 promotes 0 to 0.0 and follows IEEE 754, giving Infinity. 1 / 0 is pure int arithmetic and throws, but only after the earlier print has written its output.

How to reason it out
  1. Type each division by its operands, not by the target variable.
  2. 5 / 2 is int: 2, stored as 2.0.
  3. 1.0 / 0 is double: Infinity, no exception.
  4. 1 / 0 is int: ArithmeticException, after the first line is printed.

Exam tip: Int / 0 throws; double / 0 is Infinity; the target type does not change how a division is computed.

Java Primitives, Wrapper Classes, Operators and Casting (1Z0-831) — the lesson that teaches this.

Question 5Handling Date, Time, Text, Numeric and Boolean Values

Given:public class Main { public static void main(String[] args) { int x = 5; x = x++ + ++x; System.out.println(x); } }What is the result?

Choose one.

  • a
    It prints 12 Correct

    x++ yields 5 and sets x to 6; ++x then sets x to 7 and yields 7. The sum 5 + 7 = 12 is assigned to x last.

  • b
    It prints 11

    11 would be 5 + 6, treating ++x as if it saw the original x. The postfix increment has already made x 6, so ++x makes it 7.

  • c
    It prints 13

    13 would be 6 + 7, treating x++ as if it yielded the incremented value. Postfix yields the value before the increment.

  • d
    It prints 7

    The increments do happen, but the final assignment overwrites x with the sum of the two operand values, 12.

The concept

Postfix ++ yields the old value, prefix ++ yields the new value, and operands are evaluated left to right.

Why that’s the answer

Operands of + are evaluated left to right: x++ produces 5 (x becomes 6), then ++x makes x 7 and produces 7. The assignment runs last and stores 12, discarding whatever the increments left in x.

How to reason it out
  1. Evaluate the left operand: x++ gives 5, x is now 6.
  2. Evaluate the right operand: ++x makes x 7 and gives 7.
  3. Add the two values: 12.
  4. Assign last: x = 12.

Exam tip: Postfix gives the old value, prefix the new one; the assignment always happens last.

Java Primitives, Wrapper Classes, Operators and Casting (1Z0-831) — the lesson that teaches this.

Question 6Handling Date, Time, Text, Numeric and Boolean Values

Given:public class Main { public static void main(String[] args) { int i = 0; for (int n = 0; n < 3; n++) { i = i++; } int j = 0; j = j++ + j++; System.out.println(i + " " + j); } }What is the result?

Choose one.

  • a
    It prints 3 1

    i = i++ evaluates to the old value of i and assigns it after the increment, so the increment is overwritten on every pass and i stays 0.

  • b
    It prints 0 3

    3 would mean j kept both increments and added a third. The assignment replaces j with the sum of the two yielded values, 0 + 1.

  • c
    It prints 3 2

    Both values assume the increments survive the assignment. In both statements the assignment runs last and overwrites them.

  • d
    It prints 0 1 Correct

    i = i++ stores the old value back every time, so i stays 0. For j: the first j++ yields 0 (j is 1), the second yields 1 (j is 2), and the sum 1 is assigned to j.

The concept

In x = x++, the postfix expression yields the old value and the assignment overwrites the increment.

Why that’s the answer

The right-hand side is fully evaluated before the assignment. For i = i++ that value is the old i, so i never changes. For j = j++ + j++ the two postfix expressions yield 0 and 1 (left to right) and j is set to their sum, 1. Readers who let increments 'stick' get 3 or 2.

How to reason it out
  1. Evaluate the whole right-hand side before assigning.
  2. i = i++: yields 0, increments to 1, then assigns 0 back. Repeat three times: 0.
  3. j++ + j++: yields 0 then 1, sum 1.
  4. Assign 1 to j.

Exam tip: x = x++ leaves x unchanged: the assignment stores the value the postfix expression yielded.

Java Primitives, Wrapper Classes, Operators and Casting (1Z0-831) — the lesson that teaches this.

What 1Z0-831 domain 1 tests, topic by topic

The official exam guide breaks Handling Date, Time, Text, Numeric and Boolean Values into 3 topics. The question bank follows the same split, so a weak topic shows up as a cluster of misses you can go back and read.

Published 1Z0-831 practice questions per topic in Handling Date, Time, Text, Numeric and Boolean Values
TopicWhat it coversQuestions
Primitives, wrapper classes, operators and castingOfficial 1Z0-831 objective 1.1: "Use primitives and wrapper classes. Evaluate arithmetic and boolean expressions, using the Math API and by applying precedence rules, type conversions, and casting."35
Strings, StringBuilder and text blocksOfficial 1Z0-831 objective 1.2: "Manipulate text, including text blocks, using String and StringBuilder classes."35
Date-Time API: dates, times, durations, periods and time zonesOfficial 1Z0-831 objective 1.3: "Manipulate date, time, duration, period, instant and time-zone objects including daylight saving time using Date-Time API."35
Total105

Revise Handling Date, Time, Text, Numeric and Boolean Values before you drill it

Other 1Z0-831 domains

Handling Date, Time, Text, Numeric and Boolean Values: your questions

Handling Date, Time, Text, Numeric and Boolean Values is domain 1 of the 1Z0-831 exam guide and carries 11% of the scored content — the 2nd-heaviest of the 10 domains. On a 50-question paper that works out to roughly 6 questions, though Oracle does not publish an exact per-domain count and individual exam forms vary.

Source

The domain weight and topic list on this page come from the official 1Z0-831 exam guide.