✨
Java
  • 자바의 역사
  • Ch1
    • Before Start Java
      • History of Java
      • Feature of Java
      • API Documentation
      • Hello World!
      • eclipse shortcut
      • Eclipse IDE
      • GitHub to eclipse
  • Ch2
    • Variable
      • Variable
    • Variable Type
    • Character and String
    • Primitive type and range
    • printf and formatter
    • Scanner
    • Overflow of Int
    • Transition between different variable types
    • Object Array
  • CH3
    • Operator
  • CH4
    • 조건문과 반복문
    • if statement
    • switch
    • Math.random()
    • for statement
    • while statement
    • break, continue, named iterated statement
  • CH5
    • Array
    • 배열 활용
    • String Array
  • OOP
    • Intro
  • Class and Object
  • Make multiple Classes in one file
  • How to use Object
  • Object Array
  • Variable type according to declared location
  • Class Variable and Instance Variable
  • Method
  • Call Stack
  • Parameter
  • Static method(Class method) and Instance method
  • (Method)Overloading
  • Constructor
  • Constructor this()
  • Reference type variable "this"
  • Initialize variable
  • Inheritance
  • Composite
  • Single Inheritance, Object Class
  • (Method)Overriding
  • super, super()
  • package, class path
  • import, static import
  • modifier
  • access modifier
  • Encapsulation
  • Polymorphism
  • reference type transition
  • instanceof operator
  • Parameter polymorphism
  • Multiple object using one array
  • Abstract Class, Abstract Method
  • Creating Abstract Class
  • Interface
  • Interface Polymorphism
  • Interface Pros
  • Default method and static method
  • Inner Class
  • Anonymous Class
  • java.lang package and useful class
    • Object class
    • hashCode(), toString()
    • String class
    • StringBuffer class
    • StringBuilder class
    • Math class
    • Wrapper class
    • Number class
    • String to Number, String to Wrapper class
    • Auto-boxing and (auto)Unboxing
  • Collection Framework
    • Collections framework
    • List, Set, Map Interface
    • List의 removeAll() 과 clear() 비교
    • List Interface - ArrayList
    • How to view Java API source
    • List Interface - LinkedList
    • Stack and Queue
    • Iterator, ListIterator, Enumeration
    • Array
    • Comparator와 Comparable
    • Stack
    • String
    • String + char = String
    • String.toCharArray()
    • BufferedReader / BufferWriter
    • Scanner로 String 입력 - next( )와 nextLine( )
    • 공백없이 2차원배열 데이터 String으로 한번에 한줄씩 입력받기(문자/숫자)
    • 공백을 사이에 두고 빠른 2차원 배열 입출력
    • arr[index++]과 arr[index] index++의 차이
    • int와 long의 차이
    • Untitled
    • 타입 간의 변환
    • Array 와 ArrayList
    • valueOf()
    • Char
    • 변수, 객체 초기화(초기값 설정)
  • error troubleshooting
    • No enclosing instance of type
    • ASCII Code Table
    • java.lang.NumberFormatException
    • No enclosing instance..
  • reference
    • String을 생성하는 2가지 방법과 차이점
    • StackOverflowError(스택, 힙 메모리)
    • swtich-case 반복문
Powered by GitBook
On this page

Was this helpful?

  1. Ch2

Primitive type and range

(참고) 1byte = 8 bits

Type \ Size(Byte)

1

2

4

8

논리형

boolean

문자형

char

정수형

byte

short

int

long

실수형

float

double

(설명) int를 기준으로 작은 게 short, 큰 게 long이다.

double은 float보다 정밀도가 2배이기 때문에 double이라고 명명된다고 한다.

정수형은 int형이 default이고, 실수형은 double형이 default이다.

  1. 표현범위1

n 비트로 표현할 수 있는 값의 갯수 : 2^n 개. (부호 유무에 따라 값의 범위가 달라진다!⭐️)

각 데이터 타입만 알면 아래와 같은 공식으로 표현 범위를 알 수 있기 때문에 외우지 않아도 된다.

n 비트로 표현할 수 있는 부호없는 정수의 범위 : 양수 - 1 ~ 2^n, 0 - (2^n)-1

n 비트로 표현할 수 있는 부호있는 정수의 범위 : -2^(n-1) ~ 2(n-1)-1

=>양수와 음수 둘 다 표현한디. 표현할 수 있는 범위의 절반을 음수표현에 사용한다.

ex)부호있는 정수(2^n개): n = 8, -2^7 ~ 2^7-1.=> [-128, 127]

부호없는 정수(2^n개): n=8, [0, 255]

byte형 : 1byte크기 = 8bits = 2^8 = 256.

2. 표현범위2

자바에서는 정수형과 실수형에는 부호를 나타내는 비트(부호비트)가 있다.

ex) short : 2byte = 16bits. 1bit 부호비트 + 15 bits. 값의 표현 범위 : -2^15 ~ 2^15-1. (2^15 = 32768) => -32768 - 32767

char : 문자코드를 저장하기 때문에 부호 비트가 없다. char : 2byte = 16bits. 0 ~ (2^16) -1 = 0 - 65535

int : 4byte = 32bits, 1 부호비트 + 31bits. 값의 표현 범위 : -2^31 ~ 2^31-1(2^31 = 약 20억) => -20억 - 20억.

long : 8bytes = 64bits, 1 부호비트 + 63bits. 값의 표현 범위 : -2^63 ~ 2^64 - 1.(8*10^18 = 약 800경) => -800 부터 800경

3. 표현범위3

Type

저장 가능한 값의 범위(양수)

정밀도

크기

float

1.4E-45 ~ 3.4E38

음수 : -3.4x10^38 ~ -1.4^10^-45

7자리

4bytes(=32bits)

double

4.9E-324 ~ 1.8E308

음수 : -1.8E308 ~ -4.9E-324

15자리

8bytes(=64bits)

float의 표현할 수 없는 범위 : -1.4X10^-45 ~ 1.4X10^-45

S(1) + E(8) + M(23) : 부호 비트1 + 지수비트8 + 가수비트23

float의 정밀도 : 가수비트 23bit는 정규화를 통해 24bit까지 가능하다.->2^24->10^7 < 2^24 < 10^8 이기 때문에 정밀도가 7이 된다.

double : float의 정밀도의 2배.

S(1) + E(11) + M(52) : 부호 비트1 + 지수비트11 + 가수비트52

double의 정밀도 : 마찬가지로, 정규화를 통해 53bit까지 가능하다면 2^53=약 (2^24)^2 = (10^7)^2 < 2^48 < (10^8)2 => 10^14 < 2^48 < 10^16 이 되므로 정밀도가 15 정도 된다.

PreviousCharacter and StringNextprintf and formatter

Last updated 4 years ago

Was this helpful?