요청
요구사항 분석
설계
구현
유스케이스
시퀀스 다이어그램
예외 처리 문법(try ~ catch)
try { }
catch (Exception e) { }
try { }
catch (Excetion e) { }
finally { // try와 catch의 영향 없이 무조건 실행, 대부분 자원 반납을 명령함 }
throws 예외를 발생시킨 쪽으로 예외를 던져버리는 형식
throw 고의로 예외를 발생시키겠다
void 메소드명 throws Exception {
throw.Exception
}
ArrayIndexOutOfBoundsException
NullPointerException 존재하지 않는 객체를 가리킬 때 발생
객체 자료 -> 기초 자료 : 래퍼클래스
기초 -> 객체 : valueOf()
DB관련 Exception.
ClassNotFoundException : 드라이브 이름을 찾지 못했을 떼
SQLException : db url, id, pw가 올바르지 않을 때
추상 메소드 - 강제로 재정의할 때 사용
interface
- 다형성 : 객체가 다양하게 변하는 것
- 다중 구현 가능
public interface 인터페이스 {
public 상수
public 추상 메소드
}
차이점
추상메소드 - 상속을 통한 사용
인터페이스 - 구현을 통한 사용
추상메소드 - 일반 클래스와 동일
인터페이스 - 상수와 추상메소드만 가능
추상메소드 - 단일 상속
인터페이스 - 다중 구현
package InterfaceEx;
public abstract class LunchMenu {
public int rice;
public int bulgogi;
public int banana;
public int milk;
public int amond;
public LunchMenu(int rice, int bulgogi, int banana, int milk, int amond) {
super();
this.rice = rice;
this.bulgogi = bulgogi;
this.banana = banana;
this.milk = milk;
this.amond = amond;
}
public abstract int calculating();
}
package InterfaceEx;
public class PriceTable {
public static final int RICE = 1000;
public static final int BULGOGI = 2000;
public static final int BANANA = 700;
public static final int MILK = 200;
public static final int AMOND = 100;
}
package InterfaceEx;
public class Child1 extends LunchMenu {
public Child1(int rice, int bulgogi, int banana, int milk, int amond) {
super(rice, bulgogi, banana, milk, amond);
// TODO Auto-generated constructor stub
}
@Override
public int calculating() {
// TODO Auto-generated method stub
return rice + bulgogi + banana;
}
}
package InterfaceEx;
public class Child3 extends LunchMenu {
public Child3(int rice, int bulgogi, int banana, int milk, int amond) {
super(rice, bulgogi, banana, milk, amond);
// TODO Auto-generated constructor stub
}
@Override
public int calculating() {
// TODO Auto-generated method stub
return rice + bulgogi + milk + amond;
}
}
package InterfaceEx;
public class LunchMain {
public static void main(String[] args) {
LunchMenu child1 = new Child1(PriceTable.RICE, PriceTable.BULGOGI, PriceTable.BANANA, PriceTable.MILK, PriceTable.AMOND);
LunchMenu child3 = new Child3(PriceTable.RICE, PriceTable.BULGOGI, PriceTable.BANANA, PriceTable.MILK, PriceTable.AMOND);
System.out.println("child1 아이의 식대 : " + child1.calculating());
System.out.println("child3 아이의 식대 : " + child3.calculating());
}
}'BackEnd > Backend 공부 정리' 카테고리의 다른 글
| Java-15 (0) | 2024.08.27 |
|---|---|
| sqldeveloper-14 (0) | 2024.08.26 |
| sqldeveloper-13 (0) | 2024.08.23 |
| Java-13 (0) | 2024.08.23 |
| sqldeveloper-12 (0) | 2024.08.22 |