SCJP,SCWCD,CCNA,CCAI,MCP,MCSA,MCSE<br />working on CCNP+SCBCD
scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
SCJP2. Please Indent your code using UBB Code
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Ian
originally written by Peter van der Linden in Just Java 2
The stack is a runtime data structure for keeping track of memory to support methods and recursive method invocation.
When you call a method, some housekeeping data, known as an activation record or stack frame, is pushed onto the stack. The activation record contains the return address, the arguments passed to the method, the space for local variables and so on. When you return from a method, the record is popped from the stack. The next method call will push another record into the same space.
If you have any pointers back into the old activation record on the stack, memory can be corrupted, as the pointer references an area that the next function call will reuse for a different purpost. This is a common problem in C/C++, and can be hard to debug. In other words, the lifetime of stack-based storage is tied to the scope in which it was allocated, and although some languages let you get this wrong, Java doesn't!
The heap is another runtime data structure used to support your program. It is a large storage area that is managed dynamically. All objects in Java are allocated on the heap; no objects are ever allocated on the stack.
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
SCJP2. Please Indent your code using UBB Code
SCJP2. Please Indent your code using UBB Code
SCJP,SCWCD,CCNA,CCAI,MCP,MCSA,MCSE<br />working on CCNP+SCBCD
If the same string is there already in pool of strings then the old string will be replaced with the new one.
String s1 = new String("Testing String");
constructing the String by calling new then the String object will be created at runtime and will not there in pool of strings
For String s2 = new String("String");
s2 (reference) --> String object, which in
turn has a reference to
the same "String" constant
that s1 is referencing.
SCJP2. Please Indent your code using UBB Code
SCJP,SCWCD,CCNA,CCAI,MCP,MCSA,MCSE<br />working on CCNP+SCBCD