Java OCA 8 through a frontend developer's eyes
On this page
Why Java and why this exam
The goal is to be able to write backend in Java/Spring, not only frontend. A certificate by itself doesn’t get you a job. But preparing for it forces you to learn the core of the language down to the details, not “at Stack Overflow level”. The exam tests exactly the details: will this code compile, what will it print, which exception will it throw.
The book is the official Study Guide for this exam: 6 chapters, each with a list of exam objectives, a summary and review questions. At the start there’s an assessment test; at the end, answers with explanations and tips for preparing.
The plan in numbers
Each chapter’s pages are counted from the table of contents: the start of the next chapter minus the start of the current one.
| Chapter | Topic | Pages | Days at 10 pages/day |
|---|---|---|---|
| 1 | Java Building Blocks | 1–50 → 50 | 5 |
| 2 | Operators and Statements | 51–100 → 50 | 5 |
| 3 | Core Java APIs | 101–164 → 64 | 7 |
| 4 | Methods and Encapsulation | 165–232 → 68 | 7 |
| 5 | Class Design | 233–298 → 66 | 7 |
| 6 | Exceptions | 299–332 → 34 | 4 |
| Total | 332 | 35 |
Why 35 and not 332 / 10 = 33.2? Because the days are counted per chapter and rounded up: 64 pages is 7 days, not 6.4 — a partial day still takes a day. The sum of the rounded values: 5 + 5 + 7 + 7 + 7 + 4 = 35. This is rounding up (ceil) — the same as Math.ceil(64 / 10) in programming.
Where I am now
I’ve read 271 pages out of 332 — the middle of chapter 5, the section on interfaces.
- Read: 271 / 332 = 0.816 → 82%.
- Left: 332 − 271 = 61 pages.
- At 10 pages a day: ⌈61 / 10⌉ = ⌈6.1⌉ = 7 days → the chapters will be done by 16 November.
The ⌈ ⌉ brackets are the same rounding up: 6.1 days is still seven calendar days.
After that — not “read it and forgot it”, but revising chapters 1–4 through LeetCode problems (plan below) and practice tests. The target is December, when I start applying for jobs.
The self-check rule: after each chapter, the Review Questions without hints, the result as a percentage. Below 65% (the exam’s pass mark), the chapter is reread, not “I’ll sort it out later”.
Chapter 1. Java Building Blocks
What it covers: class structure, main(), packages and imports, constructors and initialisation order, primitives and reference types, variable scope, the garbage collector.
Where TypeScript gets in the way:
- There are eight primitives, and they have a fixed size. TypeScript has one
numberfor everything. Java hasbyte(8 bits),short(16),int(32),long(64),float,double, pluscharandboolean. The size decides whether a value fits:byteholds −128 to 127, because 8 bits give 2⁸ = 256 values, and half of them go to negative numbers. - A local variable without a value can’t be read. In TypeScript it’s
undefined. In Java it’s a compile error. Class fields, on the other hand, get a default value:0,false,null. - A wildcard import doesn’t reach into subpackages.
import java.util.*;doesn’t import classes fromjava.util.concurrent.
Exam trap: the order in which an object is initialised. First the fields and initialiser blocks — top to bottom, in the order they’re written — and only then the constructor body.
public class Order {
private String name = "поле";
{ System.out.println(name); } // блок инициализации
public Order() { name = "конструктор"; System.out.println(name); }
public static void main(String[] args) { new Order(); }
}
// напечатает: поле, затем конструкторMy Review Questions result: TODO
Chapter 2. Operators and Statements
What it covers: operators and their precedence, type promotion in calculations, if, switch, loops, break and continue with labels.
Where TypeScript gets in the way:
- Numbers are “promoted” in calculations. Arithmetic on
byteandshortalways givesint. Sobyte a = 1, b = 2; byte c = a + b;won’t compile: the right side isint, and it can’t be silently put into abyte. - Integer division. In Java
7 / 2is3, not3.5, if both numbers are integers. In JavaScript it’s3.5. ifonly accepts aboolean. No “truthiness”:if (count)with a number won’t compile. The JS habit of writingif (value)is an error here.- In Java 8,
switchworks withintand smaller types,char,Stringandenum, but not withlongorboolean.
Exam trap: x++ and ++x in the same expression. The postfix form returns the old value, the prefix form the new one:
int x = 3;
int y = x++ + ++x; // 3 + 5 = 8, а x в итоге 5My Review Questions result: TODO
Chapter 3. Core Java APIs
What it covers: String and the string pool, StringBuilder, comparing with == and equals(), arrays, ArrayList, wrappers and autoboxing, dates and times from java.time.
Where TypeScript gets in the way:
- On objects,
==compares references, not contents. Two different strings with the same text may not be equal by==. Contents are compared byequals(). In JS,===on strings compares values, so your hand writes==— and the answer is wrong. - Strings are immutable, as in JS:
s.toUpperCase()returns a new string and doesn’t changes. If you don’t assign the result, it’s lost. The exam loves code like that. - An array has a fixed length. Arrays have no
push; for a growing list there’sArrayList. substring(begin, end)doesn’t includeend— likeslicein JS. On the other hand,StringBuilder’s methodsappend,insert,deletechange the object itself, whilesubstringdoesn’t.- Dates are immutable.
date.plusDays(1)returns a new date. A call without assignment does nothing.
Exam trap: ArrayList<Integer> has two remove methods: by index (int) and by object (Integer):
List<Integer> list = new ArrayList<>(Arrays.asList(10, 20, 30));
list.remove(1); // удалит элемент с индексом 1 → [10, 30]
list.remove(Integer.valueOf(10)); // удалит значение 10 → [30]My Review Questions result: TODO
Chapter 4. Methods and Encapsulation
What it covers: declaring methods, access modifiers, static, passing parameters, overloading, constructors, encapsulation, immutable classes, simple lambdas and Predicate.
Where TypeScript gets in the way:
- Four access levels, not three.
private, no modifier (“package-private” — visible inside the package),protected(package + subclasses),public. TypeScript has no “inside the package” level. - Java always passes by value. For objects, the reference is passed by value. Assign a new object to the parameter, and the caller won’t see it. Call a method on the object, and it will. It’s the same as in JS, but the exam checks it at every step.
- Method overloading. In TypeScript, overloads are only types; the function has one body. In Java, several methods with the same name really are different methods, and the compiler picks the right one.
Exam trap: the order in which an overload is chosen. First an exact type match, then widening a primitive (int → long), then autoboxing (int → Integer), and only then varargs:
static void print(long x) { System.out.println("long"); }
static void print(Integer x) { System.out.println("Integer"); }
public static void main(String[] args) { print(5); } // long: расширение раньше упаковкиMy Review Questions result: TODO
Chapter 5. Class Design
What it covers: inheritance, calling parent constructors, overriding and hiding methods, abstract classes, interfaces with default and static methods, polymorphism and casting.
Where TypeScript gets in the way:
- Typing is nominal, not structural. In TypeScript an object fits an interface if it has the required fields. In Java a class fits only if it explicitly says
implements. - The first line of a constructor is always
this(...)orsuper(...). If you don’t write it, the compiler insertssuper(). And if the parent has no constructor without parameters, the code won’t compile. - Overriding and hiding. An ordinary method is overridden: the version of the actual object is called. A
staticmethod is hidden: the version for the variable’s type is called. Fields are hidden too, not overridden.
Exam trap: the rules for overriding. The method in the subclass must have the same signature, be no less accessible, declare no new or broader checked exceptions, and return the same type or a subtype.
My Review Questions result: TODO
Chapter 6. Exceptions
What it covers: what exceptions are for, checked and unchecked, try/catch/finally, common exceptions, throw and throws.
Where TypeScript gets in the way:
- Checked exceptions. In TypeScript any function can throw anything, and the compiler says nothing. In Java a checked exception (a subclass of
Exception, but not ofRuntimeException) must be either caught or declared inthrows. Otherwise the code won’t compile. - The order of
catchmatters. A block for a parent exception above the block for a child one is a compile error: the second block is unreachable. finallyruns almost always, even iftrycontains areturn.
Exam trap: throw and throws. throw new X() throws an exception inside a method; throws X in a method declaration warns that it may be thrown.
My Review Questions result: TODO
LeetCode for each chapter
The book teaches the language, but a junior or intern interview almost always includes a “write some code” task. So each chapter gets one or two problems where its topic is really needed. Not for the count: I write up each problem in leetcode/ from a template and set a confidence and a review date.
Legend: ✅ solved, ⬜ planned. The problems are chosen so that the chapter’s trap shows up in code, not only in a test.
| Chapter | Problem | Difficulty | What it reinforces |
|---|---|---|---|
| 1. Building Blocks | ⬜ 7. Reverse Integer | medium | int is 32 bits: overflow, checking against Integer.MAX_VALUE before multiplying |
| 1. Building Blocks | ⬜ 9. Palindrome Number | easy | integer division / 10 and remainder % 10 instead of converting to a string |
| 2. Operators | ⬜ 136. Single Number | easy | XOR (^): a ^ a = 0, a ^ 0 = a — a solution with O(1) memory |
| 2. Operators | ⬜ 191. Number of 1 Bits | easy | shifts: the difference between >> and >>> for negative numbers (JS has the same pair) |
| 3. Core APIs | ✅ 151. Reverse Words in a String | medium | String is immutable, split, StringBuilder |
| 3. Core APIs | ⬜ 242. Valid Anagram | easy | an int[26] array and char arithmetic: c - 'a' is a number |
| 3. Core APIs | ⬜ 1. Two Sum | easy | HashMap: one of the most common interview problems |
| 4. Methods | ✅ 206. Reverse Linked List | easy | references are passed by value: what changes for the caller and what doesn’t |
| 4. Methods | ✅ 21. Merge Two Sorted Lists | easy | the same: working with references in a loop; for revision, rewrite it recursively |
| 4. Methods | ⬜ 49. Group Anagrams | medium | a lambda in computeIfAbsent(key, k -> new ArrayList<>()) |
| 5. Class Design | ✅ 20. Valid Parentheses | easy | Deque (an interface) instead of Stack (a class); autoboxing of Character |
| 5. Class Design | ⬜ 155. Min Stack | medium | your own class: private fields, encapsulation, only the public methods needed |
| 5. Class Design | ⬜ 232. Implement Queue using Stacks | easy | implementing a given API on top of another structure |
| 6. Exceptions | ⬜ 8. String to Integer (atoi) | medium | what Integer.parseInt does and when it throws NumberFormatException; handling edge cases by hand |
Total: 4 solved, 10 planned.
Tricky spots worth checking in the problems
Integerand==. Comparing twoIntegerobjects with==works for numbers from −128 to 127 (they’re cached) and breaks for larger ones. In problem 20 I useequals— correct. It’s a common interview question.- A
charis a number.'b' - 'a' == 1, soint[26]instead ofHashMapfor letters. - Overflow is silent.
Integer.MAX_VALUE + 1gives a negative number without an error. In problems 7 and 8 that’s the whole point.
Pace
10 problems in 4 weeks: 2–3 problems a week after reading, and at weekends, revising the problems whose next_review date has come.
| Week | Problems |
|---|---|
| 10–16 November | finish chapters 5–6; 155, 232 |
| 17–23 November | 7, 9, 136 |
| 24–30 November | 191, 242, 1 |
| 1–7 December | 49, 8 + revise 20, 21, 151, 206 |
After the book: what else a Spring backend needs
The OCA book is about Java Core. A backend developer interview will also ask about:
- SQL — LeetCode has the SQL 50 set; start with 175 (Combine Two Tables) and 176 (Second Highest Salary):
JOIN,LIMIT/OFFSET,NULL. - Collections in more depth:
HashMapinternals,equals/hashCode. - Spring Boot: a pet project with a REST API and a database — it matters more than the number of problems solved.
How I study
- 10 pages a day, progress in the book card; problems in
leetcode/. - I type out every example from the book by hand and run it (
javac+java) rather than just reading it. The exam tests what code does, and you only see that by running it. - Before running it I write down my answer: “will it compile? what will it print?”. Then I compare. If I was wrong, I write down why.
- Review Questions without hints, the result goes into the table.
What’s next
After the book: practice tests and booking the exam. Then Spring Boot and a pet project: a certificate tests the language, but you get hired for what you can build with it.