Programming
-
[Java] Checked, Unchecked ExceptionProgramming/Java 2024. 3. 13. 16:03
자바 실행 시 발생할 수 있는 프로그램 오류를 Error와 Exception두가지로 구분한다. Error 시스템에 비정상적인 상황이 발생했을 경우 발생 메모리 부족(OutOfMemory Error), 스택오버플로우(StackOverflowError)와 같이 복구할 수 없는 것 Exception 프로그램 실행 중 개발자의 실수로 예기치 않은 상황이 발생 컴파일러가 에러처리를 확인하지 않는 RuntimeException클래스들은 unchecked 예외라고 하고, 예외처리를 확인하는 Exception 클래스들은 checked예외라고 한다. Checked Exception 반드시 에러 처리를 해야 한다(try-catch or thorw) Exception클래스의 하위 ● FileNotFoundException ..
-
[Java] OOME, JVM8 메모리Programming/Java 2024. 2. 29. 17:28
out of memory error 힙 메모리에서 발생하는 메모리 에러 OOME가 발생하는 시점은 대부분 개발이 완료된 후 사용자 테스트 및 인수 테스트 단계에서 많이 발생한다. 즉, 개발 단계에서 수행하는 단위 테스트의 경우 목적 기능에 대한 검중 위주로 진행되기 때문에 식별이 어렵고 가동 초기 단계 혹은 이와 유사한 테스트 환경에서 주로 발생하게 되는 것이다. OOME가 발생한 시점에 빠르게 대응해야 하는데 JVM Option을 통한 처리 방법과 Dump파일 분석을 통해 대응하게 된다. Java의 Reflaction기능을 이용하거나 Spring같은 프레임워크를 사용하는 경우 메모리를 고려하여 설계해야 한다. OOME 케이스 java.lang.OutOfMemoryError: Java Heap Space..
-
[Java] Spring 빌드 Jar, WarProgramming/Java 2024. 2. 29. 00:26
Spring 프레임워크를 빌드하면 나오는 실행 파일 포맷은 Jar, War 두가지이다. Gradle, Maven 같은 빌드 도구를 사용하여 빌드하면 하나의 산출물인 Jar, War파일이 생성된다. Jar파일은 JVM위에서 실행되지만, War파일은 WAS위에서 실행된다. Jar -> SpringBoot를 사용하는 경우 War -> JSP만으로 이루어져 있거나, 외부 WAS를 사용할 경우 사용하거나 필요에 맞게 배포(패키지)포맷을 정하면 된다. ● 외장 WAS를 사용하는 환경이라면 war배포 ● 내장 WAS를 써야하는 환경이라면 jar배포 ● jar와 달리 war는 WEB-INF 및 META-INF 디렉토리로 사전 정의된 구조를 사용하며, WAR파일을 실행하려면 Tomcat, Weblogic, Websphe..
-
[Java] Garbage CollectionProgramming/Java 2024. 2. 28. 01:36
GC JVM내에서 메모리 관리를 해주는 것. 쓰지 않는 객체(힙 메모리 객체가 null)인 경우 가비지 컬렉터의 대상이 된다. 사용자가 동적으로 생성한 객체가 있는 영역인 Heap메모리에서 동작한다. C++에서는 Heap영역의 메모리를 사용하기 위해 동적 메모리 영역을 할당 받고 해제하는 과정을 개발자가 직접 해야한다(메모리를 수동으로 직접 관리) → 메모리 영역을 할당 받고 해제하지 않으면 메모리 누수가 발생할 수 있고, 이미 해제한 메모리 영역을 또 해제하면 에러가 발생할 수 있다. → Java에서는 동적 메모리 영역(힙 메모리)를 GC가 관리하여 에러 발생 요인을 방지할 수 있다. GC를 수행하게 되면 GC를 수행하는 스레드를 제외한 모든 스레드가 중지된다. → 이것을 stop-the-world라고..
-
[Java] String 클래스Programming/Java 2024. 2. 6. 19:28
String public final class String extends Object implements Serializable, Comparable, CharSequence String 클래스는 final로 선언되어 있다. String 클래스는 자식 클래스를 양산할 수 없다. 모든 클래스의 부모 클래스인 Object클래스를 확장했다. - Serializable 인터페이스 : 구현해야 하는 메소드가 하나도 없는 특이한 인터페이스 - Comparable 인터페이스 : compareTo()메소드 하나만 선언되어 있다. - CharSequence 인터페이스 : 문자열을 다루기 위한 클래스 - StringBuilder, StringBuffer 클래스도 CharSequence인터페이스를 구현해 놓았다. 불변한 객..
-
[SpringBoot] Lombok 롬복Programming/SpringBoot 2023. 12. 7. 16:07
Lombok이란 코드를 간소화해 주는 라이브러리입니다. 자바의 라이브러리로 반복되는 메소드를 Annotation을 사용해서 자동으로 작성해주는 라이브러리입니다. Lombok을 이용해서 작성한 코드는 컴파일 과정에서 Annotataion을 이용해서 코드를 생성하고 .class에 자동 컴파일 됩니다. Lombok 설치 프로젝트 탐색기에서 firstproject > src >build.gradle 파일에서 설정 코드를 작성합니다. dependencies { compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' } 편집기에 코끼리 모양의 새로고침 아이콘을 클릭합니다. 롬복 라이브러리가 다운로드 되는지 확인합니다...
-
[SpringBoot] JPAProgramming/SpringBoot 2023. 12. 7. 15:12
JPA Java Persisitence API는 자바 진영의 ORM기술 표준입니다. - ORM (Object Relational Mapping) : 객체와 테이블을 매핑해서 패러다임의 불일치를 개발자 대신 해결 DB에 데이터를 기록해야 할때, 자바 언어로 저장할 수 없습니다. DB는 SQL언어를 사용하기 때문입니다. JPA는 자바 언어로 DB에 명령을 내리는 도구입니다. 데이터를 객체 지향적으로 관리할 수 있게 해줍니다. JPA의 핵심 도구로는 엔티티와 리파지터리가 있습니다. Entity 자바 객체를 DB가 이해할 수 있게 만든 것으로, 이를 기반으로 테이블이 만들어집니다. Repository 엔티티가 DB속 테이블에 저장 및 관리될 수 있게 하는 인터페이스 1. DTO를 엔티티로 변환하기 2. 리파지터..
-
[SpringBoot] MVC패턴 + REST API + JPA 프로젝트 설계Programming/SpringBoot 2023. 12. 7. 14:09
MVC + JPA 프로젝트 설계 Form을 사용한 웹 설계는 아래와 같습니다. REST API를 사용하지 않는다면 응답을 뷰 템플릿으로 하게 됩니다. MVC + REST API + JPA 프로젝트 설계 REST API를 사용하면 요청과 응답 데이터가 대표적으로 JSON을 사용하여 통신하게 됩니다. 클라이언트와 서버 간 처리 흐름은 크게 4가지로 나눌 수 있습니다. - MVC (Model-View-Controller) : 서버 역할을 분담해 처리하는 기법 - JPA (Java Persisitence API) : 서버와 DB간 소통에 관여하는 기술 - SQL (Structured Query Language) : DB데이터를 관리하는 언어 - HTTP (HpyterText Transfer Protocol) :..