67
2012. 6. 16 2012년 자바카페 OPEN세미나 JavaCafe J J Java D D Developer’s F F Forum community 김흥래 [email protected] 주제 : Introduction to Google Guava

[2012 자바카페 OPEN 세미나] Introduction to google guava

  • Upload
    -

  • View
    8.083

  • Download
    7

Embed Size (px)

DESCRIPTION

2012년 자바카페 OPEN 세미나에서 발표한 내용입니다. Google Guava에 대한 소개입니다.

Citation preview

Page 1: [2012 자바카페 OPEN 세미나] Introduction to google guava

2012. 6. 16

2012년 자바카페 OPEN세미나

JavaCafeJJJJava DDDDeveloper’s FFFForum

community

김흥래[email protected]

주제 : Introduction to Google Guava

Page 2: [2012 자바카페 OPEN 세미나] Introduction to google guava

JavaCafeJJJJava DDDDeveloper’s FFFForum

Community

구아바 ????

Page 3: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 4: [2012 자바카페 OPEN 세미나] Introduction to google guava

소개

� Google Core Library (JavaSE 5.0 +)� 구글 자바 프로젝트에서 기본적으로 사용� Google Guava로 명칭을 통일� Andorid 개발 지원� GWT 개발 지원� Apache license 2.0

Page 5: [2012 자바카페 OPEN 세미나] Introduction to google guava

지겹다. 또 라이브러리야???

식상해…………….

Page 6: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 7: [2012 자바카페 OPEN 세미나] Introduction to google guava

Google Guava

Apache CommonsLang 컴포넌트

Apache CommonsCollections 컴포넌트

유용한 유틸리티

Page 8: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 9: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 10: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 11: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 12: [2012 자바카페 OPEN 세미나] Introduction to google guava

수많은 프로젝트에비슷한 기능은 없을까?

Page 13: [2012 자바카페 OPEN 세미나] Introduction to google guava

비슷한 기능을재사용 할 수는 없을까?

Page 14: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 15: [2012 자바카페 OPEN 세미나] Introduction to google guava

Apache Commons Library

� 프로그램의 공통적인 기능을 재사용하기위한 목적으로 시작

� Google Library와 더불어 전세계적으로 가장 많이 사용되고 있는 Library

� 현재 Commons Library는 40여개의 컴포넌트들로 구성

� 각각의 컴포넌트를 필요에 따라서 선택적으로 사용하는 것이 가능

Page 16: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 17: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 18: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 19: [2012 자바카페 OPEN 세미나] Introduction to google guava

