Upload
tak-lee
View
124
Download
4
Embed Size (px)
DESCRIPTION
Lab09. review for mid-term
Citation preview
Oct 13th Lab09.Stack, Heap, and Metaspace
http://www.slideshare.net/takyeon
public class Student {public String name;public int tokenLevel;private static int currentCount = 0;private static final int DEFAULT_TOKENS =
3;public Student() {
name = "unknown";tokenLevel = DEFAULT_TOKENS;currentCount++;
}}
Student s1 = new Student();s1.name = "Tak";
STACK HEAP META SPACE
DEFAULT_TOKENS
0
3
currentCount 1 Xs1
nametokenLevel 3
"unknown"
"Tak"
X
constructor
All static fields of a class live in Metaspace.
All local variables (both primitives and references) live on the stack. Non-primitive data objects are stored in the heap, and referenced by variables on the stack.
All non-primitive objects live on the heap.Primitive instance variables of those objects are stored inside the object. Non-primitive variables are stored outside of the object, and referenced by the instance variable.
Size? 5
* *** ***** ****************
Scanner sc = new Scanner(System.in);int size = sc.nextInt();
for(int row=0; row<size; row++) {for(int col=0;col<4-row;col++) {
System.out.print(" ");}for(int col=0;col<row*2+1;col++) {
System.out.print("*");}System.out.println();
}sc.close();
row col : 1st spaces before *
col : 2nd
number of *
0 4 11 3 32 2 53 1 74 0 9
int x,y;x=2; y=5;System.out.println(x++ * y++);System.out.println(++x * ++y);System.out.println(++x * y++);System.out.println(x++ * ++y);
System.out.println("1 + 2 = " + 1 + 2);System.out.println("1 + 2 = " + (1 + 2));
1 + 2 = 121 + 2 = 3
year % 4 == 0 && year % 100 != 0 || year % 400 == 0
((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)
Any question?