전체 글
-
테스트코드에서는 H2 DB를 사용하자!프로젝트/게시판 프로젝트 2022. 5. 11. 21:48
H2 데이터베이스란? H2는 자바 기반 오픈소스 RDBMS입니다. 주로 인 메모리 데이터베이스로 사용되며 기능 테스트할 때 유용합니다. 인 메모리 데이터베이스는 휘발성 데이터베이스이기 때문에 컴퓨터를 종료하면 모든 데이터가 삭제됩니다. 스프링 부트에서 dependency를 추가하면 약 2MB 크기의 라이브러리로 H2 DB를 사용할 수 있습니다. H2 데이터베이스를 사용하는 이유는? 실제 서비스용 DB는 따로두고 테스트 코드용 DB와 분리하여 이용할 수 있습니다. 또한 휘발성 데이터베이스이기 때문에 테스트코드의 매번 DB를 지워주는 작업 없이 테스트 코드의 재사용성을 높일 수 있게 합니다. 인 메모리 데이터베이스이기 때문에 빠른 실행속도를 보여줍니다. 사용법 build.gradle에 다음과 같은 의존성을 ..
-
[프로그래머스] 2019 KAKAO BLIND RECRUITMENT - 무지의 먹방 라이브 - 자바(JAVA)알고리즘/프로그래머스 2022. 5. 11. 00:01
https://programmers.co.kr/learn/courses/30/lessons/42891 코딩테스트 연습 - 무지의 먹방 라이브 programmers.co.kr 문제 해석 회전판에 먹어야 할 N개의 음식이 존재합니다. 각 음식에는 1부터 N까지 번호가 붙어있으며, 각 음식을 섭취하는데 일정 시간이 소요됩니다. 무지는 다음과 같은 방법으로 음식을 섭취합니다. 무지는 1번 음식부터 먹기 시작하며, 회전판은 번호가 증가하는 순서대로 음식을 무지 앞으로 가져다 놓는다. 마지막 번호의 음식을 섭취한 후에는 회전판에 의해 다시 1번 음식이 무지 앞으로 온다. 무지는 음식 하나를 1초 동안 섭취한 후 남은 음식은 그대로 두고, 다음 음식을 섭취한다. 다음 음식이란, 아직 남은 음식 중 다음으로 섭취해야 ..
-
Spring Rest API 예외처리 (feat. 스프링의 기본적인 예외 처리 방법과 Best Practice)프로젝트/게시판 프로젝트 2022. 5. 10. 18:46
긴글을 읽기 싫은 분들을 위한 요약 1. Spring은 기본적으로 예외 처리를 지원합니다.(whitelabel 에러 페이지) 2. 하지만 기본예외처리는 404에러가 나도 500에러를 보여줍니다. 3. try-catch를 사용하면 가독성이 떨어지기 때문에 이를 해결하기 위해 Spring은 다양한 에러처리 방법을 지원합니다. 4. @ResponseStatus의 단점 에러 응답 내용을 수정할 수 없음 5. @ExceptionHandler 컨트롤러 내에서 사용되면 중복된 코드가 발생됨 6. @ControllerAdvice와 @RestControllerAdvice를 활용하면 전역적으로 예외를 처리할 수 있음(Best Practice) 7. 실제 프로젝트 적용예시(try-catch로 하던 예외처리를 @RestCon..
-
Java는 왜 Pure OOP가 아닐까?Java 2022. 5. 10. 00:38
Pure OOP란? 말 그대로 순수하게 완전히 OOP를 지향하고 관련 기능을 지원하는 언어를 말합니다. 프로그래밍 언어가 Pure OOP를 지원하기 위해서는 7가지 특성이 충족되어야 합니다. Encapsulation/Data Hiding(캡슐화/은닉화) Inheritance(상속) Polymorphism(다형성) Abstraction(추상화) All predefined types are objects (이미정의 된 타입들은 모두 객체여야 한다) All user defined types are objects (사용자가 정의한 타입들은 모두 객체여야 한다.) All operations performed on objects must be only through methods exposed at the obje..
-
[백준] 10282번 : 해킹 - 자바(JAVA)알고리즘/백준 2022. 5. 10. 00:01
https://www.acmicpc.net/problem/10282 10282번: 해킹 최흉최악의 해커 yum3이 네트워크 시설의 한 컴퓨터를 해킹했다! 이제 서로에 의존하는 컴퓨터들은 점차 하나둘 전염되기 시작한다. 어떤 컴퓨터 a가 다른 컴퓨터 b에 의존한다면, b가 감염되면 www.acmicpc.net 문제 해석 네트워크 시설의 한 컴퓨터가 해킹되었습니다. 서로 의존하는 컴퓨터들은 점차 하나씩 감염되기 시작합니다. 어떤 컴퓨터 a가 다른 컴퓨터 b에 의존한다면 b가 감염되면 일정 시간 뒤에 a도 감염됩니다. 하지만 b가 a를 의존하지 않는다면 a가 감염되더라도 b는 안전합니다. 컴퓨터 번호와 각 의존성이 주어질 때 , 총 몇 대의 컴퓨터가 감염되며 그에 걸리는 시간이 얼마인지 구하세요 문제 풀이 전..
-
[백준] 1113번 : 수영장 만들기 - 자바(JAVA)알고리즘/백준 2022. 5. 9. 00:01
https://www.acmicpc.net/problem/1113 1113번: 수영장 만들기 지민이는 수영장을 만들려고 한다. 수영장을 만들 곳의 크기는 N*M이고, 각 칸은 직육면체이다. 따라서, 각 칸의 직육면체의 높이가 쓰여 있는 다음과 같은 땅을 생각할 수 있다. 16661 61116 16661 이 www.acmicpc.net 문제 해석 지민이는 수영장을 만드려고 합니다. 수영장을 만들 곳의 크기는 N*M의 직사각형입니다. 각, 칸에는 높이가 쓰여 있습니다. 16661 61116 16661 이 수영장에는 물이 15만큼 들어갈 수 있습니다. 높이가 6인 벽들로 둘러쌓여있는 부분인 가운데 3개의 칸에 5만큼 물을 채울 수 있습니다. 땅의 모양이 주어질 때, 수영장에 물이 얼마큼 있을 수 있는지 구하세..
-
[백준] 17070번 : 파이프 옮기기 1 - 자바(JAVA)알고리즘/백준 2022. 5. 8. 00:01
https://www.acmicpc.net/problem/17070 17070번: 파이프 옮기기 1 유현이가 새 집으로 이사했다. 새 집의 크기는 N×N의 격자판으로 나타낼 수 있고, 1×1크기의 정사각형 칸으로 나누어져 있다. 각각의 칸은 (r, c)로 나타낼 수 있다. 여기서 r은 행의 번호, c는 열의 www.acmicpc.net 문제 해석 N x N 크기의 집이 존재합니다. 각 칸은 (r , c)로 나타낼 수 있습니다. r은 행번호, c는 열 번호입니다. 집은 빈칸0 , 벽 1로 이루어집니다. 파이프는 항상 빈칸만 차지해야 하며 파이프를 밀 수 있는 방향은 →, ↘, ↓입니다. 밀면서 회전시킬 수 있지만 45도만 회전시킬 수 있습니다. 다음 그램은 파이프가 놓여진 방향에 따라서 이동할 수 있는 방..
-
[백준] 17471번 : 게리맨더링 - 자바(JAVA)알고리즘/백준 2022. 5. 7. 00:01
https://www.acmicpc.net/problem/17471 17471번: 게리맨더링 선거구를 [1, 4], [2, 3, 5, 6]으로 나누면 각 선거구의 인구는 9, 8이 된다. 인구 차이는 1이고, 이 값보다 더 작은 값으로 선거구를 나눌 수는 없다. www.acmicpc.net 문제 해석 N개의 구역이 존재하고 이 구역은 1번부터 N번까지 번호가 매겨져 있습니다. 구역을 두 개의 선고 구로 나누어야 하고, 각 구격은 두 선거구 중 하나에 포함되어야 합니다. 선거구는 구역을 적어도 하나 포함해야 하며, 한 선거구에 속한다면 모두 연결되어 있어야 합니다. 구역 A에서 B로 이동할 수 있다면 이는 연결되어 있다고 할 수 있습니다. 공평하게 선거구를 나누기 위해 두 선거구에 포함된 인구의 차이를 최..