[태그:] <span>byte</span>

Java 언어에서 기본 형식의 변수는 스택 메모리에 inline으로 잡힙니다. 반면 클래스 형식의 개체는 힙 메모리에 잡힙니다. Java 언어에서는 기본 형식의 변수의 값을 래핑한 클래스를 제공합니다.

Java 언어에서 제공하는 래퍼 클래스는 기본 형식의 값을 인자로 개체를 생성하도록 생성자를 제공하고 있습니다. 그리고 기본 형식의 값을 문자열 형태의 인자로 전달하여 개체를 생성하는 생성자도 제공합니다.

Bloolean(boolean value), Boolean(String str)
Byte(byte value), Byte(String str)
Character(char value)
Short(short value), Short(String str)
Integer(int value), Integer(String str)
Long(long value), Long(String str)
Float(float value), Float(String str)
Double(double value), Double(String str)

다음은 기본 형식의 래퍼 클래스 개체를 생성하여 출력한 예제입니다.

//기본 형식의 래퍼 클래스 개체를 생성하여 출력한 예
public class Program {
	public static void main(String[] args){
		Boolean b1 = new Boolean(true);
		System.out.println(b1);
		Boolean b2 = new Boolean("false");
		System.out.println(b2);
		
		byte ob1 = (byte)3;
		Byte by1 = new Byte(ob1);
		System.out.println(by1);				
		Byte by2 = new Byte("123");
		System.out.println(by2);
		
		Character c1 = new Character('a');
		System.out.println(c1);
		
		short os = 10200;
		Short s1 = new Short(os);
		System.out.println(s1);
		Short s2 = new Short("32000");
		System.out.println(s2);
		
		Integer i1 = new Integer(2000000);
		System.out.println(i1);
		Integer i2 = new Integer("30000000");
		System.out.println(i2);
		
		long ol = 35l;
		Long l1 = new Long(35l);
		System.out.println(l1);
		Long l2 = new Long("38");
		System.out.println(l2);
		 
		Float f1 = new Float(3.14f);
		System.out.println(f1);
		Float f2 = new Float("2.10");
		System.out.println(f2);
		
		Double d1 = new Double(4.56);
		System.out.println(d1);
		Double d2 = new Double("1.23456");
		System.out.println(d2);
	}
}

실행 결과

true
false
3
123
a
10200
32000
2000000
30000000
35
38
3.14
2.1
4.56
1.23456

Java 입문