Java Variables and Data Types With EXAMPLE
Java Variables and Data Types With EXAMPLE
html
1. Variable Declaration
2. Variable Initialization
• Variable Declaration
• Variable Initialization
• Types of variables
• Data Types in Java
• Type Conversion & Type Casting
Variable Declaration:
To declare a variable, you must specify the data type & give the variable a unique
name.
1 of 9 9/20/21, 10:12
Java Variables and Data Types with EXAMPLE https://www.guru99.com/java-variables.html
int a,b,c;
float pi;
double d;
char a;
Variable Initialization:
To initialize a variable, you must assign it a valid value.
pi =3.14f;
do =20.22d;
2 of 9 9/20/21, 10:12
Java Variables and Data Types with EXAMPLE https://www.guru99.com/java-variables.html
Example :
int a=2,b=4,c=6;
float pi=3.14f;
double do=20.22d;
char a=’v’;
Types of variables
In Java, there are three types of variables:
1. Local Variables
2. Instance Variables
3. Static Variables
1) Local Variables
Local Variables are a variable that are declared inside the body of a method.
2) Instance Variables
Instance variables are defined without the STATIC keyword .They are defined Outside a
method declaration. They are Object specific and are known as instance variables.
3) Static Variables
Static variables are initialized only once, at the start of the program execution. These
3 of 9 9/20/21, 10:12
Java Variables and Data Types with EXAMPLE https://www.guru99.com/java-variables.html
1. Primitive Data Types :- which include integer, character, boolean, and float
2. Non-primitive Data Types :- which include classes, arrays and interfaces.
4 of 9 9/20/21, 10:12
Java Variables and Data Types with EXAMPLE https://www.guru99.com/java-variables.html
float (4 bytes)
double (8 bytes)
char (2 bytes)
Logical
byte 0 1 byte
5 of 9 9/20/21, 10:12
Java Variables and Data Types with EXAMPLE https://www.guru99.com/java-variables.html
6 of 9 9/20/21, 10:12
Java Variables and Data Types with EXAMPLE https://www.guru99.com/java-variables.html
7 of 9 9/20/21, 10:12
Java Variables and Data Types with EXAMPLE https://www.guru99.com/java-variables.html
About
About Us
Advertise with Us
Write For Us
8 of 9 9/20/21, 10:12