Code
Data Types:
There are two types:
Primitive Data Types.
Object / Reference data types.
Primitive Data Types:
Primitive data types are those which are defined by java, there are 8 data types, let’s have a look on them with some description and examples.
int:
It is 32-bit signed and unsigned integer
If you don’t assign some value at initialization of variable then its default value is 0
For example int a; // now if you print it , it will show you ‘0’ on console
float:
It is 32-bit and upto 754 decimal floating point number.
For example float a = 1.2;
double:
It is 64-bit and upto 754 decimal floating point number.
For example double a = 1.256;
char:
It is 16-bit Unicode characters.
For example char temp = ‘A’;
boolean:
It represents true or false.
For example Boolean result = true;
long:
It is 64-bit signed integer
For example long a = 500000;
short:
It is 16-bit signed integer
For example short a = 500;
byte:
It is 8-bit signed integer
For example byte a = 500;
Object / Reference Data Types:
Usually we create reference data types while creating object of class i.e.,
Student st1 = new Student(); // object is created and its reference also
If,
Student st1 = null; // it means object has a reference null
0 comments:
Post a Comment