Programming/Java

Programming/Java

Java 한글 인코딩

Naver 한글인코딩에 대한 이해 한글 인코딩의 역사와 유니코드 : http://d2.naver.com/helloworld/19187 유니코드와 Java를 이용한 한글 처리 : http://d2.naver.com/helloworld/76650 JAVA - 한글 인코딩 변환 체크 한방에 끝내기 public static void FindEncoding(String s) { try { String word = s; System.out.println("utf-8(1) : " + new String(word.getBytes("utf-8"), "euc-kr")); System.out.println("utf-8(2) : " + new String(word.getBytes("utf-8"), "ksc5601")); Sy..

Programming/Java

Thread-safe Queue

멀티 스레드 환경에서 Queue는 생산 및 소비의 구조에 필수적인 자료구조이다. 여기서 우리는 BlockingQueue라는 interface를 구현한 객체를 가져다 쓸 수 있다. Block 이라는 것은 먼저 무엇일까? '막는다'는 뜻이다. 그럼 무엇을 막는 다는 것인가? 그것은 바로! Queue가 꽉찼을때의 삽입 시도 / Queue가 비어있을때의 추출 시도 를 막는 다는 것이다. 이 자동으로 '막는' 기능이 있어 BlockingQueue 의 구현체는 모두 Thread-safe 하다. 그럼 이제부터 본격적인 BlockingQueue에 대한 포스팅을 시작한다. 1. ArrayBlockingQueue - 고정배열에 일반적인 Queue를 구현한 클래스, 생성 후 크기변경 불가 - 꽉찼을때 추가 block, 비었..

Programming/Java

Difference Between newSingleThreadExecutor and newFixedThreadPool

Difference Between newSingleThreadExecutor and newFixedThreadPool(1) Similirity newSingleThreadExecutor returns ExecutorService with single thread worker and newFixedThreadPool(1) also returns ExecutorService with single thread worker. In both case if thread terminates, new thread will be created. Difference ExecutorService returned by newSingleThreadExecutor can never increase its thread pool s..

Programming/Java

List 객체의 final 한정자가 갖는 의미

Java의 final List 객체의 의미는?? final 은 본래 객체의 접근을 변경을 방지하는 한정자로 사용된다. 하지만, List 객체에 있어서는 최초 객체를 생성한 후에 필요에 따라 add, remove 등의 객체 element 변경이 가능하다.. 그럼, List 객체에 있어서 final이 갖는 의미는 무엇인가?? 한번 객체화 시킨 변수에 대해서 다른 참조자를 갖도록 할 수 없다. 즉, reference type의 객체로 한번 지정한 참조에 대한 변경을 허용하지 않는 것이다! 그럼 내부의 element에 대한 변경을 하지 않는 객체를 얻기 위해서는 어떻게 할 수 있을까? 아래 예제의 Nameserver2 를 보면, 기존의 Nameserver 객체를 Collection.unmodifiableList..

Programming/Java

Enum 사용 팁?

public enum MessageType { Error(0), SPR(65537), SSR(65538), State(2), CmdAnswer(4), Command(5), CompoundIOConfig(102), CompoundIOValues(111), Event(21), List(13), ReturnState(14), Update(30), Stop(31), KeepAlive(1212752128), Register(1380271872), CompoundRequest(120), CompoundReply(121), CompoundEvent(122), Unknown(-1); private int _id; private static MessageType[] _types = values(); private Mes..

Programming/Java

Java Copy by reference & deep clone with reflection

자바의 Copy by Reference 개념을 이해하기 위해서 만든 코드임. 또한, 깊은 복사를 이용한 결과 값을 보이는 예제도 함께 구현함. MyObject의 deep clone 구현에서는 wildcard type을 적용함. MyOject 를 상속한 MyObjectExt에 적용될 수 있는 사항도 포함하고 있음. deep clone의 경우에는 MyObject를 상속한 모든 클래스에 대해서 deep clone을 수행할 수 있도록 한다. deep clone시에는 MyObject의 필드 정보에 대해서만 clone을 수행하지만, reflection 정보를 확장해서 더욱 기능을 높일 수 있다. package application; import java.lang.reflect.Constructor; import j..

Programming/Java

Daemon Thread

Application 이 종료될 때 JVM에 의해서 종료되는 Thread를 말한다. 보통 사용용도는 resource manager 또는 service 를 수행하는 중요도가 낮은 역할의 실행을 무한으로 돌릴때 사용한다. 가장 대표적인 예가 garbage collector 이다. Java has a special kind of thread called daemon thread. Only executes when no other thread of the same program is running. JVM ends the program finishing these threads, when daemon threads are the only threads running in a program. Daemon thre..

Programming/Java

JAVA Default Charset 변경

Java의 String 변환 ( 인코딩, 디코딩 )을 수행할 때에 문자열을 default charset을 기반으로 수행하게 된다. default charset 이 컴퓨터 시스템에 종속되어 있다고 생각했으나, 그게 아니라 파일의 인코딩 정보를 이용해서 한다는 점이다. 기본 Charset을 쉽게 변경하는 방법은 이클립스의 Edit -> Set Encoding에서 Other를 클릭하면 선택할 수 있는 인코딩 옵션들을 확인할 수 있다. 원하는 방식의 인코딩으로 변경할 수 있다.

RichardBang
'Programming/Java' 카테고리의 글 목록