Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Java / Java Basics

    The Whole Story

    The whole module retold as one story — no new facts, a fast revision of Java Basics.

    Extra: Revision3 min read

    A Java program is a recipe card with a fixed shape: a class, and inside it a main method where the cook starts reading. You write source code, javac compiles it to bytecode, and the JVM runs it — all three installed together as the JDK (Ch 1).

    Values live in labelled boxes — variables — each made for one type. Eight primitive types cover whole numbers (int by default, long when things might pass 2 billion), decimals (double), true/false (boolean) and single characters (char), with final for boxes that never change (Ch 2). Operators combine them, with traps worth knowing by heart: int / int throws away the fraction, % keeps the left side's sign, i++ hands over the old value, && and || stop early, a char is secretly a number (so c - 'a' is a position), and narrowing needs an explicit cast that chops rather than rounds (Ch 3).

    Text is a String — a string of beads with length, charAt, substring, compared with .equals, printed with printf, and parsed into numbers when it comes from outside (Ch 4). Programs decide with if/else if/else (first true wins), the ternary for small choices, and switch for many fixed values (Ch 5), and repeat with for when the range is known, while when only the stopping rule is, and for-each when only the items matter — always watching the first and last values for off-by-one mistakes (Ch 6).

    Repeated work becomes a method: a named recipe with parameters and a return value, each call living in its own stack frame, with variables that exist only in their scope — and Java always copies the value passed in, which for arrays and objects is a reference to the same thing (Ch 7). Many values of one type go in an array: a fixed row of numbered lockers, instant to reach by index because addresses are just arithmetic, guarded against out-of-bounds access, with Arrays helpers, 2-D grids and the counting trick (Ch 8).

    Put together, those pieces produce the StudyBuddy report — and they're also the entire toolkit of the LeetCode class Solution methods and fast-input templates you'll write for the rest of the year (Ch 9). What's missing is the other half of Java: objects — your own types, like Student and Quiz. That's the next file.