본문 바로가기

전체 글669

kosta 클라우드 네이티브 애플리케이션 개발 과정 day 17 kosta 클라우드 네이티브 애플리케이션 개발 과정 day 17 array, list, set 을 이용한 lotto number 생성 예제 package kosta.mission3.mission3_02.lectureSolution; import java.util.*; public class LottoMain { public static void main(String[] args) { } private static void lottoWithSet() { Random random = new Random(); Set set = new TreeSet(); for (int i =0; set.size() < 6; i ++){ set.add(random.nextInt(45) + 1); } System.out.prin.. 2023. 1. 11.
[독서 기록] 모던 자바 인 액션 13장, 디폴트 메서드 모던 자바 인 액션 13장, 디폴트 메서드 자바의 디폴트 메서드 : 기존 인터페이스를 구현하는 클래스가 자동으로 인터페이스에 추가도니 새로운 메서드의 디폴트 메서드를 상속받게 한다 List 인터페이스의 sort 메서드 default void sort(Comparator 2023. 1. 11.
[독서 기록] 모던 자바 인 액션 12장, 새로운 날짜와 시간 api java.time 패키지의 local 을 사용해보기 LocalDate 만들고 값 읽기 LocalDate date = LocalDate.of(2017, 9, 21); int year = date.getYear();// 2016 Month month = date.getMonth();// September int day = date.getDayOfMonth();// 21 DayOfWeek dow = date.getDayOfWeek(); // thursday int len = date.lenghOfMonth();// 31 boolean leap = date.isLeapYear(); // false (윤년 여부) 팩토리 메서드 now는 시스템 시계의 정보를 이용해서 현재 날짜 정보를 얻는다. LocalDate t.. 2023. 1. 11.
[독서 기록] 모던 자바 인 액션 11장 null 대신 Optional 클래스 11장 null 대신 Optional 클래스 보수적인 null 처리법 public String getCarInsuranceName(Person person) { if (person != null) { Car car = person.getCar(); if (car !=null) { Insurance insurance = car.getInsurance(); if (insurance !=null) { return insurance.getName(); } } } } returrn "Unknown"; } - 365p null 때문에 발생하는 문제 - 에러의 근원이다 - 코드를 어지럽힌다 - 아무 의미가 없다 - 자바 철학에 위배된다 - 형식 시스템에 구멍을 만든다 - 367p 값이 있으면 Optional 클래스는.. 2023. 1. 11.
Java도 함수형 프로그래밍을 지향해야 하는 이유 함수형 프로그래밍 * 함수형 프로그래밍의 특징은 함수를 일급 시티즌으로 대우한다는 것이다 * stream에서 for each로 element를 돌면서 데이터를 보내는 것이 아니라 함수, 즉 action을 보낸다 * function을 sending 한다 ! /** * 기존의 for문을 이용한 sum을 구할 때와는 달리 * local variable이나 mutations, loop 등을 신경쓸 필요 없다 * Fp는 그저 명령할 뿐이다 * * 또한 명령을 수행함에 있어 구체적인 방법을 정하지 않는다 * just saying what to do and not how to do */ List numbers = List.of(4, 5, 6, 7, 8, 3, 15); int sum = numbers.stream() .. 2023. 1. 10.