Friday, July 28, 2017

Java variables and its data types

This article specially deals to understand about the variables in Java and its data types. It really helpful for the Java Beginners and Selenium Freshers who want to be a professional selenium tester. First we need to try to understand what is variable ?

Generally variables are  used to store the data that may be number,character or String(group of characters). Variable can be also referred as name of the reserved area allocated in memory location.

How to declare a variable ?

 int a = 100;  // a is the variable of type Integer that holds the value 100 reserved in the RAM.

There are different types of variables available in Java. Those variables are given as below.


  1. Local variable
  2. Instance variable 
  3. Static variable

Local variable:


Variables that are declared with in methods and it will have scope with in that method


Instance variable:

Variables that are declared with in Class area but not with in methods are termed as Instance variables. It can be used by all the methods inside that class. It denotes the state of that specific class.

Static variable:

If the variables is declared as static then it can be used as local. Value of the variable can be changed only in static methods. Modification of static static variable will be reflected in the all the objects or instances using that variable.

What is meant by Datatype ?

Datatype is to denote that what type of data is going to be stored in specific variable. Two different types of datatypes are listed below.


·         primitive data types

·         non-primitive data types


Data Type
Default Value
Default size
boolean
false
1 bit
char
'\u0000'
2 byte
byte
0
1 byte
short
0
2 byte
int
0
4 byte
long
0L
8 byte
float
0.0f
4 byte
double
0.0d
8 byte