donaricano-btn

 Instanceof

- instanceof operator is used to test whether the object is an instance of the specified type

- It is also known as type comparison operator

It returns either true or false


1. Example


- true

2. instanceof in java with a variable that have null value

 

- false

3. Downcasting with java instanceof operator

1) Downcasting

When subclass type refers to the object of Parent class, it is known as downcasting

 

 

2) Possibility of downcasting with instanceof

 

3) Downcasting without the use of instanceof

 

'Back-End > Java_1' 카테고리의 다른 글

[Java] Interface  (0) 2016.09.12
[Java] Abstract class  (0) 2016.09.12
[Java] Static Binding and Dynamic Binding  (0) 2016.09.08
[Java] Runtime Polymorphism  (0) 2016.09.08
[Java] Final keyword  (0) 2016.09.07
블로그 이미지

리딩리드

,
donaricano-btn

하이버네이트 + 스프링(2)


1. ServiceImpl


- 스프링 인티그레이션 기능으로 비즈니스 로직의 세션 관련 오브젝트가 삭제되었다

2. DaoImpl

 

- 하이버네이트의 세션 오브젝트가 제공하는 CRUD는 HibernateTemplate 클래스를 통해 이용한다

3. 하이버네이트 3.0.1 이후 버전

- 3 이후 버전에서는 HibernateTemplate을 사용하지 않고 구현 가능

1) getCurrentSession

- SessionFactory의 getCurrentSession()를 실행하면 현재 사용중인 Session 오브젝트를 가져올수있다(트랜잭션 매니저로 관리되는 세션 오브젝트를 가져올 수 있다)

2) HibernateTemplate을 사용하지 않고 구현

 

a. SessionFactory 직접 사용의 장점

- 하이버네이트에서 제공하는 모든 API를 사용가능

- 하이버네이트에 익숙한 개발자라면 API만 의식하면 되므로 효율적 개발가능

b. 단점

- 직접 세션 오브젝트를 사용하므로 위험할 수 있다

- HibernateTemplate은 안전하지만 버전 4에서 지원 안함


FullSource - https://github.com/KyleJeong/Hibernate/tree/master/hiberSpring


블로그 이미지

리딩리드

,
donaricano-btn

하이버네이트 + 스프링(1)

- 하이버네이트와 스프링을 같이 사용함으로 독립성 높인 간단한 코드가 된다


1. 폴더 구성

2. 정의 파일


1) 데이터 베이스를 정의한다

2) 하이버네이트의 세션 오브젝트를 작성하고 SessionFactory 클래스를 정의한다

3) 스프링이 제공하는 HibernateTemplate 클래스를 정의한다

- 하이버네이트를 더 단순하게 사용할 수 있고 범용 데이터 엑세스 예외로 변환 해준다

- HibernateTemplate 내부는 SessionFactory를 사용, 그러므로 2에서 정의한 프로퍼티를 받는다

4,5) 하이버네이트 트랜잭션 설정

- 하이버네이트 트랜잭션 매니저로 HibernateTransactionManager를 사용한다

- 위 예제는 선언적 트랜잭션으로 Service로 이름이 끝나거나 find, add, remove 모두 대상이됨

FullSource - https://github.com/KyleJeong/Hibernate/tree/master/hiberSpring
블로그 이미지

리딩리드

,
donaricano-btn

Static Binding and Dynamic Binding


1. Binding

- Connecting a method call to the method body is known ad binding


1) static binding(early binding)

2) dynamic binding(late binding)


2. Static binding

- When type of the object is determined at compiled time, is is known as static binding

- If there is any private, final or static method in class, there is static binding



3. Dynamic binding

- When type of the object is determined at run-time, it is known as dynamic binding

 

- Object type can't be determinded by the compiler, because the instance of Dog is also an instance of Animal, so Compiler doesn't know its type


'Back-End > Java_1' 카테고리의 다른 글

[Java] Abstract class  (0) 2016.09.12
[Java] Instanceof  (0) 2016.09.09
[Java] Runtime Polymorphism  (0) 2016.09.08
[Java] Final keyword  (0) 2016.09.07
[Java] Instance initializer block  (0) 2016.09.07
블로그 이미지

리딩리드

,