Data Types in Java
Notes:
Data Types in Java Programming Language:
Data type:
As the name itself indicating, data type indicates type of data.
Note: While developing any software application; we come across different types of data and data values. We need to store and process them efficiently.
Game:
playerScore= 10; // playerScore is an integer type data
worldGravity =9.8; // worldGravity is a real type data
re-play=’y’; // re-play is a character type data
etc.
Banking application:
accountNumber=10; // accountNumber is an integer type data
rateOfInterest=13.5; // rateOfInterest is a real type data
hasLoan=’y’; // hasLoan is a character type data
etc.
Types of data types:
To store and process different types of data and data values efficiently;
JAVA provides mainly 2 types of data types.
1. Primitive or basic or built-in
2. Non primitive or derived or composite
Primitive types are again divided into:
Numeric types:
- allow us to store and process numeric values (i.e. integer & real numbers)
Nonnumeric types:
- allow us to store and process non numeric values (i.e. characters and Boolean values)
Numeric types are again divided into:
Integer types:
- allow us to store and process the integer numbers (i.e. a number without decimal point)
Ex: 22, -44, 2017, etc.
Real types:
- allow us to store and process a real numbers (i.e. a number containing decimal point)
Ex: 3.142, 9.8, 2.123456, 3.4E+38
Integer types are again divided into:
byte, short, int and long data types:
- allow us to store and process the +ve as well as –ve integer numbers
Ex: 22, -44, 128 etc.
Real types are again divided into:
float and double data types:
- allow us to store and process the real numbers containing 6 to 7, 14 to 15 digits after the decimal point
Ex: 3.142, 9.8, 2.123456, 3.4E+38
Non numeric types are again divided into:
boolean data type:
- allows us to store and process the Boolean values
Ex: true or false
char data type:
- allows us to store and process a symbol enclosed in between pair of single quotations
Ex: ‘A’, ‘9’, ‘$’, ‘\n’ etc.
Non primitive types are again divided into:
array:
- is used to store and process the list of data values
class:
- is used to store and process the information of an object
interface:
- is just a pure abstract class