1Z0-771 study materials
1Z0-771 study resources

1Z0-771: Java Fundamentals and Data Types

1Z0-771 · Work through your exam, one topic at a time.

All guide sections

Java Fundamentals and Data Types

Domain 1 tests whether you can read a short snippet and decide whether it compiles and what it prints: primitive widths, literal syntax, promotion and casting, var, arrays, and String equality.

Primitives and literal rules

  • Eight primitives: byte (8 bits), short (16), int (32), long (64), float (32), double (64), char (16, unsigned), boolean.
  • Integer literals are int unless suffixed L; floating-point literals are double unless suffixed f. Prefixes: 0x hex, 0b binary, leading 0 octal.
  • Underscores may only separate digits: 1_000_000 compiles; _100, 100_, 1_.0 and 1.0_f do not.

Promotion and casting

  • Binary numeric promotion widens to double, else float, else long, else int. byte, short and char always promote to int in arithmetic.
  • Widening is implicit; narrowing needs a cast. Compound assignment (+=) and ++/-- apply an implicit cast, which is why b += 3 compiles when b = b + 3 does not.

var, arrays, String

  • var is legal only for local variables with an initializer; not for fields, parameters, or null.
  • Arrays are covariant: Object[] o = new String[1]; compiles, but storing an Integer throws ArrayStoreException at runtime. length is a field, not a method.
  • String is immutable and pooled; == compares references, so use equals for content.

Worked example

byte b = 5;
b = b + 3;      // compile error: int cannot be assigned to byte
b += 3;         // compiles; implicit cast to byte
long n = 1_000 * 1_000_000_000L; // int * long -> long

The first assignment fails because b + 3 is an int. The compound form hides the cast, so no error.

Traps

  • switch accepts int-compatible types, String and enums, never long, float or boolean.
  • char c = 'a' + 1; is legal (constant expression in range); char c = 'a' + 1L; is not.
  • var is resolved at compile time, so var x = 1; x = "s"; fails.