데이터의 크기
제일 작은 단위 : 비트(bit)
8 bit = 1 byte
1024 byte = 1 kilobyte
megabyte
gigabyte
terabyte
petabyte
exabyte
zettabyte
정수형 데이터
byte (1byte) : -128 ~ 127
short (2byte) : -32,768 ~ 32,767
int (4byte) : -2,147,483,648 ~ 2,147,483,647
long (8byte) :
long a = 21000000;
long b = 1;
a와 b는 8byte라는 같은 크기 메모리 사용
실수형 데이터
float (4byte)
double (8byte)
문자
char (2byte) : 모든 유니코드 문자
"AB" => 2+2= 4 byte
상수(constant, 변하지 않는 값)형 데이터 타입
package org.opentutorials.javatutorials.constant;
public class constantdemo {
public static void main(String[] args) {
double a = 2.2;
float b = 2.2F; => F : float 타입임을 명시적으로 지정
long c = 211111010L;
byte d = 100;
short e = 200; => 따로 byte, short로 명시하지 않아 숫자 부분은 int지만, 자바가 메모리 크기 범위 안에서는 허용해주기 때문에 오류 발생하지 않음.
}
}
'Programming > 자바' 카테고리의 다른 글
생활코딩 자바 - 연산자 (0) | 2022.03.12 |
---|---|
생활코딩 자바 - 형변환 (0) | 2022.03.04 |
생활코딩 자바 - 주석, 세미콜론 (0) | 2022.03.03 |
생활코딩 자바 - 변수 (0) | 2022.03.01 |
생활코딩 자바 - 숫자와 문자열 (0) | 2022.02.28 |