Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JVM memory  RSS feed

 
Anil Kumardvg
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

1) Is there memory required for methods, and when v create object, each object is going to have there own methods or for one class there will be one method all object will refer that.

thanks
 
krishna bulusu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Methods are the engines to process a data.
they are simply some lines of code in your java class to modify the variables.
the state of an object is its instance variables.
so, when you create instance variables, then some memory will be allocated.
 
Rajan Venkat
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anil,

Methods and local variables are stored in stack,
Object and instance variables are stored in heap.

The Main method is a method which will start the java application and it will be invoked by JVM.Once the program starts with the main method,the main method will be pushed in to the stack memory ,whatever method you are calling from main method will be pushed in to the stack at the top of the main. When the mothod copletes it will be popped up from the stack and it goes till the main get popped off.

please let me know if you have any doubts on that .
 
Anil Kumardvg
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Rajan for your reply,I have still doubt please don't mind.
for example
class Emp{
int empId;
void getEmp(){
//body
}
}
if we create 10 object for above class then each object have different value of instance variable of empId,what abt all object have same getEmp() method or each object have there own method, if all objects refers same method, then how its going to proceed with each instance variable.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't double post.
 
Rajan Venkat
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Emp{
int empId;
void getEmp(){
//body
}
}
if we create 10 object for above class then each object have different value of instance variable of empId,what abt all object have same getEmp() method or each object have there own method, if all objects refers same method, then how its going to proceed with each instance variable.


As you said each object will have its own instance variable inside object in heap, when it comes to methods which will store in the stack when you call a method from one object which will get expires once method completes same way happens for all the objects. Hope this clears you.

Please let me know if you have any doubts on this.
 
Anil Kumardvg
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!