사랑해 마니마니

Java 그냥 끄적 끄적 본문

카테고리 없음

Java 그냥 끄적 끄적

분리불안증후군 2015. 9. 22. 13:03

Primitive Type


Reference Type: class, interface, array, enum


final 변수


% 몫 연산자


+= 복합 연산자

<textarea name="code" class="brush:cpp;">

int arr[] = new int[10];


int arr[] = { 1, 2, 3 };


arr.length


for (int num : arr ) {

   foo()

}


try {

} catch ( ) {

} finally {

}

</textarea>

&& ||


== !=


condition ? true : false ;



int withdraw(int amount) throws Exception {

   throw new Exception("....");\

}


method signature


this


this(  ): 생성자 호출


static


final static FINAL_STATIC_VARIABLE


ClassName.finalStaticVariable


extends


super( ... ): Super class 생성자 호출


method overriding


final class: 상속 금지

final method: overriding 금지


abstract: 인스턴스화 금지

           

abstract method: method implementation을 할수 없다. class도 abstract로 처리해야 함

                   - 생각해봐 method를 implementation하지 않은 불완전한 놈이 객체 생성을 할 수 있겠니?

> 서브 클래스에서 이 메소드를 반드시 구현하도록 하기 위해서

> Runtime에 서브 클래의 메소드를 호출하기 위해서


interface


interface내 static field: 클래스 내에서 사용하는 상수

 단 초기화 필요


interface foo{

   final static byte STATE_BORROWED = 1;

}


implements


Type case


instance of


obj instanceof typeName


class Boo{

  enum Season {

      SPRING, SUMMER, FALL

  }

  Season.SPRING; 클래스 내부

}


Boo.Season.SPRING; 클래스 외부


Season seasons[] = Season.values();

for (Season season : seasons ){

  System.out.println(season)

}


Season season = Season.valueOf("SPRING");


enum Season {

  SPRING("봄"), SUMMER("여름"), FALL("가을");

  final private String name;

  Season(Strig name) {

   this.name = name;

  }

  String value() {

    return name;

  }

}


Season.SPRING -> season.value();













Comments