what is data type?
A data type defines the kind of data a variable can hold. It tells the compiler what type of value the variable is expected to store, and how much memory to allocate for it.
There are two types of data type:
Primitive data type
Non-primitive data type.
Primitive data type:
- There are basically 8 primitive data type. They are
- byte-Integer from -128 to 127, and size is 1 byte. It can be represent as byte a=100; .The default value of byte is 0.
- short-integer from -32k to 32k, size is 2 byte. It can be represent as short b=1000; .The default value of short is 0.
- int-integer(default), size is 4 byte .It can be represent as int c=12345;.The default value of int is 0.
- long- large integer, size is 8 byte. It can be represent as long d=987654;.The default value of long is 0.
- float-decimal number (less precision), size is 4 byte. It can be represent as float e=3.09 f;.The default value of float is 0.0.
- double-decimal number (high precision), size is 8 byte. It can be represent as double f=54.78;.The default value of double is 0.0 .
- char-A single character, size is 2 byte. It can be represent as char g='p';. The default value of char is ''.
- boolean-true or false, size is 1 bit. It can be represent as boolean h=true;. The default value of boolean is false.
Non primitive data type:
String-sequence of characters. It can be represent as String i="flower";.The default value is "".
Top comments (0)