전체 글
-
프록시(proxy) 패턴디자인 패턴 2022. 5. 3. 15:24
프록시와 리얼 서브젝트가 공유하는 인터페이스가 있고, 클라이언트는 해당 인터페이스 타입으로 프록시를 사용한다. 클라이언트는 프록시를 거쳐서 리얼 서브젝트를 사용하기 때문에 프록시는 리얼 서브젝트에 대한 접근을 관리거나 부가기능을 제공하거나, 리턴값을 변경할 수도 있다. 리얼 서브젠트는 자신이 해야 할 일만 하면서(SRP) 프록시를 사용해서 부가적인 기능(접근 제한, 로깅, 트랜잭션, 등)을 제공할 때 이런 패턴을 주로 사용한다. 참고 백기선 - 더 자바, 코드를 조작하는 다양한 방법 https://www.oodesign.com/proxy-pattern.html https://en.wikipedia.org/wiki/Proxy_pattern https://en.wikipedia.org/wiki/Single_..
-
클래스 로더 (class loader)프로그래밍/Java 2022. 5. 1. 15:14
JVM internal 아키텍처 에서 클래스 로더 시스템을 자세하게 그리면 위와 같이 구성되어 있다. 참고 https://hyokeun0419.tistory.com/77 클래스 로더 로딩, 링크, 초기화 순으로 진행된다. 로딩 클래스 로더가 .class 파일을 읽고 그 내용에 따라 적절한 바이너리 데이터를 만들고 "메소드" 영역에 저장 이 때 메소드 영역에 저장하는 데이터 FQCN(fully qualified class name, 패키지 경로까지 포함된 클래스 이름) , 클래스 | 인터페이스 | 이늄, 메소드와 변수 로딩이 끝나면 해당 클래스 타입의 Class 객체를 생성하여 "힙" 영역에 저장 특정 클래스를 읽을 때 최상위 부모에게 먼저 읽어달라는 요청을 한다. (Bootstrap > Extension..
-
JVM 구조프로그래밍/Java 2022. 4. 30. 22:28
JVM 구조는 크게 클래스 로더 시스템, 메모리, 실행 엔진 으로 구성되어 있다. 클래스 로더 시스템 컴파일된 .class 파일(byte code) 를 읽고 메모리에 적절하게 배치하는게 클래스 로더가 하는 일이다. 클래스 로더가 하는일은 크게 세 가지로 나누어 볼 수 있다. 로딩, 링크, 초기화 로딩: 클래스 파일에서 byte code 를 읽어오는 과정 링크: 레퍼런스를 연결하는 과정 초기화: static 값들 초기화 및 변수에 할당 메모리 크게 다섯가지 영역으로 나뉘어져 있다. 모두 중요하긴 하지만 하나를 꼽으라면, 메소드 영역을 더 유심히 볼 필요가 있다. 메소드 영역에는 클래스 수준의 정보 (클래스 이름, 부모 클래스 이름, 메소드, 변수) 를 저장한다. 그리고 공유자원이다. 즉 다른 영역에서도 참..
-
발행-구독 패턴디자인 패턴 2022. 4. 30. 20:10
발행(publisher) 구독(subscriber) 패턴은 옵저버(Observer) 패턴과 유사한 부분이 많다. 발행-구독 패턴이 무엇인지, 옵저버 패턴과 어떤 차이가 있는지 살펴보자. 발행구독 패턴 발행자와 구독자가 있고 그 사이에 브로커(=메시지 큐)가 존재하는 형태이다. 이것의 특징을 나열하면 아래와 같다. 1. 발행자 메시지의 수신자가 정해져 있지 않다. 2. 메시지는 정해진 범주에 따라서 구독을 신청한 수신자에게 전달이 된다. 3. 수신자는 발행자에 대한 정보 없이 원하는 메시지를 수신할 수 있다. 4. 메시지큐 패러다임과 마치 형제같은 관계로 대형 메시지 지향 미들웨어 솔루션의 일부라고 한다. 발행자(=pub)와 구독자(=sub) 은 아래와 같은 특징을 가진다. 1. pub 이 sub 의 선언..
-
JDK, JRE, JVM 이해하기프로그래밍/Java 2022. 4. 29. 22:39
JVM (Java Virtual Machine) 자바 가상 머신으로 자바 바이트 코드 (.class file) 를 OS에 특화된 코드로 변환(인터프리터와 JIT 컴파일러)하여 실행한다. 바이트 코드를 실행하는 표준(JVM 자체는 표준)이자 구현체(특정 벤더가 구현한 JVM)이다. JVM 벤더: 오라클, 아마존 등 특정 플랫폼에 종속적이다. .java 파일을 컴파일하면 .class 파일이 생성되는데 해당 파일은 바이트 코드로 이루어져 있다. 이후 바이트 코드(.class 파일)를 인터프리터와 JIT 컴파일러를 사용하여 해당 OS에 맞는 기계어로 변경한 후 실행되게 된다. (OS에 의존적이기 때문에 특정 플랫폼에 종속적인 것이다.) 이 외에도 JVM 은 메모리 관리의 역할도 가지고 있다. 여러 밴더에 따라 ..
-
[leetcode] 27. Remove Element알고리즘 2021. 11. 22. 21:23
Description 정수 배열과 특정 값이 주어졌을때, 배열 안에 특정 값이 있다면 모두 제거하는 문제 Input: arr = [3, 2, 2, 3], val = 3 Output: [2, 2, _, _] Input: arr = [0, 1, 2, 2, 3, 0, 4, 2], val = 2 Output: [0, 1, 4, 0, 3, _, _, _] Success 두 개의 포인터 변수를 이용하여 인덱스를 순회하고 특정 값이 아닌 값들을 앞에 배치시킨다. class Solution { public int removeElement(int[] nums, int val) { if (nums == null) return -1; int j=0; for (int i=0; i
-
[leetcode] 905. Sort Array By Parity알고리즘 2021. 11. 22. 18:19
Description 정수 배열이 주어졌을때, 짝수인 요소를 앞으로 이동시켜라 Input: arr = [3, 1, 2, 4] Output: [2, 4, 3, 1] Input: arr = [0] Output: [0] Success 두 개의 포인터 변수를 둔다. 인덱스를 돌며 짝수인 값을 앞으로 이동시킨다. 이동이 된 후에는 그 다음 인덱스를 가리킬 수 있도록 j 값을 1씩 증가시킨다. class Solution { public int[] sortArrayByParity(int[] nums) { int j=0; for (int i=0; i
-
[leetcode] 283. Move Zeroes알고리즘 2021. 11. 19. 08:09
Description 정수 배열이 주어졌을때, 0이 아닌 요소를 앞으로 이동시키고 배열의 모든 0 은 끝으로 이동시킨다. Input: arr = [0, 1, 0, 3, 12] Output: [1, 3, 12, 0 ,0] Input: arr = [0] Output: [0] fail 두 개의 포인터 변수를 둔다. 0이 아닌 값들을 찾을 변수 i 와 앞에서부터 변경되어야 할 인덱스를 가르키는 변수 j를 두어 계속해서 0이 아닌 값들을 앞으로 이동시킨다. 결국 0인 값들은 뒤로 이동되고, 0이 아닌값들은 앞으로 이동된다. class Solution { public void moveZeroes(int[] nums) { int j = 0; for(int i = 0; i < nums.length; i++) { if(..