JavaRanch Home    
 
This page:         last edited 16 February 2014         What's Changed?         Edit

Stack Or Heap   

(Level: beginner)

This page is (hopefully) an answer to the numerous questions we receive along the lines of "where does Java hold my variables?".

The simple answer is: It doesn't matter.

Unless you're a computer engineer, or a system architect, or a writer of Java compilers or JVMs, Java puts "things" where it thinks best - and whether that's the Stack or the Heap makes absolutely NO difference to you as a programmer.

Furthermore, Java is a memory-managed language, so the whole philosophy is that you shouldn't know - and you certainly shouldn't rely on - where it puts things, because it might change in a future release.

If you're doing a course in Computer Science theory, and you want to understand how Stack frames or heap memory works, by all means look it up - Java's definitions are not very different to other languages that use the terms (and many do).

But if you're simply learning Java as a language for programming, it's a distraction.

Create objects; use them; let the garbage-collector clean them up - it really is as simple as that.

Anything else is internal procedural "fluff", and will NOT help you become a better Java programmer.

.

Hope it helps.



CategoryWinston

JavaRanchContact us — Copyright © 1998-2014 Paul Wheaton