Java TutorialLesson 9Free preview
Java Type Casting
This lesson is part of Java · All levels
Summary
Type casting is the process of converting a data type of one value into another type. Widening casting runs automatically from smaller to larger types such as int to double, while narrowing casting must be written manually such as double to int. In narrowing, the decimal point is discarded so that the value can change.
Key points
- Widening casting runs automatically and doesn't lose key data
- Narrowing casting requires manual writing in a value manner (type)
- Doing narrowing from double to int will throw away the fraction.
- Uncarefully casting can result in inaccurate values and even overflow.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.