1. 예외
잘못된 조작 및 코딩이 발생할 때 예외 처리 (Error와 다름)
IOException | 입력 및 출력 작업 실패, 인터럽트 시 발생 |
FileNotFoundException | 파일이 없을 때 |
ParseException | 문자열 파싱 오류 |
ClassNotFoundException | 클래스를 못찾을 때 |
SQLException | 데이터베이스 접근 오류 |
MalformedURLException | 잘못된 URL일때 |
InterruptedException | 쓰레드가 작업 중 인터럽트될 때 |
NoSuchMethodException | 메소드를 못찾을 때 |
NoSuchFieldException | 필드를 못찾을 때 |
package com.chap09;
import java.net.MalformedURLException;
import java.net.URL;
public class MalformedURLExceptionExample {
public static void main(String[] args) {
try {
URL url = new URL("htp://www.example.com");
System.out.println("프로토콜: " + url.getProtocol());
} catch (MalformedURLException e){
System.out.println("잘못된 URL 형식입니다: " + e.getMessage());
}
}
}
package com.chap09;
public class NullPointerExceptionExample {
public static int getStringLength(String a){
int length = 0;
try {
length = a.length();
} catch (NullPointerException e){
System.out.println("NullPointer 발생! : " + e.getMessage());
}
return length;
}
public static void main(String[] args) {
getStringLength(null);
}
}
2. 컬렉션
- List : ArrayList, Vector, LinkedList 가 있으며 순서가 있으며 중복O - add, set, remove, get, size()
- Queue : PriorityQueue, LinkedList로 구현하여 순서가 있으며 중복O, 데이터 접근 시 순차적으로 접근 - add, element, peek, poll, remove, clear
- Map : HashMap이 있으며, key, value값의 쌍으로 저장하는 자료구조, 키는 중복X, 값은 중복O - put, get, remove, size, containsKeyValue
- Set : HashSet이 있으며, 순서를 유지하지 않으며 중복X - add, remove, contains, isEmpty()
'KT AIVLE School > JAVA' 카테고리의 다른 글
상속, 추상화, 제네릭 (0) | 2024.11.29 |
---|---|
객체지향 (0) | 2024.11.28 |
자바 시작 ( 자바 변수 및 제어문 ) (0) | 2024.11.26 |