SlideShare a Scribd company logo
μΆ”J
κ°€D
된K
것8
듀에
은
?

Home : GodOfJava.com
Blog : tuning-java.com

이상민
이 λ¬Έμ„œλŠ” λ‚˜λˆ”κΈ€κΌ΄λ‘œ μž‘μ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€. μ„€μΉ˜ν•˜κΈ°
λͺ©
μ°¨
1. Introduction
2. JDK 7 Summary
3. JDK 8 Summary
4. java.time
5. Lambda Expression
6. Bulk Data Operation
7. Conclusion
JDK 7 Summary
1. JDK 7 μ—μ„œ λ³€κ²½λœ 것듀

-

μΆ”κ°€ 사항
숫자 ν‘œμ‹œ 방법 보완
switch λ¬Έμ—μ„œ String μ‚¬μš©
μ œλ„€λ¦­μ„ μ‰½κ²Œ μ‚¬μš©ν•  수 μžˆλŠ” Diamond
μ˜ˆμ™Έμ²˜λ¦¬μ‹œ λ‹€μ€‘μ²˜λ¦¬ κ°€λŠ₯

6
2. JDK 7 μ—μ„œ μΆ”κ°€λœ 것듀

-

μΆ”κ°€ 사항
Fork Join
NIO2
JDBC 4.1
TransferQueue μΆ”κ°€
Objects 클래슀 μΆ”κ°€

7
JDK 8 Summary
1. JDK 8 Download
JDK 8 은 2013λ…„ 10μ›” ν˜„μž¬ EA (Early Access)
- 정식 버전은 아직 λ‚˜μ˜€μ§€ μ•Šμ•˜μœΌλ©° 2014λ…„ μ€‘μ—λŠ” λ‚˜μ˜¬ λ“―
λ‹€μš΄λ‘œλ“œλŠ” μ•„λž˜ λ§ν¬μ—μ„œ
- https://jdk8.java.net/download.html
- 잘 μ•ˆλ°›μ•„μ§. οƒ  계속 λŠκΉ€ !!!
(Safariμ—μ„œ 계속 λ‹€μ‹œ λ‹€μš΄λ‘œλ“œλ₯Ό λˆ„λ₯΄λ©΄μ„œ λ°›κ±°λ‚˜ λ‹€μš΄λ‘œλ“œ 툴 ꢌμž₯)

