0% found this document useful (0 votes)
16 views1 page

Data Types

The document explains data types in Java, detailing how they specify the size and type of values stored in variables. It covers type conversion and type casting, illustrating automatic conversion from smaller to larger types and explicit casting from larger to smaller types. Additionally, it lists Java data types with their default values, sizes, and ranges, and briefly describes various operator categories used in Java programming.

Uploaded by

Varshika M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views1 page

Data Types

The document explains data types in Java, detailing how they specify the size and type of values stored in variables. It covers type conversion and type casting, illustrating automatic conversion from smaller to larger types and explicit casting from larger to smaller types. Additionally, it lists Java data types with their default values, sizes, and ranges, and briefly describes various operator categories used in Java programming.

Uploaded by

Varshika M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

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

You might also like