Thursday 20 October 2016

Primitive Data Types

Primitive data types


  • Primitive data type represents the values of integers (without decimals), floating point (with decimals), characterboolean.
  • Primitive data types are 8
                1) byte
                2) short
                3) int
                4) long
                5) float
                6) double
                7) char
                8) boolean (true, false)

These 8 separated in 4 categories:
1.   Integral
byte, short, int, long
2.   floating
float, double
3.   character
char
4.   boolean
boolean     
Integral data types :To represent values without decimals

Type
Size in Bytes
Range
  byte
  1 byte
  -128 to 127

  short
  2 bytes
  -32,768 to 32,767

  int
  4 bytes
  -2,147,483,648 to 2,147,483, 647

  long
  8 bytes
  -9,223,372,036,854,775,808 to
   9,223,372,036,854,775,807

Examples: 

        byte  a = 10;
        short b = 20;
        int d    = 30;
        long e  = 40;

byte, short, int, long              all these are data types
a, b, c, d                               all these are variables names.
10, 20, 30, 40                       all these are values        
 ;                                                       →        This is symbol of semicolon

100% Fact : 

Always datatype and variable will work together in programming. These couple of things will play major role. In upcoming chapter we will learn about variables and values

Floating point data type : To represent values with decimals

Type
Size in Bytes
Range
   float
   4 bytes
 -3.40282347E+38F to                      -3.40282347E+38F
  (6-7 significant decimal digits)

   double
   8 bytes
  -1.79769313486231570E+308 to         ±1.79769313486231570E+308
   (15 significant decimal digits)

Examples:

        float g = 1.23f;
        double h = 1.234d;
       
float, double                  all these are data types
g, h                              all these are variables names.
1.23, 1.23                     all these are values
 ;                                           →       This is symbol of semicolon

  
character data type :  To represent character values  

Type
Size in Bytes
Range
   char
   2 byte
   0 to 65,536 (unsigned)

Examples:

        char i = 'a';
       
char                              This is char data type
i                                  here i is a variable name.
a                                 here a is a value
;                                         →       This is symbol of semicolon


boolean data types : To represent true or false values

Type
Size in Bytes
Range
  boolean
  Not applicable
   true or false

Examples:

        boolean status1 = true;
        boolean status2 = false;
       
boolean                         This is boolean data type
status1, status2           here k is a variable name.
;                                            →      This is symbol of semicolon

Thanks for your time.
Nireekshan