CHAPTER 4. JAVA BASICS
environment. Let‟s continue with learning about variables used in Java in the next subsection.
Figure 4.7. Terminal output of our Java program in Android Studio
4.3. Variables in Java Variables are entities that contain information. Variables can be thought as boxes that hold data. The creation of variables is called “the declaration of the variable” and placing its value during its declaration is referenced as “initializing the variable”. We can insert the value of the variable during the declaration or later, depending on conditions. Just as real world boxes that can be used to hold different things like a sugar box, a match box or a component box, variables in programming languages also have different types. Java is defined as a statically and strongly typed programming language which means that the type of a variable should be defined during its creation and this type cannot be changed later. There are two variable type groups in Java: 1. Primitive variable types: These variable types hold single data at a time. In other words, primitive variables hold primitive values. Primitive variables always have values. Primitive variables exist from their creation to the end of a Java program. 2. Reference variable types: These “non-primitive” types are dynamic variables; they can be created and erased before the program ends. These variables store the addresses of objects they refer to. Unlike primitive 53