Types and variables
We discussed Java’s primitive number types — int and double — and how to write expressions with them. Most of the operators we discussed were familiar but there were still a couple of surprises to be had. First, the modulo operator (%) was new to most. It calculates the remainder of integer division and you can see examples here. We also learned that integer division truncates (it doesn’t round) such that 13 / 5 would evaluate to 2.
We then talked about variables as a way to name spots in memory to store information for later. We learned that we always have to declare a variable before giving it a value by associating it with a type. Mixing types results in errors. For example:
String zach = "Ryan"; // a variable named zach refers to the text Ryan int bar; bar = 10; double foo = 10.2;
We can use variables anywhere we would use a literal value of the corresponding type.




