Java - double type and integral types cast

Introduction

The value of all integral types (int, long, byte, short, char) and float can be assigned to the double data type without using an explicit cast.

  
int num1 = 15000; 
double salary = num1;             // Ok. int to double assignment 
salary = 12455;                   // Ok. int literal to double 
double bigNum = 1226L;                   // Ok, long literal to double 
double justAChar = 'A';           // Ok. Assigns 65.0 to justAChar 
  

A double value must be cast to the integral type before assigning to any integral data type.

int num1 = 10; 
double salary = 10.0; 
num1 = salary;      // A compile-time error. Cannot assign double to int 
num1 = (int)salary; // Now Ok.