본문 바로가기

전체 글

(161)
기타 etc (Pattern Matching, Text Blocks, Enum) Pattern Matching ( Java 16+ ): 타입 확인 + 타입 변환(casting)을 한 번에 처리Object obj = "Hello";if (obj instanceof String str) { System.out.println(str.length());} 조건과 함께 사용 가능if (obj instanceof String str && str.length() > 5) { System.out.println(str);} switch에서도 사용가능 ( Java 21 + )static String getType(Object obj) { return switch (obj) { case String str -> "문자열: " + str; case Integer ..
Record : Java record는 "데이터를 담는 객체(DTO)를 아주 간결하게 만드는 문법public record UserRecord( Long id, String custNo, String email, String password, String name, String nickname, String phone, String role, String status, LocalDateTime createdAt, LocalDateTime updatedAt, LocalDateTime deletedAt){}- 자동으로 생성자를 만들어 준다.- final이라는 중요한 특징, Record의 필드는 기본적으로 변경할 수 없다.- equals(), hashCode(..
[NIO] Files, Path NIO는 파일 시스템의 작업을 위한 강력한 기능을 제공합니다. FileChannel을 사용하여 파일의 데이터를 읽고 쓸 수 있습니다.이 외에도 Paths, Files와 같은 유틸리티 클래스들을 통해 파일 복사, 이동, 삭제, 파일 속성 읽기 등의 작업을 효율적으로 처리할 수 있습니다.API용도Path파일/디렉터리 경로 표현Path.of()Path 생성Paths.get()Path 생성, 기존 방식Files.readString()파일 → StringFiles.writeString()String → 파일Files.copy()복사Files.move()이동/이름 변경Files.delete()삭제Files.exists()존재 여부Files.createDirectory()디렉터리 생성Files.createDirect..
CompetableFuture CompletableFuture는 "아직 결과가 나오지 않은 작업의 결과를 담아두는 객체"이며크게 비동기 작업 실행 → 결과 변환 → 다른 비동기 작업과 연결 → 완료 대기 → 예외 처리 흐름으로 처리됩니다. 1. supplyAsync(): 값을 반환하는 비동기 작업CompletableFuture future = CompletableFuture.supplyAsync(() -> { try { Thread.sleep(1000); } catch (InterruptedException e) { throw new RuntimeException(e); } return "Hello, World!"; });2. runAsync(): 값을 반환하지 않는 비동기 작업.CompletableFutu..
Comparator `Comparator` 는 객체를 어떤 기준으로 정렬할지 정의하는 함수형 인터페이스(Functional Interface) 입니다. 1. compareint compare(T o1, T o2);반환값의미음수o1이 먼저0같다양수o2가 먼저 compare 구현Comparator com1 = (p1, p2) -> { if (p1 == null && p2 == null) { return 0; } else if (p1 == null) { return -1; } else if (p2 == null) { return 1; } else { return p1.compareTo(p2); } }; String.compareTo()는 사전적인 의미가 아니라, 각 문자의 Unicode(..
Comparator, Collectors `Comparator` 는 객체를 어떤 기준으로 정렬할지 정의하는 함수형 인터페이스(Functional Interface) 입니다. 1. compareint compare(T o1, T o2);반환값의미음수o1이 먼저0같다양수o2가 먼저 compare 구현Comparator com1 = (p1, p2) -> { if (p1 == null && p2 == null) { return 0; } else if (p1 == null) { return -1; } else if (p2 == null) { return 1; } else { return p1.compareTo(p2); } }; String.compareTo()는 사전적인 의미가 아니라, 각 문자의 Unicode(..
LocalTime, LocalDate, LocalDateTime LocalDate 날짜 년/월/일 생일LocalTime 시간 시/분/초 LocalDateTime 날짜 + 시간 년/월/일 + 시/분/초 주요메소드메서드용도now()현재 날짜/시간 조회format()화면 표시, 로그 출력parse()문자열을 날짜/시간으로 변환plusDays(), plusMonths(), plusHours()날짜·시간 계산minusDays(), minusMinutes()날짜·시간 계산isBefore(), isAfter()날짜·시간 비교toLocalDate(), toLocalTime()LocalDateTime 분리of()테스트 데이터 생성getYear(), getMonthValue(), getDayOfMonth()날짜 정보 추출getHour(), getMinute(), getSecond()시..
HTTP Contents Type Content-TypeContent-Type 해당 개체에 포함되는 미디어 타입 정보 컨텐츠의 타입(MIME 미디어 타입) 및 문자 인코딩 방식(EUC-KR,UTF-8 등)을 지정한다. Content-Type1) XML Media의 타입 - Content-Type: text/xml - Content-Type: Application/xml - Content-Type: Application/xml-external-parsed-entity - Content-Type: Application/xml-dtd - Content-Type: Application/mathtml+xml - Content-Type: Application/xslt+xml2) Application의 타입 - Content-Type: Appli..