📝 Java Syntax — Variables, Data Types, Operators

Java Syntax — Variables, Data Types: When you declare a variable in Java you also write its type (`int count = 5;`), because Java is a statically typed language — like fixing bot

When you declare a variable in Java you also write its type (`int count = 5;`), because Java is a statically typed language — like fixing both the amount and the unit when a recipe says "2 cups of flour": you set the unit up front so you cannot later add the wrong ingredient. But if Python lets you just write `count = 5`, why bother writing a type for every variable in Java? Because the type declaration lets the compiler catch errors before the code runs; if you try to assign a string to an `int`, the code never runs at all. In Python that error only surfaces when a test happens to reach that line, whereas in Java it appears instantly at compile time. For a QA engineer this early warning is valuable: in a 500-line test util, a wrong type usage is caught in Java by a compile error before CI even starts, while in Python it explodes only when a specific scenario passing through that code path runs, giving you a false-green sense of confidence until then.

Java Program = Recipe Card

The notes break class/body/main method into visible parts; this turns that pattern into a visual flow.

Java Syntax — Hello World!

Micro Lab: Code practice

Replace the TODO line with the critical line from the expected solution. This is not a real runtime; the goal is to reinforce writing the correct structure in a controlled way.

Variables & Data Types

How Variables Live in Memory

Primitive values live directly on the stack; object types like String use a stack reference that points to the real object on the heap.

Variable types and declaration

Step by Step: Code practice

Identify goal and input

Complete the critical line

Check output or behavior