CS 151 Lecture Notes - Lecture 6: Standard Streams, String Literal
Document Summary
A conversion between one primitive type and another falls into one of two categories: widening conversions and narrowing conversions. Widening conversions: translate data into another data type that uses equal or greater space, safest conversion because it does not lose info, can lose precision (because of rounding least significant digits) Narrowing conversions: more likely to lose info, translates data into data type that uses less space, should be avoided. Assignment conversion: occurs when a value of one type is assigned to a variable of another type during which the value is converted to the new type. Promotion: occurs automatically when certain operators need to modify their operands in order to perform the operation. Similar conversion is taking place when a number is concatenated with a string. Casting: most general form of conversion in java. A cast is a java operator that is specified by a type name in parentheses. Placed in front of the value to be converted.