정의

프리미티브 타입을 객체로 표현하는데 사용되는 클래스들의 통칭이다.
프리미티브 타입의 데이터를 감싸는 역할을 하는 래퍼 클래스
e.g., Byte Object -> byte type data

래퍼클래스는 인스턴스를 생성하면서 힙 메모리에 값이 저장되고 객체 변수는 참조 값을 가지므로 비교연산이 불가능하다. equals 메소드를 사용하거나, UnBoxing을 통하여 비교연산을 한다.

JDK 1.5 after 자바 컴파일러가 자동으로 처리함. (Auto Boxing Auto UnBoxing)

name primitive type
Byte byte
Short short
Integer int
Long long
Character char
Float float
Double double
Boolean boolean

박싱(Boxing)과 언박싱(UnBoxing)

1
2
3
4
5
6
7
8
9
10
11
12
13
public static void main(String[] args){
Byte b = new Byte(1);
Short s = new Short(123);
Integer integer = new Integer(12345);
Long l = new Long(123456789L);
Float f = new Float(1.5F);
Double d = new Double(1.);
Character ct = new Character('꿈');
Boolean bl = new Boolean(true);

Byte b = Byte.valueOf(1);
Integer ii = Integer.valueOf(1);
}
1
2
3
4
5
public static void main(String[] args){
int i = 10;
Integer wrapperClazz = new Integer(i);
System.out.print(wrapperClazz.intValue());
}

Method and Constant

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public static void main(String[] args){
String str = Integer.toBinaryString(9); // 숫자9의 이진문자열을 리턴한다 2^3 + 1
String str = Long.toBinaryString(11000L);

int i = Float.floatToRawInBits(1.5F);
int i = Long.longToRawLongBits(1.5);

byte b = Byte.parseByte("1");
short s = Short.parseShort("1");
int i = Integer.parseInt("1");
long l = Long.parseLong("1");
float f = Float.parseFloat("1.5");
double d = Double.parseDouble("1.5");
boolean b = Boolean.parseBoolean("true");
}