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

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