Java Numeric Data Type

Java Data Type
1. Java is strongly typed programming language
e.g. int x = 10.6; Wrong
Boolean a = 0; Wrong
2. Java is not considered as pure object-oriented language as it used primitive data types which are not an object. Also, operator overloading and multiple inheritances are not supported.

Watch here:

Primitive data types
1. Numeric Data Type
2. Non-Numeric Data Type
a. char
b. boolean

Numeric Data Type
1. Integral Data Type
a. byte ( 8 bit) (MAX_VALUE = +127 , MIN_VALUE = -128) (RANGE = -128 to +127)
e.g. byte b = 127 , byte b = 128 (Incorrect), byte c = 10.5 (incorrect), byte d = true
* If we want to handle data in terms of streams then we use byte

b. short (2 bytes – 16 bits) (RANGE – -2^15 to 2^15-1) (-32768 to 32767)
* No one is used short data type
e.g. short s = 32767, short s = 32768 (wrong)
* Short is used for a 16-bit processor like 8085, 8086 because of reading and writing process is easy and efficient. But now they are outdated so no one is using short data type.

c. int (4 bytes – 32 bits) (Range -2^31 to 2^31-1) (-2147483648 to 2147483647)
* Most common data type is int
e.g. int x = 2147483647, int x = 2147483648 (wrong), int x = 2147483648L

d. long ( 8 bytes – 64 bits) (Range -2^63 to 2^63-1)
* If we want to count all characters present in a big file then we use long

Leave a Reply

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