Tutorial 2 Summary
In tutorial 2, we introduce the concept of variables and data types. A variable is like a container in your program. It's a place to store things. If you want to keep a number or some text, then you can put it in a variable.
Each variable has a data type, which just tells Java what you're going to put in that variable. There are several data types, but in this tutorial we will only cover the most useful ones. Those are:
intfloatdoublebooleanString
int, float, double, and
boolean are primitive data types. That means that they are
built into the Java language and Java does not need to look somewhere else to
find it. String is not a primitive data type, but it is used
so often that we include it here with the basic data types. It is
technically in the java.lang package, but don't worry
about that now; we'll cover stuff like that later.
To make a variable, you first state the data type of the variable, and then you put the name of the variable. You can't give the variable any name you want, and there are specific naming rules for variables. Don't worry about those too much. If you just remember to only use lower and upper-case letters, underscores, and numbers (don't start the variable with a number, though), then you should be fine. These are some examples of making variables:
int number = 2; float some_decimal = 4.5f; double anotherDecimal1234 = 2.71828; boolean MITisFun = false; boolean strongBadIsTheMan = true; String some_text = "I like coffee, I like tea...";
Note that each line ends with a semi-colon. That tells Java that
you're done with that statement. Unless a line ends with a curly
bracket like "{" or "}", you probably want to end it with a
semi-colon. Also note that after 4.5, there is an
"f". That tells Java that the number 4.5 is to be a
float, since Java likes to think that decimal numbers will be doubles.
The equals sign after the variables mean that you want to take whatever is after the equals sign and put it in the variable. The equals sign is called the assignment operator. You will see more operators later, but an operator is something that tells Java what you want it to do with some data. For example, "+", "-", "*", and "/" are all operators, and they tell Java to add, subtract, multiply, and divide. For example, if we say:
int a = 2+3; int b = 20-1; System.out.println(a); System.out.println(b);
then the numbers "5" and "19" will be printed to the screen.

