Software Project Lecture 3
Software Project Lecture 3
Software Project Lecture 3
Joon-Woo Lee
• Java's data types are largely divided into primitive types and
reference types.
• The reference type is a type that refers to the address of an object,
and includes
• array type
• enum type
• class
• interface type.
2
Software Project Spring 2023
Integer
Array Type
byte char short
Enum Type
int long
Class
Floating-point
Interface
float double
Boolean
boolean
3
Software Project Spring 2023
• The difference between the default type and the reference type is the
stored value in the variable.
• Default types store the values themselves, but reference types store
the memory address at which the object was created.
• Variables is allocated in the stack.
• The object itself of the reference type is allocated in the heap.
4
Software Project Spring 2023
Array object
5
Software Project Spring 2023
variable-1 variable-1
...
Heap
...
...
“Java Programming” “Apple”
Frame-1 Frame-1
1 2 3 variable-n variable-n
Object-1
variable-1 variable-1
Object-2
6
Software Project Spring 2023
• Method area
• The area where the contents of the byte code file are stored
• Heap area
• The area where the object is created
• Stack area
• The area where the frames and variables that are generated each time the
method is called are stored
7
Software Project Spring 2023
4 6 2
Array object
8
Software Project Spring 2023
System.out.println(arr1 == arr2);
System.out.println(arr2 == arr3);
}
}
9
Software Project Spring 2023
4 6 2
Array object
10
Software Project Spring 2023
refVar1 null
Garbage object
12
Software Project Spring 2023
String Type
• String is generated as a String object in Java.
• Java is designed to share a String object if the string literal is the same.
• String refVar2 = “Python”; String refVar3 = “Python” (left figure)
• If you create an object with new operator, which is the operator that creates a
new object, you can create an object with the same string but different object.
• String refVar2 = new String(“Python”);
• String refVar3 = new String(“Python”); (right figure)
Heap Heap
Stack address: 100 String object Stack address: 100 String object
“Java Programming”
refVar1 100 “Java Programming” refVar1 100
address: 200
refVar2 200 refVar2 200
address: 200 “Python”
refVar3 200 refVar3 300
address: 300
“Python”
“Python”
13
Software Project Spring 2023
Array Type
• Array is generated as an array in Java.
• The array itself is generated in the heap area.
• The variable includes the address of the array.
• The array only manages values of the same type.
• The length of the array cannot be increased or decreased.
Stack
address: 200
refVar2 200
0 1 2 3 4 5 6
Array object
14