"Hi, Amigo!"

"Hi, Ellie!"

"I'm in a good mood today, so I feel like telling you something interesting. I'll start with how Java's type system deals with primitive types."

"In Java, each object and each variable has its own preset unchangeable type. A primitive variable's type is determined when the program is compiled, but an object's type is determined when it is created. The type of a newly created object and/or variable remains unchanged over the course of its lifetime. Here's an example:"

Java code Description
int a = 11;
int b = 5;
int c = a / b; // c == 2
a / b – represents integer division. The answer is two. The remainder from the division operation is simply ignored.
int a = 13;
int b = 5;
int d = a % b; // d == 3
d will store the remainder of integer division of a by b. The remainder is 3.

"There are a couple of interesting nuances that you need to remember."

"First, a reference variable doesn't always point to a value that has the same type that it has."

"Second, when variables with two different types interact, they must first be converted into the same type."

"What about division? If we divide 1 by 3, we'll get 0.333(3). Right?"

"No, that's not right. When we divide two integers, the result is also an integer. If you divide 5 by 3, the answer will be 1 with two as the remainder. And the remainder will be ignored."

"If we divide 1 by 3, we'll get 0 (with reminder 1, which will be ignored)."

"But what do I do if I want to get 0.333?"

"In Java, before performing division, it's best to convert a number to a floating-point (fractional) type by multiplying by a floating-point number one (1.0)."

Java code Description
int a = 1/3;
a will be 0
double d = 1/3;
 d will be 0.0
double d = 1.0 / 3;
d will be 0.333(3)
double d = 1 / 3.0;
d will be 0.333(3)
int a = 5, b = 7;
double d = (a * 1.0) / b;
d will be 0.7142857142857143

"Got it."