Overview:
Let discuss about variables and it’s types,data types and it’s type.Primitive data type
Variables:
A variable is a container which holds the value while the user executed. A variable is assigned with a data type. Variable is a name of memory location. That is variable is the name of a reserved area allocated in memory. In other words, it is a name of the memory location. It is a combination of “vary + able” which means its value can be changed. There are three types of variables in java: local, instance and static. There are two types of data types in Java: primitive and non-primitive.

Types of variable :

1. Local Variable in Java
A local variable is a variable which has value within a particular method or a function. Outside the scope of the function the program has no idea about the variable. Consider a real life example, where you have an embarrassing nickname which is known to your parents. But no other person outside your house knows it, right?
That is exactly how a local variable works. It is known locally. Hence the name. Local variables cannot be declared static.
2. Java Instance Variable
Instance variables are those which are declared inside the body of a class but not within any methods. These differ with each instance of the class created although they have the same identity. [TBD]
3. Static Variables in Java
What if we want a variable that is shared across all the instances of a class? That’s where static variables come in. These are class- level variables which are the same for all the instances generated . As soon a class loads, the static variables get their initialization. [TBD]
Data Types in Java:
Data types specify the different sizes and values that can be stored in the variable. There are two types of data types in Java:
- Primitive data types: The primitive data types include boolean, char, byte, short, int, long, float and double.
- Non-primitive data types: The non-primitive data types include Classes, Interfaces, and Arrays.

Java Primitive Data Types:
In Java language, primitive data types are the building blocks of data manipulation. These are the most basic data types available in Java language
- boolean data type
- byte data type
- char data type
- short data type
- int data type
- long data type
- float data type
- double data type
boolean data type:
A boolean data type comprises of a bit of information and can store only true or false values. This data type is used to track true/false conditions.
byte data type:
This is an example of a primitive data type. It is an 8-bit signed two’s complement integer. It stores whole numbers that lie between -128 to 127. A byte data type is helpful for saving memory in large amounts.
char data type:
This data type is used to store a single character. The character must be enclosed within single quotes, like ‘E’ or ‘e’. Alternatively,can use ASCII[TBD] values to display certain characters.
short data type:
A short data type is greater than byte in terms of size and less than a integer. It stores the value that ranges from -32,768 to 32767. The default size of this data type: 2 bytes.
Int Data Type:
The int data type is a 32-bit signed two’s complement integer. Its value-range lies between – 2,147,483,648 (-2^31) to 2,147,483,647 (2^31 -1) (inclusive). Its minimum value is – 2,147,483,648and maximum value is 2,147,483,647. Its default value is 0.
Long Data Type:
The long data type is a 64-bit two’s complement integer. Its value-range lies between -9,223,372,036,854,775,808(-2^63) to 9,223,372,036,854,775,807(2^63 -1)(inclusive). Its minimum value is – 9,223,372,036,854,775,808and maximum value is 9,223,372,036,854,775,807. Its default value is 0. The long data type is used when you need a range of values more than those provided by int.
Double Data Type:
The double data type is a double-precision 64-bit IEEE 754 floating point. Its value range is unlimited. The double data type is generally used for decimal values just like float. The double data type also should never be used for precise values, such as currency. Its default value is 0.0d.
Float Data Type:
The float data type is a single-precision 32-bit IEEE 754 floating point.Its value range is unlimited. It is recommended to use a float (instead of double) if you need to save memory in large arrays of floating point numbers. The float data type should never be used for precise values, such as currency. Its default value is 0.0F.
Reference:
https://www.w3schools.com/java/java_data_types.asp
https://www.javatpoint.com/java-variables
Leave a comment