Introduction to Variables
Develop an understanding of variables and how the declaration of variables affect a Java program with the help of the examples provided in this lesson.
In this lesson, we will talk about the different types of variables and data types. It will include a reference variable that acts as a handle to the newly created object. There are a few rules and conventions that we should follow when we design and write the state of an object. Besides int
or boolean
, there are other data types; moreover, we should have a clear idea about assigning values to the variables. If we do not explicitly initialize them, are they assigned default values? Let’s learn all the techniques through examples.
Coding example: 14
In this example, we will talk about the core concept of Java. We know that local variables store their values in the ‘Stack’, whereas, the newly created objects are stored in ‘Heap’. However, the reference variable that acts as a handle to the object is stored in ‘Stack’. It only points to the new object.
Let’s see the coding example first. After that, we will discuss what actually happened.
Get hands-on with 1200+ tech skills courses.