Archive for the ‘ bitacademy ’ Category

Java-10강

2010년 1월 6일 10강

Abstract Methods

오버라이드의 강제화
객체생성 불가능
자식객체를 이용해야함.

Interface

  • 다중상속을 목적으로
  • 인터페이스는 클래스가 아니다.
  • 인스턴스화 할 수 없다.
  • 변수를 가질 수 없다.
  • 메소드 가질 수 없다.
  • 상수 & 추상메소드 만 가능하다.
Java는 다중상속을 위해서 Interface라는 개념을 사용
객체 복제.

clone()

객체의 값복사, cloneable 인터페이스가 필요
try catch 써야함, 예외잡기.
정상적인 객체는 복제 안됨
cloneable 자식들만 복제가능함

java.lang

method
clone()
interface
cloneable
재정의할 메소드 없음.
cloneable interface가 붙은 자식들만이 값복제 가능
mark(flag) interface
재정의할 메소드 없음, 상수 없음
기능없음.
shallow copy(값 복사) <-> deep copy(주소복사)

CLASSPATH 를 잡는 이유

컴파일할 때 컴퍼넌트가 어디에 있는지를 잡아줘야한다
파일의 위치가 만약
C:\temp
Component.java
Component.class
D:\jongsun
Main.java
Main.class
있다면
- complie option
>javac -classpath C:\temp Component.java
- runtiime option
>java -classpath .;C:\temp Main
운영체제 환경변수에 “CLASSPATH”를 세팅하면 컴파일, 실행시 옵션 지정 안해도 됨.
경로가 바뀔 경우에는 옵션지정.

Package와 import

- package
유사한 클래스들의 묶음
디렉토리
해당 디렉토리에 package…
package com.javasoft.lib.HR; 라는 package를 선언했다면
complie option
javac -d C:\temp Insa.java
c:\temp 아래 com->javasoft->lib->HR
- import
FQN(Fully Qualified Name) 방식
Java home path로 부터
- jar 만들기
C:\temp> jar -cvf example.jar /com
example.jar 복사
C:\Program Files\Java\jre6\lib\ext
classpath 관련 글들..
- static import
syntax:
import static TypeName.*;

Advanced Access Control

modifier same class same package subclass universe
public y y y y
protected y y y
default y y
private y
public – 클래스, 변수, 메소드
protected – 변수, 메소드
default – 클래스, 메소드, 변수
private – 변수, 메소드
내일은..
static
inner class

Java-9강

2009년 1월 5일 9강

9장 Polymorphism

객체지향의 완성은 “다형성”

  • Is a powerful feature of OO
  • Means “many forms”
  • Is the ability to have many different forms
Can be used in two ways:
  • polymorphic parameters
  • heterogeneous collections
instanceof
부모, 자식 형변환 가능한지 여부를 확인 true, false 를 리턴.
오리지날 타입을 알기 위해 사용.
- 다형성의 문제
자식은 부모형으로 형변환 될 수 있다라는 점이 문제.
그래서 나온 것이 Generic (15장에서 배움)

Overriding Methods

Virtual method invocation:
Employee e = new Manager();
e.getDetails();
Complie-time type and runtime type
선언형이나 실제형이냐..
- Rules about Overriden Methods
cannot be less accessible than the method it overrides.

10장

Abstract Method

자식클래스에서 무조건 재정의 해야함.
오버라이드의 강제화를 위해..

Abstract Class

추상 메서드를 갖고 있다면 무조건 추상 클래스로 된다.
정상적인 클래스도 abstract를 쓸 수 있다. 이유는 new를 통한 인스턴스생성을 못하게 하려고..
  • member variable
  • static variable
  • member method
  • static method
  • abstract method
위에 5가지로 추상 클래스를 만들 수 있다.

Interface
  • an interface is variation on the idea of an abstract class.
  • In an interface, all the methods are abstract.
  • In an interface, all variables are constant.
추상클래스 계열
클래스는 아님.
부모가 여러 개여도 됨(다중상속)
  • abstract method
  • constant
인터페이스는 위의 2개로 구성
인터페이스 속에는 모두 static, final이므로 생략가능한다.
자식 부모
class extends class
interface extends interface
class implements interface
interface
  • 다중상속
  • Mark(flag) interface – 멤버가 하나도 없는 인터페이스, UML은 동그라미표시
내일은
mark interface
객체의 주소, 값 복제
내부클래스
빨리끝나면 GUI
그래픽 인터페이스 이벤트 모델

Java + .NET -> actionScript
JDBC -> .NET의 ADO.NET
JSP -> ASP.NET

Java-8강

2010년 1월 4일 Java 8강

8장

What is a Inheritance?

Inheritance specifies an “is a kind of” relationship

  • Inheritance is a class relationship
  • New classes specialize existing classes
자식이 부모가 갖고있는 기능을 확장.
기존에 존재하는 클래스를 구체화.

Single and Multiple Inheritance

  • Single inheritance: extending from one super class (Java, .NET)
  • Multiple inheritance: extending from two or more super class (C++..)

상속은 복사의 개념이 아닌 공유의 개념.

  1. 부모-자식
  2. 전체-부품
  3. has-a (대등관계)
자식 부모
C++ Derived : (상속유형(지정자))Base Class
Java Subclass extends Super Class
C# Derived : Base Class

Inheritance

Inheritance is the OO term referring to grouping classes together based on common theme or common attributes.
Use the keyword extends
다중상속은 interface를 사용한다.
1.생성자는 상속되지 않는다.
부모의 생성자를 호출하려면 super 메소드를 사용
2.private은 상속되지 않는다.
3.static은 상속과 관련이 없다.
4.overshadow 변수는 상속되지 않는다.
5.오버라이드 메소드는 상속되지 않는다.
Java는 대부분의 메소드의 재정의를 허용한다.

상속이 안되는 4가지

  1. private
  2. static
  3. constructor => super()
  4. overshadow / override method => super.

The “is a” Relationship – 상속관계

A class can inherit from only one superclass at a time.
“is a” 가 말이되면 상속관계.
is a 대신 extends

The “has a” Relationship – 포함관계

Containment
Write a class that contain a reference to other classes.

this()와 super()는 같이 쓸 수 없다.
둘 다 맨 첫줄에 써야하므로..
super나 this는 static에서 사용할 수 없다.
static이 아닌 곳에서만 사용

9장

Polymorphism(다형성)

  1. 객체 형변환
  2. override method
비교 연산자

instanceof
부모, 자식 형변환 가능한지 여부를 확인 true, false 를 리턴

Design Pattern + UML
임백준