자료형
자료형
Java 자료형 정리
Primitive Type(기본형 타입) 과 Reference Type(참조형 타입) 으로 나눌 수 있다.
Primitive Type (기본형 타입)
byteshortintlongfloatdoublecharboolean
Primitive Type의 특징
null값을 가질 수 없다.변수에 실제 데이터 값이 직접 저장
스택(Stack) 메모리 저장
Reference Type (참조형 타입)
클래스 타입 (class type)
인터페이스 타입 (interface type)
배열 타입 (array type)
열거 타입 (enum type)
Reference Type의 특징
변수에 객체의 주소(참조값)를 저장
null 사용 가능
힙(Heap) 메모리에 저장
String 타입
String은 "Hello world" 와 같이 리터럴 표현이 가능하지만 Primitive Type은 아니다.
String은 Reference Type에 속하지만 기본형처럼 사용 가능하도록 지원한다.
리터럴(Literal)
리터럴이란?
리터럴이란 변하지 않는 고정된 값 자체를 의미한다.
객체를 생성하지 않고 이미 정해진 값을 그대로 변수에 대입하는 방식이다.
1
2
3
int num = 10;
String str = "Dal";
boolean flag = false;
*Primitive Type은 new 키워드로 값을 생성하는 것이 아니라 리터럴 방식으로 값을 설정한다.
Wrapper Class
Primitive Type을 객체로 감싸서(Wrap) 사용할 수 있도록 제공되는 클래스
Primitive Type ↔ Wrapper Class
| Primitive Type | Wrapper Class |
|---|---|
| boolean | Boolean |
| char | Character |
| int | Integer |
| long | Long |
| float | Float |
| double | Double |
This post is licensed under CC BY 4.0 by the author.