Each time an object is created in Java it goes into the area of memory known as heap. The primitive variables like
int and double are allocated in the stack, if they are local method variables and in the heap if they are member
variables (i.e. fields of a class). In Java methods local variables are pushed into stack when a method is invoked
and stack pointer is decremented when a method call is completed. In a multi-threaded application each thread
will have its own stack but will share the same heap. This is why care should be taken in your code to avoid any
concurrent access issues in the heap space. The stack is threadsafe (each thread will have its own stack) but the
heap is not threadsafe unless guarded with synchronisation through your code.
A method in stack is reentrant allowing multiple concurrent invocations that do not interfere with each other. A
function is recursive if it calls itself. Given enough stack space, recursive method calls are perfectly valid in Java
though it is tough to debug. Recursive functions are useful in removing iterations from many sorts of algorithms. All
recursive functions are re-entrant but not all re-entrant functions are recursive. Idempotent methods are methods,
which are written in such a way that repeated calls to the same method with the same arguments yield same
results. For example clustered EJBs, which are written with idempotent methods, can automatically recover from a
server failure as long as it can reach another server.
World of tricky Core Java Q and A Covering Object Oriented Analysis and Design, JVM Internals,Java Language Fundamentals,Datatypes,Keywords,Operators and Assignments,Identifies,Declarations and Modifiers, Conversion,Casting and Promotion, Flow control,Assertions, Exception Handling and Garbage Collection,Objects and Classes), Basic Packages and their classes,JDBC,JFC Swing,Java Server Pages (JSP), Servlets,EJB,JMS,JNDI etc and Open source technologies like Struts,Hibernate,Spring etc
Search This Blog
Saturday, February 17, 2007
How does Java allocate stack and heap memory? Explain re-entrant, recursive and idempotent
Subscribe to:
Post Comments (Atom)
18 comments:
Hi The image is not readable.
i agree the image is not readable, i think it wud be much helpful if it was.
Javapeople
I tried increasing the size of image. but It doesn't fit on my blog
This is very nice information i have found here. Thanks.
copied from a book, shame!
Picture is not clear. Can you please send this heap pic? Thanks.
My id is rnandyala@gmail.com
hi,
can you post related articles and this image to suree2k2@yahoo.com id.
Regards,
Suree.
Hi, nice article
Picture is not clear. Can you please send this heap pic? Thanks.
My id is sandeepgarg.dot@gmail.com
Hi,
Nice information..... can you plz forward the related info to rachumallu.sri@gmail.com
Excelent article. Thanks.
Picture problem
thanks..awesome and simple explanation..cleared most of my doubts...
Short and sweet. I liked the explanations. Good Job....does'nt matter if it has been copied from a book...what matters is that I can find it with a few keystrokes and google :)
Information provided here helped me a lot .....
Thank you guys..
Got something new to know....Thank you guys..
pls send me name of the book and also send me the image of the above photo
my id -jasmeet0013@gmail.com
Thanks Nice ..
Siva here:
Expected Clear picture in this site:
http://dnhome.wordpress.com/2012/06/28/how-does-java-allocate-stack-and-heap-memory/
Post a Comment