Type Casting in Java — a practical guide to Java type casting with clear examples you can reuse in real projects.
Java Tutorial Series (12/90). Prefer one article? Read the complete Java tutorial.
Short description
Widening is safe/automatic (int→long). Narrowing needs an explicit cast and may lose data.
Casting
int a = 10;
double b = a; // widening
int c = (int) 9.8; // narrowing → 9