Java Variables
1) What is Variable?
A named retention place to shop or concur the data.
There are 2 types of retention inward Computer environment:
i) Primary retention -RAM
ii) Secondary retention -ROM
Ex: CD, DVD, HDD etc...
Note: Variables shop inward primary memory.
-------------------------
2) Declaration of Variables inward Java.
Java Supports explicit proclamation of variables
Syntax:
dataType VariableName;
Ex:
int a;
---------------
dataType variable1, variable2, variable3;
Ex:
int a, b, c;
------------------------
dataType VariableName = value;
Ex:
int a =100;
--------------------------
3) Assigning values to variables
a) Initialization
int a;
a=10; // Initialization
--------------
int a=10; // Initialization
----------------
b) Reading
using Input devices
from files(text/excel)
from databases
from Application objects
-------------------------
4) Types of Variables
a) Instance Variable
A variable that is declared within the shape only exterior the method
b) Local variable
A variable that is declared within the method
c) Static variables
A Variable that is declared equally static, It cannot live on local.
----------------------
5) Naming Conventions
> Java Variables are instance sensitive, monkey is non the equally Monkey or MONKEY.
char monkey, Monkey, MONKEY
> Java variable refer must offset alongside a missive of the alphabet or $ or _
Ex:
myvar
MYVAR
$myvar
_myvar
myvar1
myvar_1
----------
1myvar - invalid
----------------------
> Variable names cannot live on equal to coffee reserved words
Ex:
int
for
import
> Must live on unique inward the ambit of declaration.
----------------------------------------
6) Java Variables Declaration Example:
package JavaExamples;
public shape VariablesExamples {
populace static void primary (String [] args){
// dataType variableName;
int a;
a = 10;
// dataType VariableName = Value;
int b = 20;
// Declaration of multiple variables inward a statement
int c, d, e;
c =30;
d =40;
e = 50;
// Declaration of multiple variables in addition to assigning values
int f=60, g=70, h=90;
int j;
j = a; // Reading
char x ='A';
double y = 2.3456;
String z = "Selenium";
System.out.println (a);
System.out.println (b);
System.out.println (c);
System.out.println (d);
System.out.println (e);
System.out.println (f);
System.out.println (g);
System.out.println (h);
System.out.println (x);
System.out.println (y);
System.out.println (z);
System.out.println (j);
}
}
------------------------------------
Also Read:
Java Operators
Java Conditional Statements
Java Loop Statements
Java Arrays
Java Methods
Sumber http://www.gcreddy.com/
1) What is Variable?
A named retention place to shop or concur the data.
There are 2 types of retention inward Computer environment:
i) Primary retention -RAM
ii) Secondary retention -ROM
Ex: CD, DVD, HDD etc...
Note: Variables shop inward primary memory.
-------------------------
2) Declaration of Variables inward Java.
Java Supports explicit proclamation of variables
Syntax:
dataType VariableName;
Ex:
int a;
---------------
dataType variable1, variable2, variable3;
Ex:
int a, b, c;
------------------------
dataType VariableName = value;
Ex:
int a =100;
--------------------------
3) Assigning values to variables
a) Initialization
int a;
a=10; // Initialization
--------------
int a=10; // Initialization
----------------
b) Reading
using Input devices
from files(text/excel)
from databases
from Application objects
-------------------------
4) Types of Variables
a) Instance Variable
A variable that is declared within the shape only exterior the method
b) Local variable
A variable that is declared within the method
c) Static variables
A Variable that is declared equally static, It cannot live on local.
----------------------
5) Naming Conventions
> Java Variables are instance sensitive, monkey is non the equally Monkey or MONKEY.
char monkey, Monkey, MONKEY
> Java variable refer must offset alongside a missive of the alphabet or $ or _
Ex:
myvar
MYVAR
$myvar
_myvar
myvar1
myvar_1
----------
1myvar - invalid
----------------------
> Variable names cannot live on equal to coffee reserved words
Ex:
int
for
import
> Must live on unique inward the ambit of declaration.
----------------------------------------
6) Java Variables Declaration Example:
package JavaExamples;
public shape VariablesExamples {
populace static void primary (String [] args){
// dataType variableName;
int a;
a = 10;
// dataType VariableName = Value;
int b = 20;
// Declaration of multiple variables inward a statement
int c, d, e;
c =30;
d =40;
e = 50;
// Declaration of multiple variables in addition to assigning values
int f=60, g=70, h=90;
int j;
j = a; // Reading
char x ='A';
double y = 2.3456;
String z = "Selenium";
System.out.println (a);
System.out.println (b);
System.out.println (c);
System.out.println (d);
System.out.println (e);
System.out.println (f);
System.out.println (g);
System.out.println (h);
System.out.println (x);
System.out.println (y);
System.out.println (z);
System.out.println (j);
}
}
------------------------------------
Also Read:
Java for Selenium (Roadmap)
Java Introduction
Java Environment Setup
Java Program Structure
Java Modifiers
Java Introduction
Java Environment Setup
Java Program Structure
Java Modifiers
Java Conditional Statements
Java Loop Statements
Java Arrays
Java Methods