Archive for December, 2009

Java-7강

this()

같은 클래스 내에 생성자를 호출
생성자가 생성자로 redirect
  • this()는 생성자 내에서 첫 줄에 와야한다. 어떤 문장도 this() 앞에 와서는 안된다. (예외는 주석)
  • 일반 method에서는 호출할 수 없다.

성적관리프로그램

클래스를 파일로 나누기
  1. Student
  2. Input
  3. Output
  4. Main
  5. Calc
  6. Sort
Java.io.File
Constructor summary에

File(String pathname)

- Java에서 String parsing 방법 3가지
  1. String class 의 split()를 이용하자
  2. java.util.String Tokenizer class를 이용하자
  3. java.util.Scanner class를 이용하자
1. split()
split은 기준(콤마, 스페이스 등등..)으로 나눈다.
기준은 정규식을 사용한다.
space = “\\s”
“\\s+” +가 붙은 것은 스페이스 한칸 이상을 뜻
변수는 가급적 private 메소드는 필요에 따라 private

소멸자

java.lang.Object

finalize


Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.


상속


Blog

1997년 ~ 2002년 이전의 정보처리기사 기출문제
중 택 1
Java로 프로그래밍
http://archchez.tistory.com/728

Java-6강

What’ a Class?

What’s an Object?

an object is an instance of a class

OOP Key Features

  • Abstraction (추상화) 7장
  • Encapsulation (캡슐화) 7장
  • Inheritance (상속) 8장
  • Polymorphism (다형성) 9장

Abstraction

개념적 -> 논리적 -> 물리적 모델링
abstraction is selective ignorance

Decide what is important and what is not

loosely coupled – 느슨하게 연결된


Encapsulation

abstraction을 코드화

the principle of protecting sensitive parts of your objects from external manipulation

Hides the implementation details of a class

members can be public or private

클래스 속 변수는 private – Java Bean에 규칙에 똑같이 적용됨.

example)
UML Diagram
클래스명
-변수
+메소드
- : private
+ : public

Restricting Data Access

Use modifiers to restrict data access:
- public
Everyone can use that part of the object
- private
No one outside the object’s class can use that part of the object

Implementing Encapsulation

Methods are public, accessible from the outside
Data is private, accessible only from the inside

get Methods and set Methods

The this Reference

The this keyword means “reference” to the same object
  1. this. – 나의
  2. this – 나 자체
  3. this() -
나는 this 부모는 super
1. this.
명시적으로 구분할 때 this. 를 사용
멤버변수와 지역변수를 구분할 때
2. this
나 전체를 return할 때

Creating Objects

step1 : Allocating memory
step2 : Initializing the object by using a constructor

Explicit Member Initialization

명시적 초기화
int num = 5;

Constructors

  • are special methods.
  • have no return type
  • have the same name as the class name
  • are called each time you create an object
  • you have been using a default constructor throughout most of the course
  • default constructor

Default Constructors

all classes must have at least one constructor
the compiler provides a default constructor to any class which does not have an explicit constructor
feature
  • public accessibility
  • same name as the class
If a class has no constructor, a default constructor is inserted.

Overriding the Default Constructor (기본생성자의 재정의)

The default constructor might be inappropriate

내일은 7장 마무리
this()
생성자에 대한 이야기
student class 나눠서 파일처리
sorting까지.

Project

documentation 70% / 개인코딩 10% / 디버깅 20%

도서추천

UMl도서


Java-5강

Methods

- call by name

- call by value

2개 이상을 return 할 수 없음
2개 이상을 넘기고 싶으면 배열을 이용
value copy
- call by reference
  • 배열
  • reference type
을 이용

- variable argument

runtime 때 size가 결정되는 배열을 사용
  • static void method(int … array)
배열의 기호는 쓰지 못하면서 배열의 기능
argument가 가변적(variable)이다.
갯수와 타입을 신경안써도 된다.

method 호출 방법 4가지

call by name, call by value, call by reference, variable argument
[modifiers] return_type method_name([parameter]){
method_body
}
String은 parameter로 쓰면 call by value
static void methodParameters(int n, String y){…}

return

return 아래 쪽에 어떤 문장도 허용하지 않는다.


Hello World 찍는 8가지 방법
local variable 접근하 듯
주소를 통한 접근
클래스 이름으로 접근
주소로 접근하면 멤버변수
주소 없이 접근하면 스태틱

recursive call

method overloading

method 중복정의
overriding과는 차이 – method 재정의
이름이 같고 매개변수는 다르고
주소없이 코딩하기 위해 main은 static 이여야 한다.
new없이 쓸꺼냐 new있이 쓸꺼냐..

Object-Orientation

eclipse 사용
UML
starUML을 이용해서 block diagram 생성, 기호

추천도서