Java Overview – Lesson 2 – Variables
Imagine that you have 1000 coffee beans, and you need to pack it into one box.
You have to determine the box size, put the label on the box to name it, and then fill the box with the coffee beans.
Based on this example in the Java world!
The box -> the Variable.
The box size -> The data type
The Label -> The variable name.
The coffee beans -> the Value.
Check the exam1 function
Download L2_Variables.java (22 downloads )The variable’s names rules.
To give a name to any variable it must meet some of the rules.
1 – The name must start with the English letter in any lettercase case capital or small.
2 – Not allowed to use any symbols except underscore _.
3- If you desire to use more than 1 name you can not separate those names using the backspace, but you can still use the underscore between every name such as the following.
my_name_is = “Ramy”; (Correct)
my name is = “Ramy”; (Wrong) X
4- You can use the camelcase letters as the following
myName = Ramy””;
5- You can add the numbers to the name just at the end or in the middle.
Year2023 = “My year”; (Correct)
Year2023is = “My year”; (Correct)
2003is = “My year”; (Wrong) X
6- The variable name is a sensitive case, which means you can define 2 variables using the same name, but you have to change the letter case for each one.
Name = “Ahmed”;
name = “Ali”;
NAME = “Mark”;
namE = “John”;