대표적인 코드 저장소인 Google Code(http://code.google.com/)와소스포지(http://sourceforge.net/)에 공개된 약 160,000개의 오픈소스 프로젝트 중Commons 라이브러리가 사용된 프로젝트를 분석하여 시각적으로 표현한 것

Page 20: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 21: [2012 자바카페 OPEN 세미나] Introduction to google guava

JavaSE Standard lang을 위한 유틸리티

Page 22: [2012 자바카페 OPEN 세미나] Introduction to google guava

java.lang.*

Page 23: [2012 자바카페 OPEN 세미나] Introduction to google guava

java.lang.* Packages

� Basic Class� Object, Process, Runtime, System, Thread,

Class, ClassLoader

� Wrapping Class� Boolean, Byte, Character, Double, Float,

Integer, Long

� String Class� String, StringBuffer, StringBuilder

Page 24: [2012 자바카페 OPEN 세미나] Introduction to google guava

특징

� Base Function� ObjectUtils, ClassUtils, ArrayUtils, BooleanUtils

� 문자열 조작� StringUtils, StringEscapeUtils, RandomStringUtils,

Tokenizer, WordUtils� Character 핸들링

� CharSetUtils, CharSet, CharRange, CharUtils� JVM Interaction

� SystemUtils, CharEncoding� Serialization

� SerializationUtils, SerializationException

Page 25: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 26: [2012 자바카페 OPEN 세미나] Introduction to google guava

JavaSE Standard Collection을 위한 유틸리티

Page 27: [2012 자바카페 OPEN 세미나] Introduction to google guava

java.util.*

Page 28: [2012 자바카페 OPEN 세미나] Introduction to google guava

java.util.* Packages

� Collections Class� ArrayList, Array, HashMap, HashSet,

LinkedList, Vector, Stack

� Utility Class� Timer, Random, Properties, Locale, Date,

Calendar

Page 29: [2012 자바카페 OPEN 세미나] Introduction to google guava

특징

� Collection 유틸리티� Ordered Maps� Bidirectional Maps� Queues� Buffers� Bags

Page 30: [2012 자바카페 OPEN 세미나] Introduction to google guava

Apache Commons짱 좋아요!

그냥 이거 쓰면 안되나요?

Page 31: [2012 자바카페 OPEN 세미나] Introduction to google guava

Lang 컴포넌트 Collection 컴포넌트

JavaSE 5 (-) 지원 JavaSE 5 (-) 지원

JavaSE 5 (+) 지원 JavaSE 5 (+) 미지원

각각 다른 패키지로 제공됨 현재 개발 중단됨

Page 32: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 33: [2012 자바카페 OPEN 세미나] Introduction to google guava

Java 5 특징

� Generics 개념 도입� Enum 타입 추가� 언어차원의 Annotation 지원� 파라미터 가변인자 (Varargs : Variable

Argument List)

Page 34: [2012 자바카페 OPEN 세미나] Introduction to google guava

출처 http://en.wikipedia.org/wiki/Java_version_history

2004 ??????

Page 35: [2012 자바카페 OPEN 세미나] Introduction to google guava

Release Note

� Last Published� 2011년 11월 09일 (Version:3.1)

� javaSE 5.0 기준으로 재개발하여 배포� Commons Lang 2.x

� JDK 1.2 ~ JDK 1.4 까지 지원� org.apache.commons.lang.*

� Commons Lang 3.x � JDK 1.5 이상 지원� org.apache.commons.lang3.*

� 개발시 사용하는 JDK 기준으로 선택적으로 사용� 필요에 의하여 혼용하여 사용 가능 (권장하지 않음)

Page 36: [2012 자바카페 OPEN 세미나] Introduction to google guava

Release Note

� Last Published� 2008년 4월 15일 (Version:3.2.1)

� 현재 Commons Collections 개발중단� Commons Collections 라이브러리

� JDK 1.2 ~ JDK 1.4 까지 지원� org.apache.commons.collection.*

� 개발시 사용하는 JDK 버전이 1.5 이상일 경우 사용을권장하지 않음

Page 37: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 38: [2012 자바카페 OPEN 세미나] Introduction to google guava

소개

� Google Core Library (JavaSE 5.0 +)� 구글 자바 프로젝트에서 기본적으로 사용� Google Guava로 명칭을 통일� Andorid 개발 지원� GWT 개발 지원� Apache license 2.0

Page 39: [2012 자바카페 OPEN 세미나] Introduction to google guava

Google Guava

Apache CommonsLang 컴포넌트

Apache CommonsCollections 컴포넌트

유용한 유틸리티

Page 40: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 41: [2012 자바카페 OPEN 세미나] Introduction to google guava

Release Note

� Last Published� 2012년 4월 30일 (Version:Release12)

� Apache Commons Collections 라이브러리가Generic를 지원하지 않아 대체하려 개발 시작

� 2009년 JDK 1.5를 기반으로 프로젝트 시작� Release11까지는 JDK 1.5 기반� Release12부터 JDK 1.6 기반� 버전업을 하면서 이름 변경

� Google Collections Library => Google Guava

Page 42: [2012 자바카페 OPEN 세미나] Introduction to google guava

제공되는 기능

• Collections• Concurrency• Primitives• Reflection• Comparison• I/O• Hashing• networking

• Strings• Math• In-memory caching• Publish/Subscribe• Various basic data

Page 43: [2012 자바카페 OPEN 세미나] Introduction to google guava

제공되는 기능

• Collections• Concurrency• Primitives• Reflection• Comparison• I/O• Hashing• networking

• Strings• Math• In-memory caching• Publish/Subscribe• Various basic data

“JDK-plus”!!!

Page 44: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 45: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 46: [2012 자바카페 OPEN 세미나] Introduction to google guava

Basic 유틸리티 (1/4)

� Object 클래스 유틸리티� java.lang.Object 클래스 Wrapping 유틸리티� com.google.common.base.Objects� equals() : equals 메소드 Override 지원� hashCode() : hashCode 메소드 Override 지원� toString() : toString 메소드 Override 지원

Page 47: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 48: [2012 자바카페 OPEN 세미나] Introduction to google guava

Basic 유틸리티 (2/4)

� Null 체크 유틸리티� 문자열의 null 문제를 다양하게 체크� com.google.common.base.Strings� emptyToNull(String) : 파라미터로 넘어온

값이 Empty 일 경우 Null 반환� isNullOrEmpty(String) : 파라미터로 넘어온

값이 Null이나 Empty인지 검사� nullToEmpty(String) : 파라미터로 넘어온 값

이 Null 일 경우 Empty 반환

Page 49: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 50: [2012 자바카페 OPEN 세미나] Introduction to google guava

Basic 유틸리티 (3/4)

� Precondition 유틸리티� 파라미터로 전달되는 값의 유효성 검사� com.google.common.base.Preconditions� checkArgument(boolean) : 인자 값을 미리

테스트하여 정상인지 검사� checkNotNull(T) : 인자 값을 미리 테스트하

여 Null인지 검사� checkState(boolean) : 인자값을 미리 테스트

하여 상태값을 검사

Page 51: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 52: [2012 자바카페 OPEN 세미나] Introduction to google guava

Basic 유틸리티 (4/4)

� Ordering 유틸리티� 객체 정렬을 위한 다양한 기능 제공� com.google.common.collect.Ordering� reverse() : 값을 반대로 정렬� nullsFirst() : null이 존재할 경우 처음으로 정렬� nullsLast() : null이 존재할 경우 마지막으로 정렬

Page 53: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 54: [2012 자바카페 OPEN 세미나] Introduction to google guava

Strings 유틸리티 (1/2)

� Joiner 유틸리티� 다양한 형태의 iterator를 하나로 합친다.� com.google.common.base.Joiner� join(Object[] parts) : 파라미터로 넘어온 배

열을 하나의 문자열로 합친다.� on(String separator) : 합칠 문자열 사이의

Separator를 지정� skipNulls() : 합칠 문자열 중 Null 값 제거

Page 55: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 56: [2012 자바카페 OPEN 세미나] Introduction to google guava

Strings 유틸리티 (2/2)

� Splitter 유틸리티� 문자열을 다양한 방식으로 분리한다.� com.google.common.base.Splitter� split(CharSequence sequnce) : 파라미터로

넘어온 문자열을 분리한다.� on(String separator) : 분리할 기분

Separator를 지정� omitEmptyStrings() : 분리 된 결과물에서

Empty 제거

Page 57: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 58: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 59: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 60: [2012 자바카페 OPEN 세미나] Introduction to google guava

Collection 유틸리티

Page 61: [2012 자바카페 OPEN 세미나] Introduction to google guava

Immutable Collections

Page 62: [2012 자바카페 OPEN 세미나] Introduction to google guava

새롭게 추가된 Collection� Multiset

� com.google.common.collect.Multiset� 두 개 이상의 키를 핸들링 할 수 있는 Set 형태의 Collection� HashMultiset, TreeMultiset, LinkedHashMultiset,

ImmutableMultiset� Multimap

� com.google.common.collect.Multimap� 두 개 이상의 키를 핸들링 할 수 있는 Map 형태의 Collection� HashMultimap, TreeMultimap, LinkedHashMultimap,

ImmutableListMultimap� BiMap

� com.google.common.collect.BiMap� 일반적인 Map과 달리 key와 value 양방향으로 검색이 가능한

Collection� HashBiMap, ImmutableBiMap, EnumBiMap, EnumHashBiMap

Page 63: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 64: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 65: [2012 자바카페 OPEN 세미나] Introduction to google guava
Page 66: [2012 자바카페 OPEN 세미나] Introduction to google guava

Guava 라이브러리를 써야하는 이유

� Apache Commons Collection의 경우 개발된지 10여년이 되었다.

� Apache Commons Collection의 경우JavaSE 5의 혜택이 없다. (generics, varags, enums, autoboxing)

� Google Guava의 경우 좀더 현대적이다. (Generic 지원, JDK7 지원)

� 아파치 라이센스 2.0 � Java Collection Framework와 완벽한 호환

Page 67: [2012 자바카페 OPEN 세미나] Introduction to google guava