Widening and Narrow conversions : Primitive Type Casting « Type Casting « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Type Casting » Primitive Type Casting 




Java's widening conversions are

From a byte to a short, an int, a long, a float, or a double
From a short to an int, a long, a float, or a double
From a char to an int, a long, a float, or a double
From an int to a long, a float, or a double
From a long to a float or a double
From a float to a double

Narrow conversions

From a byte to a char
From a short to a byte or a char
From a char to a byte or a short
From an int to a byte, a short, or a char
From a long to a byte, a short, a char, or an int
From a float to a byte, a short, a char, an int, or a long
From a double to a byte, a short, a char, an int, a long, or a float














4.2.Primitive Type Casting
4.2.1.Widening and Narrow conversions
4.2.2.Implicit and explicit casting
4.2.3.Primitive Conversion: Assignment
4.2.4.Primitives widening rules during evaluating an arithmetic expression with two operands
4.2.5.The String + operator results in the concatenation of two String objects.
4.2.6.When one of the operands in a + operation is a String, then the other operand is converted to a String.
4.2.7.Casting and the += Operator
4.2.8.If the other operand is an object, then its toString() method is invoked to convert it to a String object.
4.2.9.Incompatible type Conversion
4.2.10.A boolean cannot be converted to any other type.
4.2.11.Java relaxes its assignment conversion rule
4.2.12.Relaxation of assignment applies only when the assigned value is an integral literal.
4.2.13.Primitive Conversion: Method Call
4.2.14.Incompatible type for method. Explicit cast needed to convert double to int for parameter passing
4.2.15.For unary operators, if the operand is a byte, a short, or a char, it is converted
4.2.16.Casting is explicitly telling Java to make a conversion.
4.2.17.Casts are required when you want to perform a narrowing conversion.
4.2.18.Cast any non-boolean type to any other non-boolean type.
4.2.19.You cannot cast a boolean to any other type; you cannot cast any other type to a boolean.
4.2.20.Conversion with Casting
4.2.21.You cannot simply convert a char to a short with code
4.2.22.Example of the method signature controlling conversion of primitives
4.2.23.Casting Primitives
4.2.24.A double value too small to be represented as a float becomes a positive or negative zero.
4.2.25.A double with the special NaN value becomes the float NaN value.
4.2.26.To assign a double value to an integer type
4.2.27.Cast the floating-point number into an int
4.2.28.Cast a floating-point number to an integer type. The value loses all the digits after the decimal.
4.2.29.Cast a larger number type, such as a long, into a smaller number type, such as a byte.
4.2.30.What happens if the long value is larger than 127 when casting long to byte
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.