
Transitioning to Java
By :

Primitive data types create value variables. This means that once you declare variables in a program, you can use them in your code. However, before being represented by reference variables, classes must be instantiated into objects. But the values do not need to be instantiated.
In the CompoundInterest
program, we needed to instantiate the CompoundInterestCalculation
class before we can use it, as shown here:
var banker = new CompoundInterestCalculator04();
On the other hand, when we needed variables to hold principal
, annualInterestRate
, compoundPerTimeUnit
, and time
, we simply declared them, as shown in the following code line – we are directly assigning a value to the variable. We did not add the new
operator, which is responsible for converting classes into objects. Primitive data types are ready to go:
double principal = 100.0;
There are eight primitive types in Java. Before we look at them, let us quickly see what type safety means...