Java - 7 | Variables in Java | Rules for declaring the variables | Java Variable Assignment

preview_player
Показать описание
What is a Variable?
A variable can be thought of as a container which holds value for you during the life of your program.
Every variable is assigned a data type which designates the type and quantity of a value it can hold.
Syntax : - variable_name = value;
Physical Representation of a variable
10
x

Variable name: x
Value: 20
Data type: int

Rules to declare a Variable : -
Variable names are case-sensitive.
Every variable name should start with either alphabets or underscore ( _ ) or dollar ( $ ) symbol.
Additionally, the dollar sign character, by convention, is never used at all.
You may find some situations where auto-generated names will contain the dollar sign, but your variable names should always avoid using it.
A similar convention exists for the underscore character
while it's technically legal to begin your variable's name with "_", this practice is discouraged.
No space are allowed in the variable declarations.
Except underscore ( _ ) no special symbol are allowed in the middle of variable declaration
Variable name must not be a keyword or reserved word.
Capitalization of First Character of Second Word
If variable name contain two words then write first letter of second word in Capital Case.
If variable name contain single word then write that word in small case.
Example double salaryOfEmployee;

Java Variable Declaration : -
In Java we declare a variable like this
datatype name;

Example: Declaring a variable named myVariable of type int. int myVariable;
int myVariable1, myVariable2, …., myVariableN;

Java Variable Assignment : -
Assigning a value to a variable in Java follows this pattern: variableName = value ;
Here are three examples which assign values to three different variables with different data types
varByte = 107;
varFloat = 129.99;
varString = "This is a line";
Рекомендации по теме
Комментарии
Автор

It's easy to learn with this video.

HarshVerdhanRaj
visit shbcf.ru