The Java Programming Language 1~3장
<용어 정리>
- 클래스 멤버
- 첫번째 예제
- signature
- declaration
<기본 데이터 타입>
<Named Constant>
<주석>
<제어문 / 반복문>
<연산자>
<클래스 / 객체>
- 객체 변수 / 클래스 변수
- 클래스의 상속
- 접근한정자 -
- 메소드(method)
- 클래스(Class)
- 생성자
<Exception>
<etc>
- 배열
- String 객체
- Package
- 유니코드
자바는 유니코드를 사용하기때문에 변수이름으로 유니코드를 사용할 수 있다.
            
                    
                    
1. 자바의 개요
2. 클래스와 객체
3. 클래스 확장
2. 클래스와 객체
3. 클래스 확장
<용어 정리>
- 클래스(Class)
 - 객체(Object)
 - 인스턴스(Instance)
 
- byte code
 - native code
 
- 클래스 멤버
- 필드 : 클래스/객체에 속하는 데이터 변수 -> C++ : 멤버 변수
 - 메소드 : 필드의 상태를 조작하기 위한 수행문으로 구성됨 -> C++ : 멤버 함수
 
- 첫번째 예제
class Hello world {- header
public static void main( String[] args ) {
System.out.println("Hello, World");
}
}
- signature
- declaration
<기본 데이터 타입>
- boolean : true / false
 - char : 16 bits 유니코드 2.1문자
 - byte : 8 bits 정수
 - short : 16 bits 정수
 - int : 32 bits 정수
 - long : 64 bits 정수
 - float : 32  bits 부동소수점표현
 - double : 64 bits 부동소수점표현
 
<Named Constant>
class Suit {
final static int CLUB = 1;
final static int DIAMONDS = 2;
final static int HEARTS = 3;
final static int SPADES = 4;
}
<주석>
- // : 한줄 주석
 - /* ... */ : 구역 주석
 - /** ... */ : 문서 주석(doc comment) -> javadoc 에서 사용
 
<제어문 / 반복문>
- for
 - while
 - if - else
 - switch
 - do - while
 
<연산자>
- ++ , += , -= , *= , /=
 - & , | , ^
 - || , &&
 
<클래스 / 객체>
- 객체 변수 / 클래스 변수
- instance variable
 
class Point {
public double x, y;
}
Point Left = new Point();
Left.x = 1.0;
- class variable
 
class Point {
public static int cnt;
}
Point Right = new Point();
Point.cnt = 1;
- 메소드의 경우에도 적용됨(스태틱/클래스 메소드)
 
- 클래스의 상속
class Point {
public double x, y;
}
class Pixel extends Point {
Color color;
int col;
public void clear() {
super.clear();
this.col = 0;
color = null;
}
}
- 상속은 extends를 이용해서 한다.
 - 다중상속은 허용하지 않는다.
 - this : 현재 객체 참조
 - super : 상위 클래스참조
 
- 접근한정자 -
- 
public : 모든 클래스에서 접근가능
 - private : 해당 클래스에서만 접근
 - protected : 동일한 패키지, 해당 클래스, 서브클래스에서 접근 가능
 - package : 동일한 패키지, 해당 클래스에서 접근가능(기본값)
 
- static
 - final : 초기화되지 않을 경우 컴파일 X
 - transient
 - volatile
 
- 메소드(method)
- 접근한정자
 - abstract : declaration X
 - static
 - final
 - strictfp(strict floating point) : 정밀하게 부동소수점 연산
 
- call by value 로 수행
 
- main : public static void
 - native : 다른 언어로 만들어진 메소드
 - overloading : 같은이름 / 다른 signature
 - overriding : 동일한 메소드를 서브클래스에서 덮어씀
 
- 클래스(Class)
- public : 하나의 소스파일에 파일이름과 이름이 같은 하나의 public 클래스 존재
 - abstract : 추상 메소드 포함 - 인스턴스 X
 - final : 서브클래스 X
 - strictfp
 
- 생성자
- 예제
 
class A {
A() {
...
}
}
- 초기화블록
 
class A {
{
...
}
}
- static block
 
class A {
static {
...
}
}
<Exception>
- 새로운 예외 정의
 
class BadDataSetException extends Exception { }
- 사용
 
class A {
public int get(int input)
throws BadDataSetException {
...
...
throw new BadDataSetException();
<etc>
- 배열
- 배열의 생성
 
int[] = new int[10];
- String 객체
- Package
- 패키지 이름의 중복을 막기위한 코딩 규약 (~.~.~)
 - 패키지에 소속시키기
 
package net.gnuvill.game;
- 패키지의 사용
 
import java.util.*;
- 유니코드
자바는 유니코드를 사용하기때문에 변수이름으로 유니코드를 사용할 수 있다.
'Developing' 카테고리의 다른 글
| 파이의 정의 (0) | 2007.04.03 | 
|---|---|
| USACO Training - Friday the Thirteenth (0) | 2006.09.12 | 
| PERL에서의 웹 프로그래밍 (0) | 2006.06.03 |