← Java Programming learning path
Java Programming · Module 2 of 10

Variables and data types

Java is strongly typed: every variable has a declared type.

📖 Key ideas

  1. Primitive types: int, long, double, float, char, boolean, byte, short.
  2. String is a class for text: String name = "Asha";
  3. Declare then use: int age = 20;
  4. Casting converts types: (int) 3.7 gives 3.
  5. final makes a variable a constant.
💡 Real-life example: Types are labelled jars: you cannot pour sugar (text) into a jar marked "rice" (int).
int32-bit whole number
doubleDecimal number
booleantrue or false
finalCannot be reassigned