+4  A: 

Since you tagged your question Java, I'll assume you meant in Java. Straight from the horse's mouth:

The Java virtual machine has a heap that is shared among all Java virtual machine threads. The heap is the runtime data area from which memory for all class instances and arrays is allocated.

JVM Spec

Here is a link to a previous SO question that goes into this in serious detail (and is a language-agnostic discussion on the topic).

Here's a link to an article from C# corner detailing the issue in C#.

Kyle Walsh
is it same in .net?
uzay95
@uzay95 In a word, no. This quote from the C# corner link should help you: "The Stack is more or less responsible for keeping track of what's executing in our code (or what's been "called"). The Heap is more or less responsible for keeping track of our objects (our data, well... most of it - we'll get to that later.)."
Kyle Walsh
from 1.6 onwards this is no longer true in all cases from an *implementation* perspective. It never was totally true for certain objects like string literals.
ShuggyCoUk
+1  A: 

Order and Customer are on the heap. Though Customer may be a struct, it is a composed member of a reference type (e.g., a class).

All strings are reference types and are created on the heap.

I'm not sure about the Ship class because I don't have its declaration (i.e., I don't know if it is a struct or a class).

The int iTotal variable is created on the stack.

This is true for C#. Java may have different rules at play.

David Andres
David, what do you mean by "Customer may be a struct, it is a composed member of a reference type" ?
Preets
Customer may have been declared as struct Customer {}. struct makes Customer a Value Type and will under normal circumstances be placed on the stack. However, because Customer is a member of class Order, which is a reference type that is placed on the heap, Customer is placed on the heap as well.
David Andres
Ah ! Thanks for the explanation !
Preets
I always miss a bit of information in all this type of questions in C#/Java. While the real objects (instances) are in the heap, the references that point to them (that take real memory) are stack allocated: sProductName is a stack allocated reference to a heap allocated string... Then again, the language tries to hide the fact that the reference and the object is not the same... unluckily.
David Rodríguez - dribeas
@dribeas...and then there's boxing.
David Andres