Skip to content

OCP exam prep: primitives and references

☕ Java 17 · 🎓 OCP 1Z0-829 · Two Kinds of Data: Primitives and References

Optional page

This page is for readers preparing the Oracle Certified Professional Java SE 17 Developer exam (1Z0-829). The concepts are all you need otherwise.

Exam objective: Use primitives and wrapper classes; use local variable type inference.

Four traps to watch for

Trap 1 — Big whole numbers need L

long streams = 3_500_000_000; doesn't compile: the literal is an int, and it's too big. 3_500_000_000L works.

Trap 2 — Decimals are double

float rate = 4.5; doesn't compile. Write 4.5f.

Trap 3 — Underscore placement

Only between digits: 1_0.0 ✅, _10.0 ❌, 10_.0 ❌, 10._0 ❌, 100_ ❌.

Trap 4 — var needs a type to infer

var x = null; doesn't compile. var x = (String) null; does: the cast gives the type.

Practice questions

1. Which lines do NOT compile? (Choose all that apply. Each line is independent.)

A. long totalViews = 5_000_000_000;
B. float rating = 8.5f;
C. var genre = null;
D. double price = 9_99.99;
Answer

A and C. A: five billion doesn't fit in an int literal, it needs L. C: null gives var no type to infer. B is a valid float literal, and D has its underscore between digits.

2. What is the output?

Movie a = new Movie("Squid Game");
Movie b = a;
b.setTitle("Squid Game Season 2");
System.out.println(a.getTitle());

A. Squid Game
B. Squid Game Season 2
C. null
D. Compilation error

Answer

B. b = a copies the reference, not the object. Both variables point to the same Movie, so the change made through b shows through a.

← Back to the series · All 1Z0-829 pages