Introduction to Variables
Explore the fundamentals of variables in Java, including different data types, how reference variables work, and the importance of scope and initialization. Understand key concepts like call by value versus call by reference and how local and instance variables behave through practical code examples.
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 ...