Yeon's Frame
  • Intro
  • Project
    • 미소웨더
      • 기획 - 아이디어 및 유스케이스 정리
      • DB 설계 - JPA 활용 중심
  • Study
    • Spring
      • Spring Feature
      • N+1
      • OSIV
      • @Valid
      • Spring Boot Feature
      • Spring 5 Feature
      • JPA vs MyBatis
      • Filter, Interceptor
      • Persistence Context
      • @Transactional
      • @Controlleradvice, @ExceptionHandler
      • Spring Security
      • Dispatcher Servlet
      • @EnableWebMvc
      • Stereo Type
      • AOP
      • JPA Repository
    • Infrastructure
      • Git
      • DNS
      • JWT
      • DevOps
      • Docker
      • Jenkins
      • Cloud Computing
      • MSA
    • Clean Code
      • 깨끗한 코드
      • 의미있는 이름
      • 함수
      • 주석
      • 형식 맞추기
      • 객체와 자료구조
      • 오류 처리
      • 경계
      • 단위테스트
      • 클래스
      • 시스템
  • Basic
    • Java
      • OOP
      • OOL Features
      • Class & Objects
      • Instance & Heap Memory
      • Constructor
      • Reference Type Uses
      • Access Modifier & Hiding
      • This
      • Collaboration
      • Static
      • Inheritance
      • Polimorphism & Casting
      • Abstract Class
      • Interface
      • Object Class
    • Java Coding
      • JVM
      • String, StringBuffer, StringBuilder
      • SOF
      • Blockcing/NonBlocking
      • Enum
      • Static
      • Thread
      • hashCode() | equals()
      • JDK8
      • Stream
      • Optional
      • Lambda & Closure
      • Exception
      • Garbage Collecter
      • Collection
      • Call by Value & Call by Reference
      • Generic
    • Java_Advance
      • Inner Class
      • Lambda Expression
      • Functional Interface
      • OOP vs Lambda Expression
      • Stream
      • Reduce()
      • Exception Handling
      • Custom Exception
      • Error Log
      • IO Stream
      • IO Stream - Serialization
      • File Class
      • Decorator Pattern
      • Thread
    • Data Structure
      • Intro
      • Generic(1)
      • Generic(2) T extends
      • Generic(3) Method
      • Collection Frameworks
      • List
      • Iterator
      • Set
      • Comparable & Comparator
      • Map
  • Practice
    • Algorithm
      • Strategy
        • Primitive, Reference, Generic
        • Number Data Types
        • For-Each
        • Array, Queue, ArrayDeque
        • Array vs ArrayList
Powered by GitBook
On this page
  • int vs long
  • float vs double
  • Overflow (리터럴)
  • Memory 계산
  1. Practice
  2. Algorithm
  3. Strategy

Number Data Types

int vs long

  • int 범위가 더 작지만, 연산 속도가 더 빠르다

  • 꼭 필요한 경우에만 long 쓰자

float vs double

  • 정확도 자체는 double이 더 높다

  • 둘 다 느리니까 double 쓰자.

Overflow (리터럴)

long a = 10000000 * 100000; // int * int -> int
System.out.println(a);
>>> -727379968

long b = 10000000L * 100000; // long * int -> long
System.out.println(b);
>>> 1000000000000

double a = 3 / 2;
System.out.println(a); // 소수점 이하 버림 발생
>>> 1.0

double b = 3 / 2.0
System.out.print(b); 
>>> 1.5

double c = 3f / 2;
System.out.println(c);
>>> 1.5
  • 리터럴의 기본형은 int 형이다.

  • 연산의 결과가 소수점을 포함하려면 .0이나 f를 붙여주어야 한다.

Memory 계산

int N = 100000;
int M = 10000;
int[][] arr = new int[N][M]
  • 위의 경우 할당되는 메모리는 100,000 * 10,000 * 4byte(int) = 4GB

  • 일반적으로 시험에서 주어지는 메모리는 256MB 이므로 위와 같은 크기의 배열 할당은 위험하다.

PreviousPrimitive, Reference, GenericNextFor-Each

Last updated 2 years ago