Primitive Data types in Java

Java programming language is very strong language. In java, all the variables and objects must have an explicit defined data type. The main role of this type is to tell the compiler that how much memory is needed to store the value of variable. In java we found that there are 2 types of data types.

1) Primitive data types.
2) Reference data types.

Primitive data types are name of reserved keywords. It is special data type built into the java language. The memory space is already allocated when the variables of primitive data types are created. But in reference data types, memory space has to be allocated using the new keywords. Java supports eight primitive datatypes. They are:-

Data type                     Description                              Size/Format                               Range

byte                           Byte-length integer             8-bit signed two's complement           -128 to 127

short                             short integer                    16-bit signed two's complement      -32,768 to 32,767

int                                    integer                         32-bit signed two's complement       -2147483648 to

                                                                                                                                         2147483647

long                               long integer                  64-bit signed two's complement -92223372854775808
                                                                                                                                           to
                                                                                                                             9223372036845775807

float                 single precision floating point      32-bit IEEE 754

double             double precision floating point     64-bit IEEE 754

char                       a single character                16-bit Unicode character

Boolean              a boolean value                       size is not precisely defined              True or False

Variable and Constant

Variables are things whose value can be changed. It is same in Java also. Variable is a location of a computer's memory where the value can be stored to use in the programming. Variable are defined by user friendly name. (,) used to group the multiple variables.

Constant are variables whose value are not changed. Java programming language do not support the constant directly.  Static final keywords are used to convert a variable to constant. The Final modifier cause the value of the variable unchanged.

Comments

Popular posts from this blog

Logical operator in JAVA

Class and Object in Java

Loop Structure