Stack Heap Global Diagram
Represent variables as boxes, organized in different memory areas

This notional machine represents the state of a program by showing three separate parts of memory: the stack with its stack frames and their local variables, the heap with heap objects and their instance variables, and the global area with static variables.

Every variable is shown as a rectangle containing its current value. Variables are annotated with their name. In statically typed languages, variables are also annotated with their type.

62 Misconceptions Expressible in this Notional Machine

A notional machine focuses on a subset of the syntax and semantics of a programming language. The following misconceptions are related to the language features expressible in this notional machine.

Misconception
AddMemberAtRuntime
Set of class members can change at runtime
Misconception
ArrayHasLengthMethod
To get the length of an array, one needs to call its length method
Misconception
ArrayListIsArray
ArrayLists are arrays
Misconception
ArrayRankIsLength
Array rank and array length are the same thing
Misconception
ArraysGrow
Arrays can grow dynamically
Misconception
AssignCompares
= compares two values
Misconception
AssignmentCopiesObject
Assignment copies the object
Misconception
BoxedNull
Passing null to a wrapper class constructor creates an object representing the absence of a value
Misconception
CallWithoutFrame
A method invocation does not necessarily allocate a stack frame
Misconception
CallerFrameContainsCalleeFormal
Stack frame of caller includes variables for callee's formal parameters
Misconception
ConstructorAllocates
The constructor allocates the object
Misconception
ConstructorParameterIsField
Formal constructor parameters are equivalent to instance variables
Misconception
EqualityOperatorComparesListIdentities
(list a) = (list b) compares the identities of list a and list b
Misconception
EqualityOperatorComparesObjectsValues
o==p compares the objects referred to by variables o and p
Misconception
EqualsComparesReferences
o.equals(p) compares the references stored in the variables o and p
Misconception
ExpressionAssigns
An expression that reads a variable also updates its value after the evaluation
Misconception
FinalReferenceImpliesImmutability
An object referred to by a final variable is an immutable object
Misconception
ForEachVariableIsElement
One can assign to the variable of an enhanced for statement to store a value in the corresponding array or collection element
Misconception
FrameIsClassInstance
A stack frame is the same as an instance of a class
Misconception
ImmutableRequiresFinalParameters
Immutable classes need final constructor/method parameters
Misconception
InitCreates
__init__ must create a new object
Misconception
LocalVariablesAutoInitialized
Local variables are automatically initialized
Misconception
MethodAsField
Each object contains its own special fields for all of its methods
Misconception
MultiReferenceVariable
A reference variable can point to multiple objects
Misconception
MultiValueVariable
A variable can contain more than one value
Misconception
MultidimensionalArray
A multi-dimensional array is one thing
Misconception
MustInitializeFieldInConstructor
Constructors must assign values to all fields
Misconception
NoFieldInheritance
An object contains only the fields declared in its class
Misconception
NoFieldlessObjects
Objects without instance variables can't exist
Misconception
NoJaggedArrays
Multi-dimensional arrays have a rectangular shape
Misconception
NoLocalVariables
There are no local variables
Misconception
NullIsObject
null is an object
Misconception
NullPointerExceptionCompileTime
NullPointerExceptions are detected at compile time
Misconception
ObjectLabeledWithConstructorSignature
In stack and heap diagrams, an object on the heap is labeled like a stack frame of a constructor call
Misconception
ObjectLabeledWithVariableName
In stack and heap diagrams, an object on the heap is labeled with the name of the variable that refers to it
Misconception
ObjectsMustBeNamed
A variable is needed to instantiate an object
Misconception
OnlyInnermostArrayElements
Only the elements of the innermost array of a multi-dimensional array are accessible
Misconception
PrimitiveIsObject
Primitive values are heap objects
Misconception
PrimitiveVariablesDynamicallyTyped
The type of a primitive variable depends on its value
Misconception
PrivateFieldsImplyImmutability
A class where all fields are private is immutable
Misconception
PrivateFromOtherInstance
An object cannot access private members of other objects of the same class
Misconception
PrivateFromStatic
Static methods cannot access private members of instances of same class
Misconception
PrivateMeansFinal
A private field cannot be changed
Misconception
RecursiveActivationsShareFrame
Recursive calls of a method share a stack frame
Misconception
ReferenceIntoStack
References can point into the stack
Misconception
ReferenceLabeledWithDynamicType
In stack and heap diagrams, reference variables are labeled with the types of the objects they refer to
Misconception
ReferenceToVariable
References can point to variables
Misconception
StackTraceIsCallHistory
A stack trace is the sequence of previously called methods
Misconception
StaticFrameInGlobals
Stack frame of static method calls lives in the global memory area
Misconception
StringLengthField
One can know the length of a String object by accessing its length field
Misconception
StringLiteralNoObject
One needs to call the String constructor to get a String object from a literal
Misconception
SubtypeCompatibleWithSupertype
A variable of a subtype can reference an object of a supertype
Misconception
SuperclassObjectAllocated
When instantiating an object of a subclass, an object of a superclass is also allocated
Misconception
SupertypeIncompatibleWithSubtype
A variable of a supertype cannot reference an object of a subtype
Misconception
ThisAsField
this is a special field in the object
Misconception
ThisAssignable
One can assign to this
Misconception
ThisCanBeNull
this can be null
Misconception
ThisExistsInStaticMethod
this is a local variable, also in static methods
Misconception
ThisInConstructorIsNull
In a constructor, this is null
Misconception
UntypedVariables
Variable declarations don't need a type
Misconception
VariablesHoldExpressions
= stores an expression in a variable
Misconception
VariablesHoldObjects
A variable of a reference type contains a whole object

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.