전체 글
-
[백준] 1965번 : 상자넣기 - 자바(JAVA)알고리즘/백준 2022. 2. 16. 00:01
https://www.acmicpc.net/problem/1965 1965번: 상자넣기 정육면체 모양의 상자가 일렬로 늘어서 있다. 상자마다 크기가 주어져 있는데, 앞에 있는 상자의 크기가 뒤에 있는 상자의 크기보다 작으면, 앞에 있는 상자를 뒤에 있는 상자 안에 넣을 수가 www.acmicpc.net 문제 해석 상자가 일렬로 늘어서 있는데 상자마다 크기가 존재한다. 앞에 있는 상자의 크기가 뒤에 있는 상자의 크기보다 작으면, 앞에 있는 상자를 뒤에 있는 상자 안에 넣을 수 있다. 만약 상자의 크기가 (1, 5, 2, 3, 7)인 5개의 상자가 존재한다면, 크기 1인 상자를 크기 5인 상자에 넣고 크기 5인 상자를 크기 7인 상자 안에 넣을 수 있다. 상자의 크기가 주어질 때, 한 번에 넣을 수 있는 최..
-
[Java] String이 불변 객체인 이유는?Java/자바를 더 깊게 2022. 2. 15. 01:19
보통 String / StringBuffer / StringBuilder의 차이점들은 많이 알고 있습니다. String은 불변 객체이며, StringBuffer/ StringBuilder는 가변 객체입니다. 또한 StringBuilder는 thread-safe 하지 않으며 StringBuffer는 thread-safe 합니다. 그런데 String은 왜 불변 객체로 만들었을까요? 1. 성능 자바에서 문자열은 정말 많이 사용됩니다. 따라서 자바는 상수풀 이라는 것을 만들었습니다. public class Test { public static void main(String[] args) { String s1 = "Hello World"; String s2 = "Hello World"; System.out.pri..
-
클린 코드 - 오류 처리클린 코드(Clean Code) 2022. 2. 15. 00:01
입력이 이상하거나 디바이스가 실패할지도 모르기 때문에 오류 처리는 프로그램에 필수적인 요소입니다. 여기저기 흩어진 오류 처리 코드는 실제 코드가 하는 일을 파악하기 어렵게 만들기 때문에 오류 처리는 중요합니다. 1. 오류 코드보다는 예외를 사용하라 오류 플래그를 사용한 경우 = 예외를 사용하지 않음 if(!Error1){ doSomething1(); if(!Error2){ doSomething2(); } else { logger.log("Error2 발생"); } } else{ logger.log("Error1 발생"); } 예외를 사용하는 경우 try{ doSomething1(); } catch (Exception e){ logger.log(e); } try{ doSomething2(); } catch..
-
테스트 코드 - 회원 관리 예제 실습(회원 서비스 개발)테스트코드(Test Code) 2022. 2. 14. 00:01
이전에 회원 관리 예제를 작성하는 실습(회원 서비스 개발)을 진행하였습니다. 이를 통해 테스트 코드를 작성해보고자 합니다. https://junuuu.tistory.com/93 1. src/test/java 에 hello.hellospring.service 패키지를 생성합니다. 2. hello.hellospriong.service패키지에 MemberServiceTest 클래스를 생성합니다. 일반적으로 테스트하고자 하는 클래스 이름 뒤에 Test를 붙여 이름 짓습니다. 3. MemberServiceTest 클래스에 테스트 코드를 작성합니다. package hello.hellospring.service; import static org.junit.jupiter.api.Assertions.assertThrow..
-
스프링 부트 - 회원 관리 예제 실습(회원 서비스 개발)Spring Framework 2022. 2. 13. 00:01
이전 시간에는 회원 도메인과 리포지토리를 생성했습니다. https://junuuu.tistory.com/75 스프링 부트 - 회원 관리 예제 실습(회원 도메인과 리포지토리 생성) 비즈니스 요구사항 정리 데이터 : 회원 ID, 이름 기능 : 회원 등록, 조회 아직 데이터 저장소가 선정되지 않은 가상의 시나리오(어떤 데이터베이스를 사용할지 정해지지 않음) 일반적인 웹 애플리 junuuu.tistory.com 오늘은 회원 도메인과 리포지토리를 기반으로 회원 서비스를 개발해보겠습니다. 클래스 의존관계 MemberService는 MemberRepository에 의존적이기 때문에 MemberRepository를 사용해야 합니다. 1. hello.hellospring.service 패키지 생성 2. hello.hel..
-
[백준] 1931번 : 회의실 배정 - 자바(JAVA)알고리즘/백준 2022. 2. 12. 00:01
https://www.acmicpc.net/problem/1931 1931번: 회의실 배정 (1,4), (5,7), (8,11), (12,14) 를 이용할 수 있다. www.acmicpc.net 문제 해석 한 개의 회의실이 존재하며 회의를 하기 위해서는 회의실을 사용해야 한다. N개의 회의에 대하여 시작시간과 끝나는 시간이 주어진다. 이때 회의가 겹치지 않으며 최대가 되는 회의의 개수를 찾아보자. 회의가 끝나는 것과 동시에 다음 회의가 시작할 수 있다. 회의의 시작시간과 끝나는 시간이 같을 수도 있다. 입력 첫째 줄에 회의의 수 N이 주어진다. 둘째 줄부터 N개의 회의시작시간과 회의 종료시간이 주어진다. 제약조건 1
-
[Java] Optional이란?Java 2022. 2. 11. 00:01
Optional이란? Java 8에서 최초로 도입되었습니다. 'T' 타입의 객체를 포장해 주는 래퍼 클래스로 모든 타입의 참조 변수를 저장할 수 있습니다. Optional은 "값이 존재할 수도 있지만 안 할 수도 있는 객체" 즉, "null이 될 수도 있는 객체"를 포장해주는 래퍼클래스입니다. public final classOptional{ private final T value; } 래퍼 클래스란? 만약 메서드가 매개변수를 객체 형태로 받을 경우 기본 타입을 객체화하여 매개변수로 전달할 때 사용하는 클래스로 자세한 부분은 아래 링크를 참조하시면 좋을 것 같습니다. https://junuuu.tistory.com/68 [Java] 래퍼 클래스(Wrapper Class)란? Optional에 대해 알아보..
-
[Java] 스트림의 최종연산Java 2022. 2. 10. 00:01
이전 시간에 스트림의 중간 연산에 대해 알아보았습니다. https://junuuu.tistory.com/88?category=968252 스트림은 아래와 같은 주기를 가집니다. 1. 스트림 생성 2. 중간 연산 (0~ n번) 3. 최종 연산 (0~1번) 오늘은 스트림의 최종 연산에 대해 알아보겠습니다. 최종 연산에는 스트림의 요소를 소요하며 스트림이 닫히기 때문에 한 번만 연산할 수 있습니다. 중간 연산은 Stream을 반환하는 반면에 최종 연산은 int, boolean, Optional 등을 반환합니다. 최종 연산에는 어떤것들이 있는지 보겠습니다. forEach(), forEachOrdered() void forEach(Consumer