After completing our first program we will study variables and data types in java. First, we will look at variables then we will move towards data types.
Variables are used to store some value in memory while the execution of the program. For example, you want to add two number it means you have to store these two numbers somewhere, so you can store these to numbers in variables. Example of defining and initialize variable in Java.
A Data type identifies a set of values and their representation in memory and set of operations that can transform these values into other values that set. Java is a strongly typed language. It means you can not write any variable without mentioning its data type. There are two types of data types in java.
- Primitive data types (built-in, predefined types )
- Non Primitive data types
Primitive Types:- Which are given by keyword to us in java like int, char, float etc. You can also say it predefined or built-in data types.
|boolean||true/false||1bit||true or false|
|byte||two’s complement integer||8bits||125|
|char||Unicode character||16bits||‘a’, ‘k’, ‘m’, ‘l’|
|short||two’s complement integer||16bits||25550|
|int||two’s complement integer||32bits||325000|
|long||two’s complement integer||64bits||32954861L|
|float||IEEE 754 Floating Number||32bits||4.65F|
|double||IEEE 754 Floating Number||64bits||54564.50D|
Non Primitive Types: In this kind of data types variable store reference(memory address) of value instead of direct value. Examples of Non-Primitive data types are String, Object, Array.