Variables Of Java Class part-2

By // 2 comments:

In the previous post, talked about how many elements of a java class & local variable. Now we learn about Instance variable.



2. Instance Variable
  • Declaration:- The variables which are declared inside the class but outside of the method that are called instance variable.
  • Scope:- The variable can access inside the class. All methods, constructors and blocks of the class also able to access the variables.
  • Memory Allocation:- Memory is allocated in object creation time. Memory released when object is destroyed.
  • Stored Memory:- Heap is a memory  place where the objects, and its instance variable are stored.

3. Static Variable
  • Declaration:- The variables which are declared inside the class and outside of the method with static modifier are called static variable.
  • Memory Allocation:- When .class file is loaded the memory allocated.
  • Scope:- The static variable can access within the class. Access by class name.
  • Stored Area:- The variable stored in non-heap memory.
    To set up java environment visit here.
Next post is coming soon.......

Variables Of Java Class part-1

By // 5 comments:

In the first tutorial, I discussed that, a java class have five elements. Variable is one of these. Now we discuss about variable. There are three types of variables. They are..



  1. Local Variable
  • Declaration:- Declared inside the method or constructor or blocks.
  • Scope:- We can access the local variable only within the method, within the constructor or within the block. Out side is not possible.
  • Memory allocation:- When method or constructor of blocks start memory are allocated. When method invoked memory allocated and memory released when method completed.
  • Stored Area:- Local variable are stored in stack memory
        Next post is coming soon.......