Primitive Data Types in Java

By
Data types are the foundation of a programming language. There are 8 types of primitive in java: boolean, byte, char, double, float, int, long and short. 

  • The boolean data type holds value either true or false. The default value of the boolean is false. 
  •  The char data type represents a single character 'a', 'B', 'c'. It's 16-bit integer number(un-signed). Un-signed means non-negetive.
 The others are numeric data types in java (char is included as its number type). They are the following:
        
Integer Numbers:
  •  byte: 1 byte (8 bit) : Stores hole numbers from -128 to 127 
  •  char: 2 bytes (16 bit) : Stores hole numbers from 0 to 65535 
  •  short: 2 bytes (16 bit) : Stores hole numbers from -32768 to 32767
  •  int: 4 bytes (32 bit) : Stores hole numbers from -2147483648 to 2147483647 
  • long: 8 bytes (64 bit) : Stores hole numbers from -9223372036854775808 to 9223372036854775807  
Floating-point numbers:  
  1.  float: 4 bytes (32 bit): Store fractional numbers. Sufficient for storing 6 to 7 decimal digits.
  2.  double: 8 bytes (64 bit): Store fractional numbers. Sufficient for storing 15 decimal digits.

0 comments:

Post a Comment