기본형 변수와 참조형 변수 정리
결론부터 말하자면
기본형 타입: 8가지(boolean, byte, shrot, int, long, char, float, double), 기본값 O, Null 없음. Stack에 저장 참조형 타입: 기본형 타입 외의 나머지 전부. 기본값 없음. Null 존재, Heap 메모리에 저장.
In my conclousion
Primitive Type: 8 things(boolean, byte, short, int, long, char, float, double), default value O, Not null, located at Stack memory.
Reference Type: Every types except primitive type. Not default value, Null Exist, located at Heap memory.
1.Primitive Type
Category | Type | Size | Default Value | Range | Note. |
---|---|---|---|---|---|
Booleans | boolean | 1 bit | false | true or false |
- 언제나 값을 가지고 있으며, 기본값을 가지고 있다. >> 기본값은 클래스 멤버(속성)으로 선언될때 적용되며, 매서드 등의 로컬 변수로 선언시에는 별도로 값 초기화가 필요. (They always has always values. And they has default values >> Default values are setted when they are declared as class member(attributes). Local variables don't have it, so must initialize them) - Null 값이 존재하지 않는다. (Can't be null) - Stack 메모리에 저장된다. (Located at Stack memory) - 실제 값을 저장. (Saved real values, not reference address) |
Integer | byte | 1 byte | 0 | from -128 to 127 | |
short | 2 byte | 0 | from -32,768 to 32,767 | ||
int | 4 byte | 0 | from -2,147,483,648 to 2,147,483,647 | ||
long | 8 byte | 0L | from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | ||
Floating Point | Float | 4 byte | 0.0F | Sufficient for storing 6 to 7 decimal digits | |
Double | 8 byte | 0.0 | Sufficient for storing 15 decimal digits | ||
Characters | char | 2 byte | '\u0000' | 0 ~ 65,535 |
2.Reference Type
*참조(References)
https://www.w3schools.com/java/java_data_types.asp#:~:text=Primitive%20number%20types%20are%20divided,%2C%20short%20%2C%20int%20and%20long%20. https://gbsb.tistory.com/6 https://growinglastcanyon.tistory.com/6