← Java Programming learning pathJava Programming · Module 2 of 10
Variables and data types
Java is strongly typed: every variable has a declared type.
📖 Key ideas
- Primitive types: int, long, double, float, char, boolean, byte, short.
- String is a class for text: String name = "Asha";
- Declare then use: int age = 20;
- Casting converts types: (int) 3.7 gives 3.
- 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