Notes / Java / Variables

Variables in Java — Revision Notes

A quick-reference cheat sheet: definition, syntax, example, common mistakes and an interview tip.

beginner 📖 2 min revision

Definition

📌 Variables Java is a statically typed language — every variable's type is declared and checked at compile time.

Syntax

syntax
type variableName = value;

Example

java
public class Main {
    public static void main(String[] args) {
        int age = 20;
        double price = 49.99;
        String name = "CodeyHub";
        System.out.println(name + " - " + age + " - " + price);
    }
}

Output

outputCodeyHub - 20 - 49.99

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview Know the difference between primitive types and reference types — a very common Java fundamentals interview question.
Back to notes Read full lesson →