9
2. Full added features
μΆ”κ°€λœ κΈ°λŠ₯λ“€ λͺ©λ‘
(http://openjdk.java.net/projects/jdk8/features)

10
3. Today …
였늘 λ‹€λ£° λ‚΄μš©μ€
- java.time package
- Lambda Expression
- Bulk Data Operation
μ°Έκ³ 
- λͺ¨λ“ˆν™” 뢀뢄을 λ‹΄λ‹Ήν•˜λŠ” jigsaw λŠ” JDK 8μ—μ„œ μ œμ™Έ λ˜μ—ˆμŒ

11
java.time
Date-Time API
1. About Date-Time API
Data-Time API
- JDK 8 λΆ€ν„° 제곡되며, ISO-8601 ν‘œμ€€μ„ 따름
(http://www.iso.org/iso/home/standards/iso8601.htm)

- λͺ¨λ“  ν΄λž˜μŠ€λŠ” immutable ν•˜κ³ , thread safe
- Hijrah(Islamic), Japanese, Minguo(Taiwan), ThaiBuddhist 달λ ₯을 제곡
 μ•ˆνƒ€κΉκ²Œλ„ μš°λ¦¬λ‚˜λΌμ˜ 음λ ₯은 μ‘΄μž¬ν•˜μ§€ μ•ŠμŒ

13
2. Date-Time Design Principles
Clear
Fluent

Immutable
Extensible

14
2. Date-Time Design Principles
Clear
- APIλ₯Ό λͺ…λ°±ν•˜κ²Œ λ§Œλ“€μ—ˆμŒ
- 예λ₯Ό λ“€μ–΄ λ§€κ°œλ³€μˆ˜λ‘œ null이 λ“€μ–΄μ˜€λ©΄ NullPointerException λ°œμƒ

Fluent
- μ½”λ“œλ₯Ό 읽기 μ‰½κ²Œ
LocalDate today = LocalDate.now();
LocalDate payday = today.with(TemporalAdjuster.lastDayOfMonth()).minusDays(2);

Immutable
- λΆˆλ³€μ˜ 객체
LocalDate dateOfBirth = LocalDate.of(2012, Month.MAY, 14);
LocalDate firstBirthday = dateOfBirth.plusYears(1);

Extensible
- μž„μ˜μ˜ 달λ ₯을 μ‰½κ²Œ μΆ”κ°€ ν•  수 있음
15
3. Date-Time packages
java.time
java.time.chrono

java.time.format
java.time.temporal
java.time.zone

16
3. Date-Time packages
java.time
- λ‚ μ§œμ™€ μ‹œκ°„μ„ λ‚˜νƒ€λ‚΄λŠ” μ½”μ–΄(core) API
java.time.chrono
- μ£Όμš” 달λ ₯ 제곡
java.time.format
- λ‚ μ§œλ₯Ό formatν•˜κ³  parseν•˜λŠ” 클래슀 제곡

java.time.temporal
- λ‚ μ§œ 및 μ‹œκ°„ ν΄λž˜μŠ€λ“€μ„ μ²˜λ¦¬ν•˜κΈ° μœ„ν•œ ν™•μž₯ API
java.time.zone
- νƒ€μž„μ‘΄(time zone) 지원 ν΄λž˜μŠ€λ“€

17
4. Naming Convention
μ£Όμš” λ©”μ†Œλ“œμ΄λ¦„ prefix
Prefix

Method type

Description

of

static fact
ory

μž…λ ₯ λ§€κ°œλ³€μˆ˜μ— 따라 μΈμŠ€ν„΄μŠ€ 생성

from

static fact
ory

μž…λ ₯ λ§€κ°œλ³€μˆ˜λ₯Ό λŒ€μƒ 클래슀둜 λ³€ν™˜

parse

static fact
ory

μž…λ ₯ λ¬Έμžμ—΄μ„ νŒŒμ‹±ν•˜μ—¬ λŒ€μƒ 클래슀의 μΈμŠ€ν„΄μŠ€ 생성

format

instance

μ§€μ •λœ formatterλ₯Ό μ‚¬μš©ν•˜μ—¬ 값을 format

get

instance

λŒ€μƒ 객체의 일뢀 μƒνƒœ 값을 리턴

is

instance

λŒ€μƒ 객체의 μƒνƒœ 확인

with

instance

ν•˜λ‚˜μ˜ μš”μ†Œκ°€ λ³€κ²½λœ 볡제 객체 리턴

plus

instance

ν•˜λ‚˜μ˜ μš”μ†Œλ₯Ό λ”ν•œ 볡제 객체 리턴

minus

instance

ν•˜λ‚˜μ˜ μš”μ†Œμ˜ 값을 λΊ€ 볡제 객체 리턴

to

instance

ν˜„μž¬ 객체λ₯Ό λ‹€λ₯Έ νƒ€μž…μœΌλ‘œ λ³€ν™˜
18

at

instance

ν˜„μž¬ 객체λ₯Ό λ‹€λ₯Έ 객체와 κ²°ν•©
Lambda Expression
1. About Lambda
Lambda Expression
- β€œλžŒλ‹€ μ΅μŠ€ν”„λ ˆμ…˜β€μ΄λΌκ³  발음.
(λ¬΄μ‹ν•˜κ²Œ β€œλžŒλΈŒλ‹€β€λΌκ³  읽지 말 것 !)

- 이건 뭐 κ·Έλƒ₯ κ°„λ‹¨ν•œ ν‘œν˜„μ‹μ„ λ°°μš°λŠ” 것이라기 λ³΄λ‹€λŠ”
μƒˆλ‘œμš΄ μ–Έμ–΄λ₯Ό λ°°μš°λŠ” λŠλ‚Œ ?
- .stream().filter(…).map() κ³Ό 같이 .을 계속 μ°μ–΄μ£ΌλŠ” 문법에 μ΅μˆ™ν•΄λ„ 30%λŠ”
λ¨Ήκ³  λ“€μ–΄κ°€λŠ” 것
- 읡λͺ…(Anonymous) 클래슀만 이해해도 20%λŠ” λ¨Ήκ³  λ“€μ–΄κ°€λŠ” 것
- ν™”μ‚΄ν‘œ(->)와 λ•‘λ•‘(::)만 잘 이해해도 40%은 λ¨Ήκ³  λ“€μ–΄κ°€λŠ” 것
- λ‚˜λ¨Έμ§€ 10%λŠ” API λ₯Ό μ΄ν•΄ν•˜λŠ” 것
- 였늘 이 μ‹œκ°„μ— λͺ¨λ‘ μ΄ν•΄ν•˜κΈ° 쉽지 μ•Šμ€ 것

20
1. About Lambda
Lambda Expression 예
Stream.of(idArray)
.map(EmployeeUtils::findById)
.filter(e -> e !=null)
.filter(e -> e.getSalary() > 50000)
.findFirst()
.orElse(null);

21
2. Basic Knowledge
Lambda Expression 을 μ•Œμ•„λ³΄κΈ° 전에 μƒ˜ν”Œμ„ μ΄ν•΄ν•˜κΈ° μœ„ν•œ API 이해
java.util.Comparator interface의 compare() λ©”μ†Œλ“œ

java.util.Arrays class의 sort() λ©”μ†Œλ“œ

22
3. Understand Lambda-1
λ‹€μŒμ˜ Integer λ₯Ό μ •λ ¬ν•΄ 보자.
Integer[] data={3,2,1,4,6,5,9,8,7,10};
Arrays.sort(T[] t) λ©”μ†Œλ“œλ₯Ό μ‚¬μš©ν•  μˆ˜λ„ μžˆμ§€λ§Œ, Comparatorλ₯Ό μ‚¬μš©ν•΄μ•Ό ν•˜λŠ”
상황일 경우 Comparator μΈν„°νŽ˜μ΄μŠ€λ₯Ό κ΅¬ν˜„ν•΄μ•Ό ~~~

23
3. Understand Lambda-1

방법 1

Comparator μΈν„°νŽ˜μ΄μŠ€λ₯Ό κ΅¬ν˜„ν•œ Integer 비ꡐ 클래슀
class IntegerComparator<T> implements Comparator<T> {
@Override
public int compare(T x,T y) {
if(x instanceof Integer) {
return compareInt((Integer)x,(Integer)y);
} else return 0;
}
public int compareInt(Integer x,Integer y) {
return (x < y) ? -1 : ((x == y) ? 0 : 1);
}
}

24
3. Understand Lambda-1

방법 1

IntegerComparator 클래슀 μ‚¬μš© 예
public void useClass(Integer[] data) {
IntegerComparator<Integer> compare=new IntegerComparator<Integer>();
Arrays.sort(data,compare);
for(Integer temp:data) {
System.out.println(temp);
}
}

25
3. Understand Lambda-1
방법 2 λΆ€ν„°λŠ” compareInt() λ©”μ†Œλ“œκ°€ ν•΄λ‹Ή ν΄λž˜μŠ€μ— μ„ μ–Έ λ˜μ–΄ μžˆμ„ 경우
public int compareInt(Integer x,Integer y) {
return (x < y) ? -1 : ((x == y) ? 0 : 1);
}

26
3. Understand Lambda-1

방법 2

Anonymous 클래슀 μ‚¬μš© 예
public void anonymous(Integer[] data) {
Comparator<Integer> compare=new Comparator<Integer>() {
@Override
public int compare(Integer x,Integer y) {
return compareInt(x,y);
}
};
Arrays.sort(data,compare);
for(Integer temp:data) {
System.out.println(temp);
}
}

27
3. Understand Lambda-1

방법 3

Lambda μ‚¬μš© 예 1
public void lambda1(Integer[] data) {
Arrays.sort(data, (Integer x,Integer y) -> compareInt(x,y) );
for(Integer temp:data) {
System.out.println(temp);
}
}

28
3. Understand Lambda-1

방법 4

Lambda μ‚¬μš© 예 2
public void lambda2(Integer[] data) {
Arrays.sort(data, (x,y) -> compareInt(x,y) );
for(Integer temp:data) {
System.out.println(temp);
}
}

29
3. Understand Lambda-1

방법 5

Lambda μ‚¬μš© 예 3
public void lambda3(Integer[] data) {
List<Integer> list=Arrays.asList(data);
list.sort( (x,y) -> compareInt(x,y) );
list.forEach(System.out::println);
}

30
4. Understand Lambda-2
Lambda μ‚¬μš© 예
public class Calculator {
interface IntegerMath {
int operation(int a, int b);
}
public int operateBinary(int a, int b, IntegerMath op) {
return op.operation(a, b);
}
public static void main(String... args) {
Calculator myApp = new Calculator();
IntegerMath addition = (a, b) -> a + b;
IntegerMath subtraction = (a, b) -> a - b;
System.out.println("40 + 2 = " +
myApp.operateBinary(40, 2, addition));
System.out.println("20 - 10 = " +
myApp.operateBinary(20, 10, subtraction));
}
}
31
4. Understand Lambda-2
Lambda μ‚¬μš© 예
public class Calculator {
interface IntegerMath {
int operation(int a, int b);
}
public int operateBinary(int a, int b, IntegerMath op) {
return op.operation(a, b);
}
public static void main(String... args) {
Calculator myApp = new Calculator();
IntegerMath addition = (a, b) -> a + b;
IntegerMath subtraction = (a, b) -> a - b;
System.out.println("40 + 2 = " +
myApp.operateBinary(40, 2, addition));
System.out.println("20 - 10 = " +
myApp.operateBinary(20, 10, subtraction));
}
}
32
4. Understand Lambda-2
Lambda μ‚¬μš© 예
public class Calculator {
interface IntegerMath {
int operation(int a, int b);
}
public int operateBinary(int a, int b, IntegerMath op) {
return op.operation(a, b);
}
public static void main(String... args) {
Calculator myApp = new Calculator();
IntegerMath addition = (a, b) -> a + b;
IntegerMath subtraction = (a, b) -> a - b;
System.out.println("40 + 2 = " +
myApp.operateBinary(40, 2, addition));
System.out.println("20 - 10 = " +
myApp.operateBinary(20, 10, subtraction));
}
}
33
4. Understand Lambda-2
Lambda μ‚¬μš© 예
public class Calculator {
interface IntegerMath {
int operation(int a, int b);
}
public int operateBinary(int a, int b, IntegerMath op) {
return op.operation(a, b);
}
public static void main(String... args) {
Calculator myApp = new Calculator();
IntegerMath addition = (a, b) -> a + b;
IntegerMath subtraction = (a, b) -> a - b;
System.out.println("40 + 2 = " +
myApp.operateBinary(40, 2, addition));
System.out.println("20 - 10 = " +
myApp.operateBinary(20, 10, subtraction));
}
}
34
5. Expression
-> (arrow token)
IntegerMath addition = (a, b) -> a + b;
- λ§€κ°œλ³€μˆ˜λ‘œ a와 b λ₯Ό λ°›λŠ” μž‘μ—…μ„ addition 객체에 ν• λ‹Ήν•œλ‹€.
- (a,b)μ—μ„œ λ§€κ°œλ³€μˆ˜ νƒ€μž…μ„ λͺ…μ‹œν•΄λ„ 되고, λͺ…μ‹œν•˜μ§€ μ•Šμ•„λ„ λœλ‹€.
IntegerMath addition = (int a, int b) -> a + b;

35
5. Expression
:: (method reference)
System.out::println
- λžŒλ‹€ λ¬Έμž₯이 λ“€μ–΄κ°€λŠ” 뢀뢄에 :: 을 μ‚¬μš©ν•˜μ—¬ λ©”μ†Œλ“œ μ°Έμ‘° κ°€λŠ₯
- λ©”μ†Œλ“œ μ°Έμ‘° 문법은 μ•„λž˜μ™€ κ°™μŒ
Kind

Example

static λ©”μ†Œλ“œ μ°Έμ‘°

클래슀λͺ…::staticλ©”μ†Œλ“œλͺ…

μΈμŠ€ν„΄μŠ€ λ©”μ†Œλ“œ μ°Έμ‘°

μΈμŠ€ν„΄μŠ€λͺ…::λ©”μ†Œλ“œλͺ…

νŠΉμ • νƒ€μž…μ˜ μΈμŠ€ν„΄μŠ€ λ©”μ†Œλ“œ μ°Έμ‘°

νƒ€μž…::λ©”μ†Œλ“œλͺ…

μƒμ„±μž μ°Έμ‘°

클래슀λͺ…::new

36
Bulk Data Operation
java.util.stream.Stream
1. Stream interface
java.util.stream.Stream interface
- Collection APIλ₯Ό κ΅¬ν˜„ / ν™•μž₯ν•œ 클래슀의 객체λ₯Ό μ‰½κ²Œ μ²˜λ¦¬ν•  수 μžˆλ„λ‘ ν•œ 인
ν„°νŽ˜μ΄μŠ€
- http://download.java.net/jdk8/docs/api/
- Collection 클래슀의 stream() λ©”μ†Œλ“œλ₯Ό ν˜ΈμΆœν•˜λ©΄ Stream 객체 생성
- Steam == sequence of elements

38
1. Stream interface
λ³€ν™˜ λŒ€μƒ 객체
List<Integer> numbers=Arrays.asList(1,2,3,4,5,6,7,8,9,10);
Stream interface 예
public void map(List<Integer> numbers) {
System.out.println("map()");
numbers.stream()
.map(value -> value *2)
.forEach(System.out::println);
}

39
2. Stream methods
μ£Όμš” λ©”μ†Œλ“œ
Method

Description

filter(Predicate<T> predicate)

μ£Όμ–΄μ§„ 쑰건(predicate)에 λ§žλŠ” μš”μ†Œ 리턴

forEach(Consumer<T> action)

μ£Όμ–΄μ§„ μž‘μ—…(action) μ‹€ν–‰

map(Function<T,R> mapper)

μˆ˜ν–‰λœ μž‘μ—…(mapper)의 κ²°κ³Όλ₯Ό 리턴

reduce(BinaryOperator<T> accumulato reduce μž‘μ—… μˆ˜ν–‰ (항상 μƒˆλ‘œμš΄ 객체 및 κ°’
r)
을 리턴)
collect(Collector<? super T,A,R> co mutable reduction μž‘μ—… μˆ˜ν–‰(μˆ˜μ •λœ 객체
llector)
및 값을 리턴)

40
3. Stream 예
filter & forEach
numbers.stream()
.filter(value -> value %3 == 0)
.forEach(System.out::println);

41
3. Stream 예
map & forEach
numbers.stream()
.map(value -> value *2)
.forEach(System.out::println);

42
3. Stream 예
reduce
List<String> names=
Arrays.asList("God","Of","Java","You","Min","Yeon","Sook");
Optional<String> shortestName = names.stream()
.reduce((name1,name2) ->
name1.length()<=name2.length() ? name1 : name2 );
Optional<String> longestName = names.stream()
.reduce((name1,name2) ->
name1.length()>=name2.length() ? name1 : name2 );
System.out.println(shortestName.get());
System.out.println(longestName.get());

43
Conclusion
Conclusion
μ„€λͺ…ν•œ λ‚΄μš©μ΄ 이해 μ•ˆλœλ‹€κ³  μ’Œμ ˆν•˜μ§€ 말자 !
- μ–΄μ°¨ν”Ό JDK 8 ReleaseλŠ” λ‚΄λ…„
 이해할 μ‹œκ°„μ€ μΆ©λΆ„ν•˜λ‹€.

- μ–΄μ°¨ν”Ό Release 된 이후에 μ—¬λŸ¬λΆ„λ“€μ˜ μ‹œμŠ€ν…œμ—μ„œ JDK 8을 μ‚¬μš©ν•˜λ €λ©΄ λ©€μ—ˆλ‹€.
 이해할 μ‹œκ°„μ€ 더 μΆ©λΆ„ν•˜λ‹€.
κ·Έλ ‡λ‹€κ³  Lambda Expression λ¬΄μ‹œν•˜λ©΄ ?
- 3λ…„ 뒀에 λ„νƒœλœλ‹€.
 μ½”λ“œλ₯Ό 이해 λͺ»ν•˜κ² μ£ ?

45
Conclusion
였늘 μ„€λͺ…ν•œ λ‚΄μš©μ€ λΉ™μ‚°μ˜ 일각일 뿐
- Lambda 및 Bulk Data Operation 에 λŒ€ν•΄μ„œ μžμ„Ένžˆ μ‚΄νŽ΄λ³΄λ €λ©΄ API/Java Tutorial
μ°Έκ³ 
http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html
http://docs.oracle.com/javase/tutorial/collections/streams/index.html

46
* Lambda reference
State of the Lambda
- http://cr.openjdk.java.net/~briangoetz/lambda/lambda-libraries-final.html
Java Tutorial
- http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html
Slideshare
- http://www.slideshare.net/scottleber/java8-8-lambda-expressions

-

Marty Hall (slideshare)
http://www.slideshare.net/martyhall/java-8-tutorial-streams-part-1
http://www.slideshare.net/martyhall/java-8-tutorial-streams-part-2-mapreduce-parallel-streams-and-infinite-streams
http://www.slideshare.net/martyhall/java-8-tutorial-lambda-expressionspart-1
http://www.slideshare.net/martyhall/java-8-tutorial-lambda-expressionspart-2
http://www.slideshare.net/martyhall/java-8-tutorial-lambda-expressions-

47
κ°μ‚¬ν•©λ‹ˆλ‹€.

이 λ¬Έμ„œλŠ” λ‚˜λˆ”κΈ€κΌ΄λ‘œ μž‘μ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€. μ„€μΉ˜ν•˜κΈ°

More Related Content

PDF
μžλ°”8 λžŒλ‹€ λ‚˜λ¨Έμ§€ 곡개
PPTX
Just java
PPTX
μžλ°” 8 ν•™μŠ΅
PDF
α„Œα…‘α„‡α…‘8 ᄅᅑᆷᄃᅑ삭 소ᄀᅒ
PDF
java 8 λžŒλ‹€μ‹ μ†Œκ°œμ™€ 의미 κ³ μ°°
PDF
JDK λ³€μ²œμ‚¬
PDF
Java8 & Lambda
PPTX
λ™μž‘ νŒŒλΌλ―Έν„°μ™€ λžŒλ‹€ In java 8
μžλ°”8 λžŒλ‹€ λ‚˜λ¨Έμ§€ 곡개
Just java
μžλ°” 8 ν•™μŠ΅
α„Œα…‘α„‡α…‘8 ᄅᅑᆷᄃᅑ삭 소ᄀᅒ
java 8 λžŒλ‹€μ‹ μ†Œκ°œμ™€ 의미 κ³ μ°°
JDK λ³€μ²œμ‚¬
Java8 & Lambda
λ™μž‘ νŒŒλΌλ―Έν„°μ™€ λžŒλ‹€ In java 8

What's hot (18)

PDF
μžλ°”8 슀트림 API μ†Œκ°œ
PDF
Ji 개발 리뷰 (μ‹ λ¦Όν”„λ‘œκ·Έλž˜λ¨Έ)
PDF
α„‚α…‘α„‹α…¦ α„Žα…₯ᆺᄇα…₯ᆫᄍᅒ α„Œα…‘α„‡α…‘8 ᄅᅑᆷᄃᅑ삭 α„Œα…΅α„‹α…’α†«α„‰α…₯ᆫ
PDF
JVM λ©”λͺ¨λ¦¬ ν•΄λΆ€ν•™
PDF
μ”Ήκ³  뜯고 맛보고 μ¦κΈ°λŠ” 슀트림 API
PDF
Java stream v0.1
PPTX
Java mentoring of samsung scsc 2
PDF
Java lambda
PDF
Java advancd ed10
PDF
모델랑 연습 리뷰
PDF
Collection framework
PPTX
Linq to object using c#
PDF
Java λ³€μˆ˜μžλ£Œν˜•
PPTX
Jquery javascript_ed10
PDF
μžλ°”8κ°•μ˜ 0α„€α…‘α†Ό. java8 overview
PDF
일단 μ‹œμž‘ν•˜λŠ” μ½”ν‹€λ¦°
PDF
μžλ°”8κ°•μ˜ 2κ°•. Stream API
PPT
κ°•μ˜μžλ£Œ4
μžλ°”8 슀트림 API μ†Œκ°œ
Ji 개발 리뷰 (μ‹ λ¦Όν”„λ‘œκ·Έλž˜λ¨Έ)
α„‚α…‘α„‹α…¦ α„Žα…₯ᆺᄇα…₯ᆫᄍᅒ α„Œα…‘α„‡α…‘8 ᄅᅑᆷᄃᅑ삭 α„Œα…΅α„‹α…’α†«α„‰α…₯ᆫ
JVM λ©”λͺ¨λ¦¬ ν•΄λΆ€ν•™
μ”Ήκ³  뜯고 맛보고 μ¦κΈ°λŠ” 슀트림 API
Java stream v0.1
Java mentoring of samsung scsc 2
Java lambda
Java advancd ed10
모델랑 연습 리뷰
Collection framework
Linq to object using c#
Java λ³€μˆ˜μžλ£Œν˜•
Jquery javascript_ed10
μžλ°”8κ°•μ˜ 0α„€α…‘α†Ό. java8 overview
일단 μ‹œμž‘ν•˜λŠ” μ½”ν‹€λ¦°
μžλ°”8κ°•μ˜ 2κ°•. Stream API
κ°•μ˜μžλ£Œ4
Ad

Viewers also liked (6)

PDF
쒌좩우돌 ORM 개발기 | Devon 2012
PPT
Spring Batch 2.0
PDF
Ksug2015 jpa5 스프랑ᄀα…ͺjpa
PPTX
μ†Œν”„νŠΈμ›¨μ–΄ ν•™μŠ΅ 및 α„Œα…‘α„‡α…‘ α„‹α…°α†Έ α„€α…’α„‡α…‘α†―α„Œα…‘ ᄒᅑᆨ습 로드ᄆᅒᆸ
PDF
SpringDataJPA - μŠ€ν”„λ§ μΊ ν”„
PDF
더 λ‚˜μ€ 개발자 되기
쒌좩우돌 ORM 개발기 | Devon 2012
Spring Batch 2.0
Ksug2015 jpa5 스프랑ᄀα…ͺjpa
μ†Œν”„νŠΈμ›¨μ–΄ ν•™μŠ΅ 및 α„Œα…‘α„‡α…‘ α„‹α…°α†Έ α„€α…’α„‡α…‘α†―α„Œα…‘ ᄒᅑᆨ습 로드ᄆᅒᆸ
SpringDataJPA - μŠ€ν”„λ§ μΊ ν”„
더 λ‚˜μ€ 개발자 되기
Ad

Similar to SpringCamp 2013 : About Jdk8 (20)

PDF
Java stream v0.1
PDF
Java_10 λžŒλ‹€
PDF
Java jungsuk3 ch14_lambda_stream
PDF
ν•¨μˆ˜μ  사고 2μž₯
PPTX
ECMAScript 6의 μƒˆλ‘œμš΄ 것듀!
PPTX
Java Virtual Machine, Call stack, Java Byte Code
PDF
2014.07.26 KSUG와 지앀선이 ν•¨κ»˜ν•˜λŠ” ν…Œν¬λ‹ˆμ»¬ μ„Έλ―Έλ‚˜ - α„‚α…‘μ˜ α„Žα…₯ᆺᄇα…₯ᆫᄍᅒ α„Œα…‘α„‡α…‘8 ᄅᅑᆷᄃᅑ삭 (μ •λŒ€μ›)
PPT
Ai C#μ„Έλ―Έλ‚˜
PPTX
Java8 λžŒλ‹€
PDF
Java κ°•μ˜μžλ£Œ ed11
PDF
Swift3 subscript inheritance initialization
PDF
PySpark 배우기 Ch 06. ML νŒ¨ν‚€μ§€ μ†Œκ°œν•˜κΈ°
PPTX
κ°•μ˜μžλ£Œ 2
PPTX
About Visual C++ 10
PDF
[1A5]α„’α…­α„‹α…²α†―α„Œα…₯ᆨ안ᄋᅑᆫ드로아드ᄋᅒᆸᄀᅒᄇᅑᆯ
PPTX
ν•¨μˆ˜ν˜• ν”„λ‘œκ·Έλž˜λ°
PDF
2014.07.26 KSUG와 지앀선이 ν•¨κ»˜ν•˜λŠ” ν…Œν¬λ‹ˆμ»¬ μ„Έλ―Έλ‚˜ - μžλ°”8 λžŒλ‹€ λ‚˜λ¨Έμ§€ 이야기 (λ°•μ„±μ² )
PDF
파이썬 λ°μ΄ν„°λ² μ΄μŠ€ μ—°κ²° 2탄
PDF
12μž₯ 상속 (κ³ κΈ‰)
PPTX
Java Annotationκ³Ό MyBatis둜 λ‚˜λ§Œμ˜ ORM Framework을 λ§Œλ“€μ–΄λ³΄μž
Java stream v0.1
Java_10 λžŒλ‹€
Java jungsuk3 ch14_lambda_stream
ν•¨μˆ˜μ  사고 2μž₯
ECMAScript 6의 μƒˆλ‘œμš΄ 것듀!
Java Virtual Machine, Call stack, Java Byte Code
2014.07.26 KSUG와 지앀선이 ν•¨κ»˜ν•˜λŠ” ν…Œν¬λ‹ˆμ»¬ μ„Έλ―Έλ‚˜ - α„‚α…‘μ˜ α„Žα…₯ᆺᄇα…₯ᆫᄍᅒ α„Œα…‘α„‡α…‘8 ᄅᅑᆷᄃᅑ삭 (μ •λŒ€μ›)
Ai C#μ„Έλ―Έλ‚˜
Java8 λžŒλ‹€
Java κ°•μ˜μžλ£Œ ed11
Swift3 subscript inheritance initialization
PySpark 배우기 Ch 06. ML νŒ¨ν‚€μ§€ μ†Œκ°œν•˜κΈ°
κ°•μ˜μžλ£Œ 2
About Visual C++ 10
[1A5]α„’α…­α„‹α…²α†―α„Œα…₯ᆨ안ᄋᅑᆫ드로아드ᄋᅒᆸᄀᅒᄇᅑᆯ
ν•¨μˆ˜ν˜• ν”„λ‘œκ·Έλž˜λ°
2014.07.26 KSUG와 지앀선이 ν•¨κ»˜ν•˜λŠ” ν…Œν¬λ‹ˆμ»¬ μ„Έλ―Έλ‚˜ - μžλ°”8 λžŒλ‹€ λ‚˜λ¨Έμ§€ 이야기 (λ°•μ„±μ² )
파이썬 λ°μ΄ν„°λ² μ΄μŠ€ μ—°κ²° 2탄
12μž₯ 상속 (κ³ κΈ‰)
Java Annotationκ³Ό MyBatis둜 λ‚˜λ§Œμ˜ ORM Framework을 λ§Œλ“€μ–΄λ³΄μž

SpringCamp 2013 : About Jdk8

  • 1. μΆ”J κ°€D 된K 것8 듀에 은 ? Home : GodOfJava.com Blog : tuning-java.com 이상민 이 λ¬Έμ„œλŠ” λ‚˜λˆ”κΈ€κΌ΄λ‘œ μž‘μ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€. μ„€μΉ˜ν•˜κΈ°
  • 2. λͺ© μ°¨ 1. Introduction 2. JDK 7 Summary 3. JDK 8 Summary 4. java.time 5. Lambda Expression 6. Bulk Data Operation 7. Conclusion
  • 4. 1. JDK 7 μ—μ„œ λ³€κ²½λœ 것듀 - μΆ”κ°€ 사항 숫자 ν‘œμ‹œ 방법 보완 switch λ¬Έμ—μ„œ String μ‚¬μš© μ œλ„€λ¦­μ„ μ‰½κ²Œ μ‚¬μš©ν•  수 μžˆλŠ” Diamond μ˜ˆμ™Έμ²˜λ¦¬μ‹œ λ‹€μ€‘μ²˜λ¦¬ κ°€λŠ₯ 6
  • 5. 2. JDK 7 μ—μ„œ μΆ”κ°€λœ 것듀 - μΆ”κ°€ 사항 Fork Join NIO2 JDBC 4.1 TransferQueue μΆ”κ°€ Objects 클래슀 μΆ”κ°€ 7
  • 7. 1. JDK 8 Download JDK 8 은 2013λ…„ 10μ›” ν˜„μž¬ EA (Early Access) - 정식 버전은 아직 λ‚˜μ˜€μ§€ μ•Šμ•˜μœΌλ©° 2014λ…„ μ€‘μ—λŠ” λ‚˜μ˜¬ λ“― λ‹€μš΄λ‘œλ“œλŠ” μ•„λž˜ λ§ν¬μ—μ„œ - https://jdk8.java.net/download.html - 잘 μ•ˆλ°›μ•„μ§. οƒ  계속 λŠκΉ€ !!! (Safariμ—μ„œ 계속 λ‹€μ‹œ λ‹€μš΄λ‘œλ“œλ₯Ό λˆ„λ₯΄λ©΄μ„œ λ°›κ±°λ‚˜ λ‹€μš΄λ‘œλ“œ 툴 ꢌμž₯) 9
  • 8. 2. Full added features μΆ”κ°€λœ κΈ°λŠ₯λ“€ λͺ©λ‘ (http://openjdk.java.net/projects/jdk8/features) 10
  • 9. 3. Today … 였늘 λ‹€λ£° λ‚΄μš©μ€ - java.time package - Lambda Expression - Bulk Data Operation μ°Έκ³  - λͺ¨λ“ˆν™” 뢀뢄을 λ‹΄λ‹Ήν•˜λŠ” jigsaw λŠ” JDK 8μ—μ„œ μ œμ™Έ λ˜μ—ˆμŒ 11
  • 11. 1. About Date-Time API Data-Time API - JDK 8 λΆ€ν„° 제곡되며, ISO-8601 ν‘œμ€€μ„ 따름 (http://www.iso.org/iso/home/standards/iso8601.htm) - λͺ¨λ“  ν΄λž˜μŠ€λŠ” immutable ν•˜κ³ , thread safe - Hijrah(Islamic), Japanese, Minguo(Taiwan), ThaiBuddhist 달λ ₯을 제곡  μ•ˆνƒ€κΉκ²Œλ„ μš°λ¦¬λ‚˜λΌμ˜ 음λ ₯은 μ‘΄μž¬ν•˜μ§€ μ•ŠμŒ 13
  • 12. 2. Date-Time Design Principles Clear Fluent Immutable Extensible 14
  • 13. 2. Date-Time Design Principles Clear - APIλ₯Ό λͺ…λ°±ν•˜κ²Œ λ§Œλ“€μ—ˆμŒ - 예λ₯Ό λ“€μ–΄ λ§€κ°œλ³€μˆ˜λ‘œ null이 λ“€μ–΄μ˜€λ©΄ NullPointerException λ°œμƒ Fluent - μ½”λ“œλ₯Ό 읽기 μ‰½κ²Œ LocalDate today = LocalDate.now(); LocalDate payday = today.with(TemporalAdjuster.lastDayOfMonth()).minusDays(2); Immutable - λΆˆλ³€μ˜ 객체 LocalDate dateOfBirth = LocalDate.of(2012, Month.MAY, 14); LocalDate firstBirthday = dateOfBirth.plusYears(1); Extensible - μž„μ˜μ˜ 달λ ₯을 μ‰½κ²Œ μΆ”κ°€ ν•  수 있음 15
  • 15. 3. Date-Time packages java.time - λ‚ μ§œμ™€ μ‹œκ°„μ„ λ‚˜νƒ€λ‚΄λŠ” μ½”μ–΄(core) API java.time.chrono - μ£Όμš” 달λ ₯ 제곡 java.time.format - λ‚ μ§œλ₯Ό formatν•˜κ³  parseν•˜λŠ” 클래슀 제곡 java.time.temporal - λ‚ μ§œ 및 μ‹œκ°„ ν΄λž˜μŠ€λ“€μ„ μ²˜λ¦¬ν•˜κΈ° μœ„ν•œ ν™•μž₯ API java.time.zone - νƒ€μž„μ‘΄(time zone) 지원 ν΄λž˜μŠ€λ“€ 17
  • 16. 4. Naming Convention μ£Όμš” λ©”μ†Œλ“œμ΄λ¦„ prefix Prefix Method type Description of static fact ory μž…λ ₯ λ§€κ°œλ³€μˆ˜μ— 따라 μΈμŠ€ν„΄μŠ€ 생성 from static fact ory μž…λ ₯ λ§€κ°œλ³€μˆ˜λ₯Ό λŒ€μƒ 클래슀둜 λ³€ν™˜ parse static fact ory μž…λ ₯ λ¬Έμžμ—΄μ„ νŒŒμ‹±ν•˜μ—¬ λŒ€μƒ 클래슀의 μΈμŠ€ν„΄μŠ€ 생성 format instance μ§€μ •λœ formatterλ₯Ό μ‚¬μš©ν•˜μ—¬ 값을 format get instance λŒ€μƒ 객체의 일뢀 μƒνƒœ 값을 리턴 is instance λŒ€μƒ 객체의 μƒνƒœ 확인 with instance ν•˜λ‚˜μ˜ μš”μ†Œκ°€ λ³€κ²½λœ 볡제 객체 리턴 plus instance ν•˜λ‚˜μ˜ μš”μ†Œλ₯Ό λ”ν•œ 볡제 객체 리턴 minus instance ν•˜λ‚˜μ˜ μš”μ†Œμ˜ 값을 λΊ€ 볡제 객체 리턴 to instance ν˜„μž¬ 객체λ₯Ό λ‹€λ₯Έ νƒ€μž…μœΌλ‘œ λ³€ν™˜ 18 at instance ν˜„μž¬ 객체λ₯Ό λ‹€λ₯Έ 객체와 κ²°ν•©
  • 18. 1. About Lambda Lambda Expression - β€œλžŒλ‹€ μ΅μŠ€ν”„λ ˆμ…˜β€μ΄λΌκ³  발음. (λ¬΄μ‹ν•˜κ²Œ β€œλžŒλΈŒλ‹€β€λΌκ³  읽지 말 것 !) - 이건 뭐 κ·Έλƒ₯ κ°„λ‹¨ν•œ ν‘œν˜„μ‹μ„ λ°°μš°λŠ” 것이라기 λ³΄λ‹€λŠ” μƒˆλ‘œμš΄ μ–Έμ–΄λ₯Ό λ°°μš°λŠ” λŠλ‚Œ ? - .stream().filter(…).map() κ³Ό 같이 .을 계속 μ°μ–΄μ£ΌλŠ” 문법에 μ΅μˆ™ν•΄λ„ 30%λŠ” λ¨Ήκ³  λ“€μ–΄κ°€λŠ” 것 - 읡λͺ…(Anonymous) 클래슀만 이해해도 20%λŠ” λ¨Ήκ³  λ“€μ–΄κ°€λŠ” 것 - ν™”μ‚΄ν‘œ(->)와 λ•‘λ•‘(::)만 잘 이해해도 40%은 λ¨Ήκ³  λ“€μ–΄κ°€λŠ” 것 - λ‚˜λ¨Έμ§€ 10%λŠ” API λ₯Ό μ΄ν•΄ν•˜λŠ” 것 - 였늘 이 μ‹œκ°„μ— λͺ¨λ‘ μ΄ν•΄ν•˜κΈ° 쉽지 μ•Šμ€ 것 20
  • 19. 1. About Lambda Lambda Expression 예 Stream.of(idArray) .map(EmployeeUtils::findById) .filter(e -> e !=null) .filter(e -> e.getSalary() > 50000) .findFirst() .orElse(null); 21
  • 20. 2. Basic Knowledge Lambda Expression 을 μ•Œμ•„λ³΄κΈ° 전에 μƒ˜ν”Œμ„ μ΄ν•΄ν•˜κΈ° μœ„ν•œ API 이해 java.util.Comparator interface의 compare() λ©”μ†Œλ“œ java.util.Arrays class의 sort() λ©”μ†Œλ“œ 22
  • 21. 3. Understand Lambda-1 λ‹€μŒμ˜ Integer λ₯Ό μ •λ ¬ν•΄ 보자. Integer[] data={3,2,1,4,6,5,9,8,7,10}; Arrays.sort(T[] t) λ©”μ†Œλ“œλ₯Ό μ‚¬μš©ν•  μˆ˜λ„ μžˆμ§€λ§Œ, Comparatorλ₯Ό μ‚¬μš©ν•΄μ•Ό ν•˜λŠ” 상황일 경우 Comparator μΈν„°νŽ˜μ΄μŠ€λ₯Ό κ΅¬ν˜„ν•΄μ•Ό ~~~ 23
  • 22. 3. Understand Lambda-1 방법 1 Comparator μΈν„°νŽ˜μ΄μŠ€λ₯Ό κ΅¬ν˜„ν•œ Integer 비ꡐ 클래슀 class IntegerComparator<T> implements Comparator<T> { @Override public int compare(T x,T y) { if(x instanceof Integer) { return compareInt((Integer)x,(Integer)y); } else return 0; } public int compareInt(Integer x,Integer y) { return (x < y) ? -1 : ((x == y) ? 0 : 1); } } 24
  • 23. 3. Understand Lambda-1 방법 1 IntegerComparator 클래슀 μ‚¬μš© 예 public void useClass(Integer[] data) { IntegerComparator<Integer> compare=new IntegerComparator<Integer>(); Arrays.sort(data,compare); for(Integer temp:data) { System.out.println(temp); } } 25
  • 24. 3. Understand Lambda-1 방법 2 λΆ€ν„°λŠ” compareInt() λ©”μ†Œλ“œκ°€ ν•΄λ‹Ή ν΄λž˜μŠ€μ— μ„ μ–Έ λ˜μ–΄ μžˆμ„ 경우 public int compareInt(Integer x,Integer y) { return (x < y) ? -1 : ((x == y) ? 0 : 1); } 26
  • 25. 3. Understand Lambda-1 방법 2 Anonymous 클래슀 μ‚¬μš© 예 public void anonymous(Integer[] data) { Comparator<Integer> compare=new Comparator<Integer>() { @Override public int compare(Integer x,Integer y) { return compareInt(x,y); } }; Arrays.sort(data,compare); for(Integer temp:data) { System.out.println(temp); } } 27
  • 26. 3. Understand Lambda-1 방법 3 Lambda μ‚¬μš© 예 1 public void lambda1(Integer[] data) { Arrays.sort(data, (Integer x,Integer y) -> compareInt(x,y) ); for(Integer temp:data) { System.out.println(temp); } } 28
  • 27. 3. Understand Lambda-1 방법 4 Lambda μ‚¬μš© 예 2 public void lambda2(Integer[] data) { Arrays.sort(data, (x,y) -> compareInt(x,y) ); for(Integer temp:data) { System.out.println(temp); } } 29
  • 28. 3. Understand Lambda-1 방법 5 Lambda μ‚¬μš© 예 3 public void lambda3(Integer[] data) { List<Integer> list=Arrays.asList(data); list.sort( (x,y) -> compareInt(x,y) ); list.forEach(System.out::println); } 30
  • 29. 4. Understand Lambda-2 Lambda μ‚¬μš© 예 public class Calculator { interface IntegerMath { int operation(int a, int b); } public int operateBinary(int a, int b, IntegerMath op) { return op.operation(a, b); } public static void main(String... args) { Calculator myApp = new Calculator(); IntegerMath addition = (a, b) -> a + b; IntegerMath subtraction = (a, b) -> a - b; System.out.println("40 + 2 = " + myApp.operateBinary(40, 2, addition)); System.out.println("20 - 10 = " + myApp.operateBinary(20, 10, subtraction)); } } 31
  • 30. 4. Understand Lambda-2 Lambda μ‚¬μš© 예 public class Calculator { interface IntegerMath { int operation(int a, int b); } public int operateBinary(int a, int b, IntegerMath op) { return op.operation(a, b); } public static void main(String... args) { Calculator myApp = new Calculator(); IntegerMath addition = (a, b) -> a + b; IntegerMath subtraction = (a, b) -> a - b; System.out.println("40 + 2 = " + myApp.operateBinary(40, 2, addition)); System.out.println("20 - 10 = " + myApp.operateBinary(20, 10, subtraction)); } } 32
  • 31. 4. Understand Lambda-2 Lambda μ‚¬μš© 예 public class Calculator { interface IntegerMath { int operation(int a, int b); } public int operateBinary(int a, int b, IntegerMath op) { return op.operation(a, b); } public static void main(String... args) { Calculator myApp = new Calculator(); IntegerMath addition = (a, b) -> a + b; IntegerMath subtraction = (a, b) -> a - b; System.out.println("40 + 2 = " + myApp.operateBinary(40, 2, addition)); System.out.println("20 - 10 = " + myApp.operateBinary(20, 10, subtraction)); } } 33
  • 32. 4. Understand Lambda-2 Lambda μ‚¬μš© 예 public class Calculator { interface IntegerMath { int operation(int a, int b); } public int operateBinary(int a, int b, IntegerMath op) { return op.operation(a, b); } public static void main(String... args) { Calculator myApp = new Calculator(); IntegerMath addition = (a, b) -> a + b; IntegerMath subtraction = (a, b) -> a - b; System.out.println("40 + 2 = " + myApp.operateBinary(40, 2, addition)); System.out.println("20 - 10 = " + myApp.operateBinary(20, 10, subtraction)); } } 34
  • 33. 5. Expression -> (arrow token) IntegerMath addition = (a, b) -> a + b; - λ§€κ°œλ³€μˆ˜λ‘œ a와 b λ₯Ό λ°›λŠ” μž‘μ—…μ„ addition 객체에 ν• λ‹Ήν•œλ‹€. - (a,b)μ—μ„œ λ§€κ°œλ³€μˆ˜ νƒ€μž…μ„ λͺ…μ‹œν•΄λ„ 되고, λͺ…μ‹œν•˜μ§€ μ•Šμ•„λ„ λœλ‹€. IntegerMath addition = (int a, int b) -> a + b; 35
  • 34. 5. Expression :: (method reference) System.out::println - λžŒλ‹€ λ¬Έμž₯이 λ“€μ–΄κ°€λŠ” 뢀뢄에 :: 을 μ‚¬μš©ν•˜μ—¬ λ©”μ†Œλ“œ μ°Έμ‘° κ°€λŠ₯ - λ©”μ†Œλ“œ μ°Έμ‘° 문법은 μ•„λž˜μ™€ κ°™μŒ Kind Example static λ©”μ†Œλ“œ μ°Έμ‘° 클래슀λͺ…::staticλ©”μ†Œλ“œλͺ… μΈμŠ€ν„΄μŠ€ λ©”μ†Œλ“œ μ°Έμ‘° μΈμŠ€ν„΄μŠ€λͺ…::λ©”μ†Œλ“œλͺ… νŠΉμ • νƒ€μž…μ˜ μΈμŠ€ν„΄μŠ€ λ©”μ†Œλ“œ μ°Έμ‘° νƒ€μž…::λ©”μ†Œλ“œλͺ… μƒμ„±μž μ°Έμ‘° 클래슀λͺ…::new 36
  • 36. 1. Stream interface java.util.stream.Stream interface - Collection APIλ₯Ό κ΅¬ν˜„ / ν™•μž₯ν•œ 클래슀의 객체λ₯Ό μ‰½κ²Œ μ²˜λ¦¬ν•  수 μžˆλ„λ‘ ν•œ 인 ν„°νŽ˜μ΄μŠ€ - http://download.java.net/jdk8/docs/api/ - Collection 클래슀의 stream() λ©”μ†Œλ“œλ₯Ό ν˜ΈμΆœν•˜λ©΄ Stream 객체 생성 - Steam == sequence of elements 38
  • 37. 1. Stream interface λ³€ν™˜ λŒ€μƒ 객체 List<Integer> numbers=Arrays.asList(1,2,3,4,5,6,7,8,9,10); Stream interface 예 public void map(List<Integer> numbers) { System.out.println("map()"); numbers.stream() .map(value -> value *2) .forEach(System.out::println); } 39
  • 38. 2. Stream methods μ£Όμš” λ©”μ†Œλ“œ Method Description filter(Predicate<T> predicate) μ£Όμ–΄μ§„ 쑰건(predicate)에 λ§žλŠ” μš”μ†Œ 리턴 forEach(Consumer<T> action) μ£Όμ–΄μ§„ μž‘μ—…(action) μ‹€ν–‰ map(Function<T,R> mapper) μˆ˜ν–‰λœ μž‘μ—…(mapper)의 κ²°κ³Όλ₯Ό 리턴 reduce(BinaryOperator<T> accumulato reduce μž‘μ—… μˆ˜ν–‰ (항상 μƒˆλ‘œμš΄ 객체 및 κ°’ r) 을 리턴) collect(Collector<? super T,A,R> co mutable reduction μž‘μ—… μˆ˜ν–‰(μˆ˜μ •λœ 객체 llector) 및 값을 리턴) 40
  • 39. 3. Stream 예 filter & forEach numbers.stream() .filter(value -> value %3 == 0) .forEach(System.out::println); 41
  • 40. 3. Stream 예 map & forEach numbers.stream() .map(value -> value *2) .forEach(System.out::println); 42
  • 41. 3. Stream 예 reduce List<String> names= Arrays.asList("God","Of","Java","You","Min","Yeon","Sook"); Optional<String> shortestName = names.stream() .reduce((name1,name2) -> name1.length()<=name2.length() ? name1 : name2 ); Optional<String> longestName = names.stream() .reduce((name1,name2) -> name1.length()>=name2.length() ? name1 : name2 ); System.out.println(shortestName.get()); System.out.println(longestName.get()); 43
  • 43. Conclusion μ„€λͺ…ν•œ λ‚΄μš©μ΄ 이해 μ•ˆλœλ‹€κ³  μ’Œμ ˆν•˜μ§€ 말자 ! - μ–΄μ°¨ν”Ό JDK 8 ReleaseλŠ” λ‚΄λ…„  이해할 μ‹œκ°„μ€ μΆ©λΆ„ν•˜λ‹€. - μ–΄μ°¨ν”Ό Release 된 이후에 μ—¬λŸ¬λΆ„λ“€μ˜ μ‹œμŠ€ν…œμ—μ„œ JDK 8을 μ‚¬μš©ν•˜λ €λ©΄ λ©€μ—ˆλ‹€.  이해할 μ‹œκ°„μ€ 더 μΆ©λΆ„ν•˜λ‹€. κ·Έλ ‡λ‹€κ³  Lambda Expression λ¬΄μ‹œν•˜λ©΄ ? - 3λ…„ 뒀에 λ„νƒœλœλ‹€.  μ½”λ“œλ₯Ό 이해 λͺ»ν•˜κ² μ£ ? 45
  • 44. Conclusion 였늘 μ„€λͺ…ν•œ λ‚΄μš©μ€ λΉ™μ‚°μ˜ 일각일 뿐 - Lambda 및 Bulk Data Operation 에 λŒ€ν•΄μ„œ μžμ„Ένžˆ μ‚΄νŽ΄λ³΄λ €λ©΄ API/Java Tutorial μ°Έκ³  http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html http://docs.oracle.com/javase/tutorial/collections/streams/index.html 46
  • 45. * Lambda reference State of the Lambda - http://cr.openjdk.java.net/~briangoetz/lambda/lambda-libraries-final.html Java Tutorial - http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html Slideshare - http://www.slideshare.net/scottleber/java8-8-lambda-expressions - Marty Hall (slideshare) http://www.slideshare.net/martyhall/java-8-tutorial-streams-part-1 http://www.slideshare.net/martyhall/java-8-tutorial-streams-part-2-mapreduce-parallel-streams-and-infinite-streams http://www.slideshare.net/martyhall/java-8-tutorial-lambda-expressionspart-1 http://www.slideshare.net/martyhall/java-8-tutorial-lambda-expressionspart-2 http://www.slideshare.net/martyhall/java-8-tutorial-lambda-expressions- 47
  • 46. κ°μ‚¬ν•©λ‹ˆλ‹€. 이 λ¬Έμ„œλŠ” λ‚˜λˆ”κΈ€κΌ΄λ‘œ μž‘μ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€. μ„€μΉ˜ν•˜κΈ°