Object Oriented Programming: Unit I: Introduction to OOP and Java

Variables

Definition, initialization, declaration, Example | Java

A variable is an identifier that denotes the storage location.Variable is a fundamental unit of storage in Java. The variables are used in combination with identifiers, data types, operators and some value for initialization.

Variables

A variable is an identifier that denotes the storage location.

Variable is a fundamental unit of storage in Java. The variables are used in combination with identifiers, data types, operators and some value for initialization. The variables must be declared before its use. The syntax of variable declaration will be -

data_type name_of_variable [=initialization] [,=initialization][,...];

Following are some rules for variable declaration -

• The variable name should not with digits.

•  No special character is allowed in identifier except underscore.

•  There should not be any blank space with the identifier name.

• The identifier name should not be a keyword.

•  The identifier name should be meaningful.

For Example:

int a,b;

char m='a';

byte k=12,p,t=22;

The variables have a scope which defines their visibility and a lifetime.

Object Oriented Programming: Unit I: Introduction to OOP and Java : Tag: : Definition, initialization, declaration, Example | Java - Variables