본문 바로가기

아는 만큼 보인다/Tip

enum 자료형 흉내내기 아래와 같은 enum 자료형이 있다 두 개의 enum 상수가 있다. 멤버 변수 symbol 을 하나 갖고, 추상 메소드도 하나 선언되어있다 enum MyEnum {PLUS("+") {double apply(double x, double y){return x+y;}},MINUS("-") {double apply(double x, double y){return x-y;}};private final String symbol; // 불변MyEnum(String symbol){this.symbol = symbol;}// 추상 메소드abstract double apply(double x, double y);} 위 enum 자료형을 일반 클래스로 흉내내 보자 열거형의 각 상수는 public static final 로.. 더보기
Java HotSpot VM Options 몇 가지 아래 설명된 option들은 jdk7과 그 이전 releases에 적용되는 option임 (jdk8부터는 다를 수 있음) -XX Options 표기법 Boolean options -XX:+ means to turn on -XX:- means to turn off Numeric options -XX:= String options -XX:= -XX Options (비표준 Options) Behavioral options -XX:+UseConcMarkSweepGC Old generation (Heap area)을 GC할 때 concurrent mark-sweep 방식으로 하도록 설정한다. Garbage First(G1) Garbage Collection options Performance tuning opti.. 더보기
Java 메모리 누수(memory leak) obsolete reference(쓸모 없어진 참조), unintentional object retention(의도하지 않은 객체 보유) 더 이상 쓰일 일 없는 객체를 garbage collection 하지 못하는 오류 코드 예제 class MyStack { private static final int MAX_SIZE = 16; private final E[] elements; private int position = 0; public MyStack() { elements = (E[]) new Object[MAX_SIZE]; } public void push(E e) { if(position == MAX_SIZE) throw new IllegalStateException("Full Stack"); ele.. 더보기
Java Memory Model 영역 대상 Method area (GC의 permanent generation) 메소드의 바이트코드 클래스(static) 변수 constant pool Heap area (GC의 young generation, old generation) instance 변수 (string constant포 함) Stack area local 변수 더보기
문자열 속 일부 유니코드 치환 // 문자열 속 일부 유니코드 치환public void replaceUnicodeNotation(String input) {while( true ) {Matcher m = Pattern.compile("\\\\u([\\da-fA-F]{4})").matcher(input);if(!m.find()) break; char ch = (char) Integer.parseInt(m.group(1), 16);String a = String.valueOf( ch );input = m.replaceFirst( Matcher.quoteReplacement(a) );}return input;} 더보기
eclipse에서 java compiler 변경시.. 에러 eclipse에서 java compiler 변경 후에도.. 이전 컴파일러로 빌드하려고 한다면.. 아래 폴더를 지움 \.metadata\.plugins\org.eclipse.debug.core\.launches 더보기