public class TypeConversionDemo
{
public static void main(String[] args)
{
int intVar = 200;
/*
* Variable of smaller capacity is be assigned to another variable of
* bigger capacity.
*/
long longVar = intVar; // no explicit type casting required
float floatVar = longVar; // no explicit type casting required
System.out.println("Int value : " + intVar);
System.out.println("Long value : " + longVar);
System.out.println("Float value : " + floatVar);
}
}
Output
Int value : 200
Long value : 200
Float value : 200.0
TypeCastDemo.java
public class TypeCastDemo
{
public static void main(String[] args)
{
double doubleVar = 200000.04;
/*
* Variable of larger capacity is be assigned to another variable of
* smaller capacity.
*/
int intVar = (int) doubleVar; // explicit type casting required
byte byteVar = (byte) intVar; // explicit type casting required
System.out.println("double value " + doubleVar);
System.out.println("int value " + intVar);
System.out.println("byte value " + byteVar);
}
}
Output
double value 200000.04
int value 200000
byte value 64
To Download VariableDemoTypeCastApp Project Click the below link
https://sites.google.com/site/javaee4321/java/VariableDemoTypeCastApp.zip?attredirects=0&d=1
See also:
All JavaEE Viedos Playlist
All JavaEE Viedos
All JAVA EE Links
Servlets Tutorial
All Design Patterns Links
JDBC Tutorial
Java Collection Framework Tutorial
JAVA Tutorial