Data Types in Java are defined as specifiers that allocate different sizes and
types of values that can be stored in the variable or an identifier.
Java variable type conversion and type casting
the variables of one type can receive the value of another type.
Case 1: Variable of smaller capacity is to be assigned to another variable of
bigger capacity.
double d;
int i =10;
d=i;
This process is Automatic, and non-explicit is known as Conversion.
Case 2) Variable of larger capacity is be assigned to another variable of smaller
capacity.
double d=10;
int i;
i=(int)d;
In such cases, you have to explicitly specify the type cast operator. This
process is known as Type Casting.
Data Type Default Value Default size Range
boolean false 1 bit -
char '\u0000' 2 byte -128 to 127
byte 0 1 byte -32,768 to 32,767
short 0 2 byte
int 0 4 byte
long 0L 8 byte
float 0.0f 4 byte
double 0.0d 8 byte
public class TypeCon
{
public static void main(String[] args)
{
double d;
int i =10;
d=i; //Widening Type Casting
System.out.println("Value of d: " +d);
d= 10.7;
i=(int)d; //Narrowing Type Casting
System.out.println("Value of i: " +i);
}
}
Operators-
operators are used to perform operations on variables and values. java
divides into following groups:
Arithmetic operators- Arithmetic operators are used to perform common
mathematical operations.
Assignment operators-
Comparison operators
Logical operators
Bitwise operators