Type Casting (Cont.)


Narrowing Casting
Narrowing casting is to convert a larger-size type to a smaller-size type. It must be done manually by placing the type in parantheses in front of the value; for example:
     double myDouble = 10.0;
     int       myInt = (int) myDouble;
NCasting.java (narrowing casting)

 public class NCasting {
   public static void main( String[ ] args ) {     
     double myDouble = ;
     int       myInt = (int) myDouble;    // Manual casting: double to int
               myInt = myInt + myDouble;
     System.out.println( myInt );
   }
 }
Output:            

Review: Data Types
    Which statement is NOT true about Java data types?

      A primitive type can have a null value.
      Java is a statically-typed language.
      Java uses the Unicode system, instead of ASCII.
      The String is a non-primitive data type.
        Result:




      The bigger they are the harder they fall.