Primitive Data Types in java

Primitive Data Types 


Expect boolean and char remaining data types are consider assigned data types because we can represent both positive and negative numbers.

byte :

  1. size: 1 byte (8 bit)
  2. max value : 127
  3. min value: 128
  4. Range: -128 to 127
  5. a byte is the best choice,  if we want to handle data in terms of streams either from file or form the network.
  6. syntax : byte b = 10;
  7. Default value : 0

short:

  1. size: 2 bytes (16 bit)
  2. Range: - 2 power 15 to 2 power 15 -1
  3. the short data type is best suitable for 16-bit processors like 8085 but these processors are completed outdated and hence corresponding data type is also outdated datatype.
  4. syntax : short b = 10;
  5. Default value : 0
int :
  1. size: 4 bytes (32 bit)
  2. Range: -2 power 31 to 2 power 31 -1
  3. syntax :  int b = 10;
  4. Default value : 0
long :
  1. size: 8 bytes (64 bit)
  2. Range : - 2 power 63 to 2 power 63 -1 
  3. syntax : long b = 1051541;
  4. Default value : 0
All the above data types (byte, short, int, long ) use to represent integral values. if we want to represent floating-point values then we should go for floating-point data types.

float : 
  1. if we want 5 to 6 decimal point accuracy we go for float values.
  2. float follows a single precision.
  3. size: 4 bytes (16 bit)
  4. Range: - 3.4e38 to 3.4e38
  5. syntax : long b = 1051541.525;
  6. Default value : 0.0

double:
  1. if we want 14 to 15 decimal place accuracy then we should go for double.
  2. double follows double-precision
  3. size: 8 bytes (64 bits)
  4. Range : 17e38 to 17e38  -13.7e308 to 4.9e324
  5. syntax : double  = 1051541.52554441;
  6. Default value : 0.0
boolean :
  1. size: N.A [VM dependent]
  2. Range: N.A [but true and false are allowed]
  3. syntax: boolean b = true
  4. Default value: false
char :
  1. old languages (like c or c++ or ASCII code-based and the number of allowed different code characters are less than or equal to 256) to represent this 256 characters 8 bits are enough hence the size of char in the old language is 1 byte. but java is Unicode based and the number of different characters is greater than 256. to represent these many characters 8 bits may not enforce compulsory we should go for 16 bits hence the size of char in java is 2 bytes.
  2. size: 2 bytes (16 bits)
  3. Range  : 0 to 65535
  4. syntax : char b = "a";
  5. Default value : 0 [0 represet space character]

Comments

Popular posts from this blog

let - Keyword in JavaScript (Block scope)

Coding Problem 4: Smallest window containing 0, 1 and 2 [GFG - Problem Solving]