Topic 1 - Variables and Data Types
Topic 2 - Conditionals and Strings
Topic 3 - Loops
Topic 4 - Arrays
Topic 5 - File Handling
Semester 1 Projects
Topic 6 - Classes/Objects and Methods
Topic 7 - ArrayLists
Semester Projects

Operators

Java uses the standard mathematical operators for addition (+), subtraction (-), multiplication (*), and division (/) and modulo divsion (%). (modulo division is explained below.)
Java uses (==) to test if the value on the left is equal to the value on the right, and (!=) to test if two items are not equal.

Pay special attention to the output of the code below. What does 2 / 3 print? Why?

Modulo

The percent sign operator (%) is the modulo or remainder operator. The modulo operator (x % y) returns the remainder after you divide x (first number) by y (second number), so 5 % 2 will return 1 since 2 goes into 5 two times with a remainder of 1. Remember long division when you had to specify how many times one number when into another evenly and the remainder? That remainder is what is returned by the modulo operator.

The result of x % y when x is smaller than y is always x. The value y can’t go into x at all (goes in 0 times), since x is smaller than y, therefore, the result is just x. So if you see 2 % 3, the result is 2.

Shortcut Operators

You are also expected to know the double plus operator (++) and the double minus operator (--).
The ++ operator is used for adding one to the current value: x++ is the same as x = x + 1.

The -- operator is used for subtracting one from the current value: y-- is the same as y = y - 1.

You should know that x += y is the same as x = x + y
x -= y is the same as x = x - y
x *= y is the same as x = x * y, and 
x /= y is the same as x = x / y.

Casting

In Python you might have been used to turning int’s into float’s and vice-versa by doing something like this:

my_variable = int(some_float_variable)

In Java, the syntax is slightly different, but the semantics (meaning) is the same:

int variable1    = (int) someDoubleVariable;    // cast a double to an int
double variable2 = (double) someIntVariable;    // cast an int to a double

Java assumes that if you are performing division with integers that you want an integer result, thus, it will throw away any fractional part (the part after the decimal point).
If you use a mixture of integers (int) and floating-point (double) numbers, Java will assume that you want a floating-point result. If you have integers and you want a floating-point result from some mathematical operation, cast one of the integers to a double using (double) as shown above.
By casting we don’t mean something to do with fishing, but rather it is similar to the idea of casting a pot in clay. In Java, when you cast, you are changing the “shape” (or type) of the variable to the right of the cast to the specified type.

Casting doesn’t work with Strings in Java. if you want to turn an int into a string you can instead concatenate (combine it) to an empty string. Try it out below!

int myNum = 5;
String newStringNum = myNum + "";

String s = "my age is: " + 20;   // 20 is cast to "20"; result is "my age is: 20"

Side bar: Casting Up vs Casting Down
Each Java type has a size. For example, an int is 32 bits while a double is 64 bits. We say that a double is larger than, or wider than, an int. A smaller type can easily “fit” in a larger type. A larger type will not “fit” into a smaller type. When we cast a smaller type to a larger type, that is casting up. When we cast a larger type to a smaller type, that is casting down.
When we cast down, we are corercing the compiler to do something it would not normally do. We are telling the compliler, don’t worry, I know what I am doing; I do not care if I lose the fractional part of the number if I assign an int to a double. See the example below.

int varInt = 10;
double varDouble = 10.5;

// up cast. 10 will become 10.0 and then assigned to varDouble
varDouble = varInt; 

// explicit up cast
varDouble = (double) varInt;

// down cast; explicit cast is required 
varInt = (int) varDouble;