전체 글
-
[Java] BufferedWriter vs println 속도분석Java 2022. 3. 4. 00:01
알고리즘 문제를 풀다가 println으로 제출시에는 시간초과가 발생하고 BufferedWriter는 성공을 하는 문제가 있었습니다. 출력하는 구문이 숫자 1개 였기 때문에 버퍼를 사용하나 하지 않으나 동일할것으로 예상했었습니다. 하지만 숫자 1개를 출력할 때 속도 차이를 테스트했을시에 BufferedWriter가 10배이상 빠른 성능을 보였습니다. 테스트 코드 int iterate = 1; double startPrint = System.nanoTime(); for(int i=0; i
-
테스트 코드 걸음마 떼기 - 은행 계좌 클래스 만들기테스트코드(Test Code) 2022. 3. 3. 02:50
다음 기능을 하는 은행계좌 클래스를 만드려 합니다. 클래스 이름은 Account! 기능 - 계좌 잔고 조회 - 입금/ 출금 - 예상 복리 이자 TDD는 항상 테스트를 먼저 작성합니다. TDD에서 테스트의 최소 작성 단위를 최하위 모듈의 단위와 일치시킵니다. Java 언어 기준으로 최하위 모듈이란 '메서드'입니다. 계좌 클래스의 이름은 Account라고 하겠습니다. 1. AccountTest.java 파일을 생성합니다. 계좌 잔고 조회에 대해 한번에 테스트를 작성하고 싶지만 한번 참아보겠습니다. 우선 계좌를 생성하고 그 계좌가 정상적으로 생성되었는지 확인해보겠습니다. 2. 계좌가 생성되었는지 확인하는 테스트 코드를 작성합니다. package test; public class AccountTest { pub..
-
5215. 햄버거 다이어트알고리즘/SW Expert Academy 2022. 3. 3. 00:01
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWT-lPB6dHUDFAVT SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 문제 해석 민기가 주로 이용하는 햄버거 가게에서는 고객이 원하는 조합으로 햄버거를 만들어서 준다. 민기는 이 가게에서 자신이 먹었던 햄버거의 재료에 대한 맛을 자신의 오랜 경험을 통해 점수를 매겨놓았다. 민기의 햄버거 재료에 대한 점수와 가게에서 제공하는 재료에 대한 칼로리가 주어졌을 때 민기가 좋아하는 햄버거를 먹으면서도 다이어트에 성공할 수 있도록 정해진 칼로리 이하의 조합 중에서 민기가 가장 ..
-
쿠버네티스(Kubernetes,k8s)란?MSA & 쿠버네티스(Kubernetes) - k8s 2022. 3. 2. 16:30
쿠버네티스란? 쿠버네티스는 그리스어로 "키잡이"를 뜻에서 유래되었습니다. 쿠버네티스 또는 k8s로 불리는데 k8s라는 표기는 첫 글자 k와 마지막 글자 s 사이에 8글자를 나타내는 약식 표기입니다. 컨테이너화 된 애플리케이션의 자동 배포, 스케일링 등을 제공하는 오픈소스 기반의 관리시스템입니다. 구글에 의해 설계되었고 리눅스 재단인 CNCF에 의해 관리되고 있습니다. 도커를 포함하여 일련의 컨테이너 도구들과 함께 동작합니다. 컨테이너화된 애플리케이션..? 아래 글을 읽어보시면 좀 더 이해가 잘되실 텐데 VM에서 O/S가 빠져있는 것이 바로 컨테이너이며 이 컨테이너를 통해 배포함을 의미합니다. 쿠버네티스를 사용하는 이유? 전통적인 배포 시대 애플리케이션을 물리 서버에서 실행했습니다. 만약에 하나의 물리 서..
-
[Java] Java Multi-Thread Programming의 모든것을 알아보자Java/자바를 더 깊게 2022. 3. 2. 01:53
Multi-Thread란 무엇인가(What)? 우선 Multi-Thread에 대해 알아보기 전에 프로세스에 대해 먼저 알아보겠습니다. 프로세스란? 단순하게 말하자면 실행 중인 프로그램입니다. 프로그램을 실행하면 OS로부터 실행에 필요한 자원(메모리)을 할당받아 프로세스가 됩니다. 우리가 친숙한 바탕화면의 실행 아이콘들이 프로그램입니다. 프로세스는 CPU, 메모리, 디스크, 네트워크 등의 자원을 사용하고 있습니다. 이클립스가 메모리를 1GB사용하고있네요. 프로세스는 프로그램을 수행하는데 필요한 데이터와 메모리 등의 자원 그리고 스레드로 구성되어 있습니다. 프로세스의 자원을 이용해서 실제로 작업을 수행하는 것이 바로 스레드입니다. 따라서 모든 프로세스에는 최소한 하나 이상의 스레드가 존재하며, 둘 이상의 스..
-
반복과 재귀(Iteration, Recursion)알고리즘/알고리즘 2022. 3. 2. 00:01
반복문과 재귀의 공통점 반복은 (for / while) 문을 통하여 작업이 완료될 때까지 계속 반복합니다. 재귀는 주어진 문제의 해를 구하기 위해 동일하면서 더 작은 문제의 해를 이용하는 방법입니다. 반복문과 재귀를 통하여 유사한 작업을 수행할 수 있습니다. 반복문은 어떤 기준으로 반복할 것인가를 찾아내는 것이 중요하고, 이는 재귀 함수의 구현부를 의미합니다. 재귀 함수는 구현부를 통해 자기 자신을 호출하고 반복하게 됩니다. 반복문은 조건을 통해 반복문을 탈출하고, 재귀 함수도 특정 조건 시에 return을 통해 반복을 탈출합니다. 재귀 함수란? - 함수 내부에서 직접 혹은 간접적으로 자기 자신을 호출하는 함수 - 기본 부분(basis part)과 유도 파트(inductive part)로 구성된다. (기..
-
자바 순열과조합알고리즘/알고리즘 2022. 3. 1. 00:01
순열 서로 다른 것들 중 몇 개를 뽑아서 한 줄로 나열하는 것 서로 다른 n개 중 r개를 택하는 순열은 아래와 같이 표현합니다. nPr A B C 중 2개를 뽑는다고 한다면 결과는 아래와 같습니다. A, B A, C B, A B, C C, A C, B 순열은 이처럼 AB와 BA // AC와 CA // BC와 CA를 다른 경우의 수로 봅니다. 만약 AB = BA가 성립한다면 순서가 의미 없기 때문에 이는 순열이 아니라 조합으로 접근해야 합니다. 프로그래밍적으로 접근해보자면 A를 뽑는다면 A는 더 이상 뽑지 못하고 다음 후보로는 (B, C)가 올 수 있습니다. 만약 다음 후보에 B, C 어떤 것이 뽑히던 2개를 뽑았기 때문에 끝나게 됩니다. 따라서 처음에 올 수 있는 후보는 3가지 (A, B, C) 그다음 ..
-
[Java] Java8 default 인터페이스Java 2022. 2. 28. 16:38
default interface란? interface라 하면 추상화를 위해 method의 구현은 없고 선언만 있는 모습을 떠올리기 쉽습니다. public interface MyInterface{ int myAbstractMethod1(); int myAbstractMethod2(); } 하지만 Java8에서는 interface에 아래와 같은 method들을 정의하는 것이 가능해졌습니다. public interface MyInterface { int myAbstractMethod1(); int myAbstractMethod2(); default int myDefaultMethod() { return 0; } static int myStaticMethod() { return 0; } } 키워드 default..