Java Variables and common Data types
OK I have spent longer than I thought in this level (already 4 parts!) but here we will finish learning the concepts of the lesson. Now we can start working with the basics of programming in Java. First let's define some concepts:
Variables:
In computer programming, a variable is a storage location and an associated symbolic name which contains some known or unknown quantity or information, a value. The variable name is the usual way to reference the stored value; this separation of name and content allows the name to be used independently of the exact information it represents.Variables in programming may not directly correspond to the concept of variables in mathematics. The value of a computing variable is not necessarily part of an equation or formula as in mathematics. In computing, a variable may be employed in a repetitive process: assigned a value in one place, then used elsewhere, then reassigned a new value and used again in the same way. (Source)
The way to do this in Java is the following:
int a = 2; int b = 3; int c = a + b;
Here you are storing the values of numbers in the variables a and b, and then adding the values stored in a and b and saving that result to the variable called c. If you want to test this code, just write those lines of code inside the main method created before, and print the result (println). The result would be like this:
public static void main(String[] args)
{
int a = 2;
int b = 3;
int result = a + b;
System.out.println( "The value now stored in result is: " + result );
}
Note: Since Java is case sensitive, which means that if you call a variable something like myvariable, and then try to obtain the value stored in it by calling myVariable, you won't get the same result, make sure you keep the same name throughout the code. Again, Eclipse will warn you if you make this mistake, but still you should be careful.


