Primitive Data Types in java
Primitive Data Types
byte :
- size: 1 byte (8 bit)
- max value : 127
- min value: 128
- Range: -128 to 127
- a byte is the best choice, if we want to handle data in terms of streams either from file or form the network.
- syntax : byte b = 10;
- Default value : 0
short:
- size: 2 bytes (16 bit)
- Range: - 2 power 15 to 2 power 15 -1
- 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.
- syntax : short b = 10;
- Default value : 0
int :
- size: 4 bytes (32 bit)
- Range: -2 power 31 to 2 power 31 -1
- syntax : int b = 10;
- Default value : 0
long :
- size: 8 bytes (64 bit)
- Range : - 2 power 63 to 2 power 63 -1
- syntax : long b = 1051541;
- 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 :
- if we want 5 to 6 decimal point accuracy we go for float values.
- float follows a single precision.
- size: 4 bytes (16 bit)
- Range: - 3.4e38 to 3.4e38
- syntax : long b = 1051541.525;
- Default value : 0.0
double:
- if we want 14 to 15 decimal place accuracy then we should go for double.
- double follows double-precision
- size: 8 bytes (64 bits)
- Range : 17e38 to 17e38 -13.7e308 to 4.9e324
- syntax : double = 1051541.52554441;
- Default value : 0.0
boolean :
- size: N.A [VM dependent]
- Range: N.A [but true and false are allowed]
- syntax: boolean b = true
- Default value: false
char :
- 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.
- size: 2 bytes (16 bits)
- Range : 0 to 65535
- syntax : char b = "a";
- Default value : 0 [0 represet space character]
Comments
Post a Comment