Primitive Data Types: Part 1
Explore the concept of primitive data types in Java, how to declare variables with specific types, and understand why declaring variable types is essential in this statically typed language. Learn about the eight primitive types and the rules for sharing states between variables of the same type, including examples that demonstrate valid and invalid assignments. This lesson lays the groundwork for managing object states through variables in Java.
We'll cover the following...
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 ...