• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

differenciate 'heap' and 'stack'

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
1)what is difference between the two ie heap and stack in java terminology
2)Can someone summarize as different collections (like treest,linkedlist etc )are used/useful for under what circumstances
thanks,
Rajiv
[ August 25, 2003: Message edited by: Rajiv Goyal ]
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The heap is the dynamic chunk of memory where the objects are created. Java programmers have no pointers to acces the memory directly. The garbage collector frees memory automatically for unreferenced objects in the heap.
A Java thread is given a program counter and a Java stack. A thread cannot access the stack of another thread. When the thread calls a method a stack frame is created for the method and pushed in the thread's stack. The frame becames the current frame. Upon method completion, either normally, or abruptaly --throwing an exception-- the current stack frame is popped off the stack and discarded. The previous stack frame becomes the current one.
A frame stack has three sections:
A) local variables. For storing the local variables and parametes
B) operand stack. For storing the intermidiate result of calculations. There are no registers in the JVM!
c) frame data. For accessing the constant pool of the class where the method was declared, normal return of the method etc.
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The constant pool sounds like a set of virtual registers.
Does Java have a limit to the variable stack size? [When writing for an embedded system, whether using C or assembler, the programmer usually has to set the stack size (unless the stack is a reserved part of RAM, like in the old 6502 processor).] Can the programmer set the stack size, or does it just automatically grow as long as assignable memory is available?
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Jeff.
from API:


StackOverflowError
extends VirtualMachineError
Thrown when a stack overflow occurs because an application recurses too deeply.


Though I have never use it, from java launcher documentation:


-Xssn
Set thread stack size


The compiler is able to compute the size of the local variable and operand stack sections for every method. The size of frame data is fixed. Still, if too many invocations occurr we will see a StackOverflowError
[ August 26, 2003: Message edited by: Jose Botella ]
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think of the contant pools as the firmware of the JVM: though the JVM resolves the entries in the constant pool translating symbolic references to direct ones, a Java program only reads from such entries, it will not write to them as it would do with registers.
In fact the JVM arquitecture is stack oriented, it uses the operand stack for storing intermidiate results.
 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rajiv Goyal:
hi,
1)what is difference between the two ie heap and stack in java terminology
2)Can someone summarize as different collections (like treest,linkedlist etc )are used/useful for under what circumstances
thanks,
Rajiv
[ August 25, 2003: Message edited by: Rajiv Goyal ]


set: stores unique elements but not ordered.
linkedhashset: they r ordered and unique.It doesn't delete least recently used element when new is added.
Implementation of set is hashset.
list: elements are in ordered but not unique. They can contain duplicates.
Implementation of list are Arraylist,linkedlist and vector.
vector is thread safe but arraylist is not.
when searching some element arraylist and vector r giving good performance. but linkedlist not since we have to traverse each element.
But at the time of insertion and deletion linked list is preferred.
map: contains the elements in key value pair.
Implementations are hashmap and hashtable.
hashmap is not thread safe and can contain null elements.
hashtable is thread safe and can not contain null elements.
linkedhashmap : It deletes least recently used element when new is added.
and can contain nulls. elements i.e.keys are in order.
 
Rajiv Goyal
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all; that answer my quesion,
Rajiv
[ August 26, 2003: Message edited by: Rajiv Goyal ]
 
Yes, my master! Here is the tiny ad you asked for:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic