• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JVM memory

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't double post.
 
Rajan Venkat
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic