...

/

Primitive Data Types: Part 1

Primitive Data Types: Part 1

Learn about primitive data types in Java and develop an understanding with the help of examples.

So far we have seen nine different examples, most of which have been integer values. We have also noticed one key thing at the time of declaring a variable, we write it like this: int speed = 0;.

This means we need to specify what type of variable it is. Stating the variable’s type and the name is essential because Java is statically-typed. This means that all variables should be declared before you can use it.

By naming and declaring a variable we actually declare the state of an object. In a Car class, when we declare a variable speed, our program knows that a field exists and that the field holds numerical data. It also has an initial value, such as 0 or 1.

The data type of a variable tells ...