Report: Type Casting, Type Conversion & Automatic Type Promotion in Java
1. Introduction
Java is a strongly typed language. It supports two main ways of converting data:
Type Conversion (Implicit) and Type Casting (Explicit). Java also performs automatic
type promotion inside expressions.
2. Type Conversion (Implicit Conversion)
Implicit conversion happens automatically when a smaller data type is assigned
to a larger type. Also known as widening conversion.
Widening Hierarchy: byte → short → int → long → float → double
Example:
int a = 50;
double b = a;
3. Type Casting (Explicit Conversion)
Type casting is manual and used for narrowing conversion.
Example:
double x = 45.78;
int y = (int)x;
4. Automatic Type Promotion in Expressions
Java promotes smaller types to larger ones when evaluating expressions.
Rules:
• byte, short, char → int
• If long present → result long
• If float present → result float
• If double present → result double
Example:
byte a = 10; byte b = 20;
byte c = (byte)(a + b);
5. Difference Table
Type Conversion: Automatic, widening, safe.
Type Casting: Manual, narrowing, may lose data.
6. Conclusion
Type conversion and type casting help manage data safely in Java.
Automatic type promotion allows mixed-type expressions to execute correctly.