0% found this document useful (0 votes)
31 views

Core - Drawing Memory Models With Primitive Data

This document discusses memory models for reasoning about primitive data types in Java code. It demonstrates drawing a memory model to trace the state of variables as a code snippet executes. The model shows variable declarations as boxes labeled with the variable name. Assignments put the right hand side value into the box of the left hand side variable. By updating the model after each line of code, it shows var1 is assigned 52 initially, var2 is then assigned the current value of var1 (52), and finally var1 is assigned 127 while var2 retains its initial value of 52.

Uploaded by

Radu Iordache
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Core - Drawing Memory Models With Primitive Data

This document discusses memory models for reasoning about primitive data types in Java code. It demonstrates drawing a memory model to trace the state of variables as a code snippet executes. The model shows variable declarations as boxes labeled with the variable name. Assignments put the right hand side value into the box of the left hand side variable. By updating the model after each line of code, it shows var1 is assigned 52 initially, var2 is then assigned the current value of var1 (52), and finally var1 is assigned 127 while var2 retains its initial value of 52.

Uploaded by

Radu Iordache
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Memory Models

Part 1: Primitive data


By the end of this video you will be able to…

▪ Draw memory models for reasoning about variable values for


primitive type data
▪ Update memory models to trace the state of the variables in
Java code
Code tracing warm up
int var1;
var1 = 52;
int var2;
var2 = var1;
var1 = 127;
System.out.println("var1 is " + var1 +
", var2 is " + var2);
int var1; Variable declaration: draw a box and label it
var1 = 52; with the variable's name
int var2;
var2 = var1;
var1 = 127;
System.out.println("var1 is " + var1 +
", var2 is " + var2);
int var1; Variable declaration: draw a box and label it
var1 = 52; with the variable's name
int var2;
var2 = var1;
var1 = 127;
System.out.println("var1 is " + var1 +
", var2 is " + var2);

var1
int var1; Variable assignment: put the value of the
var1 = 52; right hand side (RHS) into the box for the
int var2; variable on the left hand side (LHS)
var2 = var1;
var1 = 127;
System.out.println("var1 is " + var1 +
", var2 is " + var2);

var1
int var1; Variable assignment: put the value of the
var1 = 52; right hand side (RHS) into the box for the
int var2; variable on the left hand side (LHS)
var2 = var1;
var1 = 127;
System.out.println("var1 is " + var1 +
", var2 is " + var2);

var1 52
int var1;
var1 = 52;
Variable declaration: draw a box and label it
int var2;
with the variable's name
var2 = var1;
var1 = 127;
System.out.println("var1 is " + var1 +
", var2 is " + var2);

var1 52
int var1;
var1 = 52;
Variable declaration: draw a box and label it
int var2;
with the variable's name
var2 = var1;
var1 = 127;
System.out.println("var1 is " + var1 +
", var2 is " + var2);

var1 52 var2
int var1; Variable assignment: put the value of the
var1 = 52; right hand side (RHS) into the box for the
int var2; variable on the left hand side (LHS)
var2 = var1;
var1 = 127;
System.out.println("var1 is " + var1 +
", var2 is " + var2);

var1 52 var2
int var1; Variable assignment: put the value of the
var1 = 52; right hand side (RHS) into the box for the
int var2; variable on the left hand side (LHS)
var2 = var1;
var1 = 127;
System.out.println("var1 is " + var1 +
", var2 is " + var2);

var1 52 var2
int var1; Variable assignment: put the value of the
var1 = 52; right hand side (RHS) into the box for the
int var2; variable on the left hand side (LHS)
var2 = var1;
var1 = 127;
System.out.println("var1 is " + var1 +
", var2 is " + var2);

52
var1 127 var2 52
int var1;
var1 = 52;
int var2; var1 is 127, var2 is 52
var2 = var1;
var1 = 127;
System.out.println("var1 is " + var1 +
", var2 is " + var2);

var1 127 var2 52

You might also like