Before taking a deep dive into any programming knowledge, its very important to understand the basics. One of the most important thing to understand is data types. As long as you are a programmer you will always work with data types.
In Java there are two types of data types:
- Primitive
- Reference
Primitive Data Types
Integer Type
Under this type we have four other types,namely:
- byte has a size of 1 byte and holds integer -128 to 127
- short has a size of 2 bytes and holds integer --32,768 to 32,767
- int has a size of 4 bytes and holds integer -2 billion to 2 billion
- long has a size of 8 bytes and holds integer -2 quatrillion to 2 quatrillion Note it ends with an "L" 3999999999467898997777776088768759L
Decimal Type
Under this type we have two types,namely:
- float has a size of 4 bytes and holds fractional number up to 7 digits. Note it ends with an "f" 3.467899f
- double has a size of 4 bytes and holds and holds fractional number up to 15 digits. ****
Char Type
Single character / letter / ASCII value e.g 'h'. Has a size of 2 bytes
Boolean
Has a size of 1 bit and its either True Or False
Reference Data Types
String Type
A sequence of characters e.g 'hello world'. It has varying size.
Difference between Primitive and Reference Data Types
Primitive Data Types
- 8 types
- Stores data
- Can only hold one value
- Less memory
- Fast
Reference Type
- Unlimited(user defined)
- Stores an address
- Could hold more than one value
- More memory
- Slower
Top comments (2)
Hey I think short can hold more values than -128 to 127.
Refer: docs.oracle.com/javase/tutorial/ja...
Hello Thanks, that was an editing error. Glad you pointed it out