Java Data Types

 

 

Java  data  types  are  provided  basically  for  two  reasons:

 

(1)To know  the  type  of  value  which we are  using

 

(2)To know  how much  amount  of   memory is  allocating  for  each type of  input  value

 

 

 

Data types in  Java  are  classified  into  Two types:

 

 

(1)Primitive data types  

 

(2)User defined data types

 

 

 

 

(1) Primitive data types:

 

Primitive data  types are  data types which are  provided by  java  vendor   which have  fixed size,fixed range and  default values.

 

There are  8  primitive  data  types  in  Java

 

  1.  Boolean:  Boolean data type is a  primitive  data  type   whose default  value is  false,size is Not Defined and it can hold two values , either True/False.

 

        2.  byte:  byte  data type  is  a  primitive  data  type   whose default  value  is  0, size is  1  byte(8 bits)  and range  is  2^7-1   to -2^7  i.e.   -128  to  127

 

 

       3. Short:  short  data type   is  a  primitive  data type  whose  default value is   0 , size is  2  bytes(16 bits)   and  range is  2^15-1  to  -2^15

 

 

       4. int: int data  type  is  a  primitive  data  type  whose  default  value  is  0, size  is  4  bytes(32 bits)  and  range  is  2^31-1  to – 2^31

 

 

      5. long:  long   is  a   primitive data type  whose  default  value  is   0 , size  is  8 bytes(64 bits)   and  range  is  2^63-1  to – 2^63

 

 

     6. char: char  is  a  primitive  data type   whose   default  value  is  0 & \u0000, size is  2 bytes(16 bits), range is 2^16-1 to   0.

 

 

    7. Float: float  is  a  primitive  data type   whose  default  value is  0.0, size  is  4  bytes(32 bits), range is 2^31-1  to  -2^31

 

 

   8. double:  double is  a  primitive  data  type  whose  default  value  is 0.0, size is  8 bytes(64 bits)  and  range  is  2^63-1 to  -2^63

 

 

 

  (2) Non-Primitive  Data Types:

In  java, non-primitive  data  types  are   also  known  as  reference  data  types or  user defined  data  types. It   is  used  to  store   complex  objects  rather  than simple  values.

 

 

 Some  common  non primitive  data  types  are:

 

 

  1. Class:   One  common  non-primitive   data type  in  java  is  the Class. Classes  are  used  to  create  objects,which are  instance  of  class. A class  defines behaviors and  properties  of  objects.

 

 

 

       2.Interface:

       Interface are  one  of  the non  primitive  data type  in  java. Interfaces  are  used  to  achieve full  abstraction and  multiple           inheritance  in java.

 

 

 

 

 

    3. Arrays: Arrays   are  fundamental  non primitive  data  type  in  java  that  allows  to  store  multiple  values  of  same  type  in a  single  variable.

 

 

 

 

  4. Enum: Enum  are  one  of  the  non primitive  data types  in  java  which  are  used  to  define a set of  named   constants, providing  a  way  to  represent  a  fixed  set  of  values.

 

 

 

 

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *