전체 글
-
Java Generic Compile 동작JAVA 2023. 9. 11. 14:42
Java 의 Generic Java에는 Generic이라는 이라는 기능이 있다. Generic 이라는 기능은 JDK 1.5 부터 도입된 기능인데 이전 자바 버전의 코드와의 호환성은 어떤식으로 유지하는걸까? 이를 위해 Type Erasure라는 기능으로 컴파일 시에는 Generic type을 제거하게 된다. 이와 관련하여 간단하게 확인해 보자. Reifiable 과 Non-Reifiable Refiable Type (구체화 타입) 타입 정보를 런타임시에 알고 구체화 하는것. 컴파일 단계에서 Type Erasure에 의해 지워지지 않는다. 일반적인 타입과 unbound wildecard type 등이 포함된다. Non-Reifiable Type (비구체화 타입) 타입 정보가 런타임때 사라지는것. 컴파일 단계..
-
JVM Memory AreaJAVA 2023. 9. 8. 16:46
JVM Architecture Class Loader JVM 내로 .class 파일들을 Load 하여 Loading된 클래스들을 Runtime Data Area에 배치한다. JVM Memory Runtime Data Area 라고도 하며 JVM이 OS에서 할당 받은 메모리 공간이다 Execution Engine Runtime Data Area에 할당됭 ByteCode 를 실행하는 역할을 한다. Interpreter, JIT compiler, Garbage Collector 로 구성되어있다. Native Method Libraries 실행에 필요한 C,C++로 이루어진 Native Libraries 이다. Native Method Interface (JNI) JVM이 Native Method Librari..
-
Java 버전 별 ArrayList add 동작JAVA 2023. 9. 6. 18:51
Java 6 public boolean add(E e) { ensureCapacity(size + 1); // Increments modCount!! elementData[size++] = e; return true; } Java 6 에서 ArrayList add이다. ensureCapacity에 현재 size +1을 전달하여 크기를 확인한다. public void ensureCapacity(int minCapacity) { modCount++; int oldCapacity = elementData.length; if (minCapacity > oldCapacity) { Object oldData[] = elementData; int newCapacity = (oldCapacity * 3)/2 + 1; ..
-
부동소수점 표현 방식 [IEEE 754]공부방 2023. 8. 31. 11:56
실수 표현 방식 많은 프로그램 언어에서 실수를 표현하기 위해 IEEE 754 표준을 따르는 부동소수점 방식을 사용하고 있다. 부동소수점 방식이란, 소수점의 위치가 고정되지 않고 그 위치를 나타내는 수를 따로 적어 유효숫자를 나타내는 가수와 위치를 나타내는 지수로 표현하는 것을 말한다. 32bit float 에서 부동소수점 표기 방법을 예로 들면 다음과 같다. - 부호: 0이면 양수, 1이면 음수 - 지수: 부호있는 정수. -127 ~ 128 - 가수: 실제 값을 저장 IEEE 754 IEEE 754는 IEEE에서 개발한 컴퓨터에서 부동소수점을 표현하는 가장 널리 쓰이는 표준이다. JAVA에서도 이 규격에 따라 부동소수점을 표현한다. 단정도와 배정도 정밀도는 유효자리수라고 이해할 수 있다. 단정도 (Sin..
-
Java Thread Safety 한 개발JAVA 2023. 8. 29. 18:23
Thread Safe 개발을 하다보면 Multi-Thread 환경에서 작업해야하는 경우가 있다. 이때 공유되는 자원등에 대해 Thread-safe 하게 작업하는것이 중요하다. Thread-safe 하나는것은 여러 스레드에서 클래스 혹은 객체헤 동시에 접근하여도 정확하게 동작하는것을 의미한다. Thread Safe 하게 개발하기 Synchronized Java에서 가장 간단하게 Thread-Safety 하게 개발하는 방법은 synchronized keyword를 사용하는 것이다. public class IncreaseNumber{ public int number; public synchronized int increase(){ return number++; } } 위처럼 synchronized keywor..
-
스프링과 디자인 패턴공부방 2023. 8. 27. 20:26
디자인 패턴 소프트웨어 디자인 패턴(software design pattern)은 소프트웨어 공학의 소프트웨어 디자인에서 특정 문맥에서 공통적으로 발생하는 문제에 대해 재사용 가능한 해결책이다. 디자인 패턴은 시스템을 디자인 할 때 공통된 문제들을 해결하는데에 쓰이는 형식화 된 관행이라고 볼 수 있다. '스프링 입문을 위한 자바 객체 지향의 원리와 이해' 라는 책에서 소개된 디자인 패턴중 일부를 살펴 보고 이 패턴들이 스프링에서 어떤식으로 사용 되는지 살펴보자 어댑터 패턴 먼저 어댑터 패턴이 적용되지 않은 두 클래스를 보자 public class ServiceA{ void runServiceA(){ System.out.println("ServiceA"); } } public class ServiceB{ ..
-
Singleton 구현 기법JAVA 2023. 8. 27. 20:18
Singleton 패턴 생성자가 여러 차례 호출되더라도 실제로 생성되는 객체는 하나이고 최초 생성 이후에 호출된 생성자는 최초의 생성자가 생성한 객체를 리턴한다. 기본적인 Singleton 패턴 public class Singleton { private static Singleton instance; private Singleton(){} public static Singleton getInstance(){ if(instance == null){ instance = new Singleton(); } return instance; } } Singleton의 getInstance를 호출할때 instance가 없다면 만들어주고 있다면 만들어둔 instance를 return 해준다. 이 코드는 스레드가 여러개일..
-
CAP Theorem공부방 2023. 8. 6. 19:58
CAP 정리 CAP 정리 (또는 브루어의 정리)는 다음과 같은 세 가지 조건을 모두 만족하는 분산 컴퓨터 시스템은 존재하지 않음을 증명한 정리이다. Consistency(일관성) : 모든 노드가 같은 순간에 같은 데이터를 볼 수 있다. Availability(가용성) : 모든 요청이 성공 또는 실패 결과를 반환할 수 있다. Partition tolerance(분할 내성) : 메시지 전달이 실패하거나 시스템 일부가 망가져도 시스템이 계속 동작할 수 있다. 위는 위키백과 기준으로 CAP 정리에대해 검색했을때의 결과이다. 단순히 CAP 중 2개를 선택하여 분산 시스템을 설계하기에는 다음과 같은 문제가 있다. Partition tolerance는 분할 내성이라는 표현으로 해석되었다. 하지만 명확한 의미는 The..