diff --git a/keyword/chapter00/keyword.md b/keyword/chapter00/keyword.md new file mode 100644 index 0000000..3058433 --- /dev/null +++ b/keyword/chapter00/keyword.md @@ -0,0 +1,220 @@ + +# ๐ŸŽฏ ํ•ต์‹ฌ ํ‚ค์›Œ๋“œ + +### **IP** +- ์ธํ„ฐ๋„ท ๋ง ๋‚ด์—์„œ ํŠน์ • ์ปดํ“จํ„ฐ ์‹๋ณ„์ž ์—ญํ• ์„ ํ•œ๋‹ค. +- OSI 7๊ณ„์ธต์—์„œ network Layer์—์„œ ํ•„์š” +- TCP/IP 4๊ณ„์ธต์—์„œ internet Layer์—์„œ ํ•„์š” +--- +### **PORT** +* ํ•˜๋‚˜์˜ ์ปดํ“จํ„ฐ ๋‚ด์—์„œ ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹๋ณ„ํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. +* OSI 7๊ณ„์ธต์—์„œ transport Layer์—์„œ ํ•„์š” +- TCP/IP 4๊ณ„์ธต์—์„œ transport Layer์—์„œ ํ•„์š” +- -- +### **CIDR** +* Classless Inter-Domain Routing + +์ธํ„ฐ๋„ท ์ƒ์˜ ๋ฐ์ดํ„ฐ ๋ผ์šฐํŒ… ํšจ์œจ์„ฑ์„ ํ–ฅ์ƒ์‹œํ‚ค๋Š” **IP ์ฃผ์†Œ ํ• ๋‹น ๋ฐฉ๋ฒ•**์ด๋‹ค. ์กฐ์ง์—์„œ CIDR์„ ์‚ฌ์šฉํ•˜์—ฌ ๋„คํŠธ์›Œํฌ์— ์œ ์—ฐํ•˜๊ณ  ํšจ์œจ์ ์œผ๋กœ IP ์ฃผ์†Œ๋ฅผ ํ• ๋‹นํ•œ๋‹ค. + +**๋‹ค๋ฅธ IP ์ฃผ์†Œํ˜•์‹์œผ๋กœ๋Š” ์–ด๋–ค ๊ฒƒ?** +- ํด๋ž˜์Šค ๊ธฐ๋ฐ˜ ์ฃผ์†Œ ์ง€์ • ์‹œ์Šคํ…œ +- IP ์ฃผ์†Œ๋Š” ๋„คํŠธ์›Œํฌ ์ฃผ์†Œ, ํ˜ธ์ŠคํŠธ ์ฃผ์†Œ๋กœ ๋‚˜๋‰œ๋‹ค. +- ํด๋ž˜์Šค ๊ธฐ๋ฐ˜ ์ฃผ์†Œ ๋ฐฉ์‹์€ ํด๋ž˜์Šค A,B,C๋กœ ๋‚˜๋‰˜์–ด ๋„คํŠธ์›Œํฌ ์ฃผ์†Œ, ํ˜ธ์ŠคํŠธ ์ฃผ์†Œ์˜ ๋น„ํŠธ ์ˆ˜๊ฐ€ ๊ณ ์ •๋œ๋‹ค. + +CIDR์€ ๊ฐ€๋ณ€ ๊ธธ์ด ์„œ๋ธŒ๋„ท ๋งˆ์Šคํ‚น(VLSM)์„ ์‚ฌ์šฉํ•˜์—ฌ ๋„คํŠธ์›Œํฌ ์ฃผ์†Œ์™€ ํ˜ธ์ŠคํŠธ ์ฃผ์†Œ ๋น„ํŠธ ๋น„์œจ์„ ๋ณ€๊ฒฝํ•œ๋‹ค. +์„œ๋ธŒ๋„ท ๋งˆ์Šคํฌ๋Š” ํ˜ธ์ŠคํŠธ ์ฃผ์†Œ๋ฅผ 0์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋„คํŠธ์›Œํฌ ์ฃผ์†Œ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ฐ’์ด๋‹ค. + + +#### CIDR์˜ ์žฅ์  + +- **IP ์ฃผ์†Œ ๋‚ญ๋น„ ๊ฐ์†Œ** + VLSM์„ ์ด์šฉํ•˜์—ฌ ๋„คํŠธ์›Œํฌ ๊ด€๋ฆฌ์ž๋Š” ๋‹ค์–‘ํ•œ ํฌ๊ธฐ์˜ ์„œ๋ธŒ๋„ท์„ ๋ถ€์—ฌ ๊ฐ€๋Šฅํ•˜๋‹ค. ๋„คํŠธ์›Œํฌ ์ฃผ์†Œ ์ ‘๋‘์‚ฌ ๋น„ํŠธ ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์ ‘๋ฏธ์‚ฌ ๊ฐ’์„ ์ผ๋ฐ˜ IP ์ฃผ์†Œ์— ์ถ”๊ฐ€ํ•œ๋‹ค. + ex. 192.0.2.0/24 + 192.0.2 -> ๋„คํŠธ์›Œํฌ ์ฃผ์†Œ + ํด๋ž˜์Šค ๊ธฐ๋ฐ˜ ๋ฐฐ์น˜๋Š” IP ์ฃผ์†Œ ๊ณต๊ฐ„์˜ ๋‚ญ๋น„๋กœ ์ด์–ด์ง„๋‹ค. CIDR์€ ์ด๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค. ๋„คํŠธ์›Œํฌ ์ฃผ์†Œ์˜ ๊ธธ์ด๋ฅผ ์ง€์ •๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํŠน์ • ๋„คํŠธ์›Œํฌ์— ํ•„์š”ํ•œ IP ์ฃผ์†Œ ๊ฐœ์ˆ˜๋ฅผ ์œ ์—ฐํ•˜๊ฒŒ ํ• ๋‹น ๊ฐ€๋Šฅ ํ•˜๋‹ค. + +- **์Šˆํผ๋„ท์„ ์œ ์—ฐํ•˜๊ฒŒ ์ƒ์„ฑ** + VPC๋Š” ์—ฐ๊ฒฐ๋œ ๋””๋ฐ”์ด์Šค ๊ฐ„์— ๋ฐ์ดํ„ฐ ํŒจํ‚ท์„ ์ „์†กํ•  ๋•Œ CIDR IP ์ฃผ์†Œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. + +---- +### **TCP์™€ UDP ์ฐจ์ด** +* TCP๋Š” IP ๋งŒ์œผ๋กœ ํ†ต์‹ ํ–ˆ์„ ๋•Œ ๋ถ€์กฑํ•œ ์ ์„ ๋ณด์™„ํ•œ๋‹ค. + * ์—ฐ๊ฒฐ ์ง€ํ–ฅ + * ์ˆœ์„œ ๋ณด์žฅ + * ์ „๋‹ฌ ๋ณด์žฅ +* UDP๋Š” TCP์—์„œ ๋งŽ์€ ๊ธฐ๋Šฅ์ด ์ œ์™ธ๋œ๋‹ค. + * IP, Port, Checksum ์ •๋„๋งŒ ํฌํ•จํ•œ๋‹ค. + * application Layer์—์„œ ๋งŽ์€ ๋ถ€๋ถ„์„ ๋‹ด๋‹นํ•ด์•ผ ํ•œ๋‹ค. + +--- +### **Web Server์™€ WAS์˜ ์ฐจ์ด** +- Web Server + - ์ •์  ๋ฆฌ์†Œ์Šค ์ œ๊ณต +- WAS + - ๋™์  ๋ฆฌ์†Œ์Šค ์ œ๊ณต + - Web Server์˜ ๊ธฐ๋Šฅ ์ˆ˜ํ–‰ ๊ฐ€๋Šฅ +* Web Server์™€ WAS์˜ ํ˜ผ์šฉ + * Web Server๋Š” ๋ณด์•ˆ, reverse proxy, ์ •์  ๋ฆฌ์†Œ์Šค ์ œ๊ณต, WAS์˜ ์—๋Ÿฌ ๋ฐœ์ƒ ์‹œ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์—๋Ÿฌ ํŽ˜์ด์ง€ ์ „๋‹ฌ ๋“ฑ ์—ฌ๋Ÿฌ ๊ธฐ๋Šฅ์„ ๋Œ€์‹  ์ˆ˜ํ–‰ํ•œ๋‹ค. + - WAS๋Š” ๋ฌด๊ฒ๊ณ  ์—๋Ÿฌ๊ฐ€ ๋นˆ๋ฒˆํ•˜๋ฉฐ ๋น„์‹ผ ์„œ๋ฒ„์ด๋‹ค. ๋”ฐ๋ผ์„œ WAS๊ฐ€ ํ•  ์ˆ˜ ์žˆ๋”๋ผ๋„, Web Server๊ฐ€ ์ž˜ ๋‹ด๋‹นํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์€ Web Server์—๊ฒŒ ์ฑ…์ž„ ๋ถ„๋ฆฌํ•œ๋‹ค. + +--- +## ์ถ”๊ฐ€ ์ •๋ฆฌ + +### **OSI 7๊ณ„์ธต๊ณผ TCP/IP 4๊ณ„์ธต ๋ชจ๋ธ** + +**์›น ๋ธŒ๋ผ์šฐ์ € ํ†ต์‹ ๊ณผ์ •** +* ํฌ๋กฌ ๋ธŒ๋ผ์šฐ์ € ๊ฒ€์ƒ‰์ฐฝ์—์„œ url ์„ ์ž…๋ ฅ +* ํฌ๋กฌ ๋ธŒ๋ผ์šฐ์ €๋Š” ์ด๋ฅผ ๋„คํŠธ์›Œํฌ์—์„œ http ํ˜•์‹์— ๋งž๊ฒŒ ๋ฐ์ดํ„ฐ ์ƒ์„ฑ +* ์ธํ„ฐ๋„ท์„ ํ†ตํ•ด ๋„ค์ด๋ฒ„ ์„œ๋ฒ„๋กœ ์ „๋‹ฌ๋œ๋‹ค. +* ๋„ค์ด๋ฒ„ ์„œ๋ฒ„๋Š” ์ด ํŒจํ‚ท์„ ํ’€์–ด์„œ, ๋ฐ์ดํ„ฐ๋ฅผ ํ•ด์„ํ•œ๋‹ค. + +**์†ก์‹  ํ˜ธ์ŠคํŠธ** +- ์šฐ๋ฆฌ๋Š” ๋ธŒ๋ผ์šฐ์ €๋ผ๋Š” ์‘์šฉ ๊ณ„์ธต์„ ํ†ตํ•ด์„œ ์š”์ฒญํ•œ๋‹ค. +- ๊ฐ ๋ฐ์ดํ„ฐ๋“ค์€ ์ˆœ์„œ๋ฅผ ์ง€ํ‚ค๋ฉด์„œ ํ•œ ๊ณ„์ธต์”ฉ ๋‚ด๋ ค๊ฐ„๋‹ค. + - ๊ฐ ๊ณ„์ธต์—์„œ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ธฐ์กด ๋ฐ์ดํ„ฐ์— ์ถ”๊ฐ€ํ•˜๋ฉด์„œ ๋‚ด๋ ค๊ฐ„๋‹ค. + +**์ˆ˜์‹  ํ˜ธ์ŠคํŠธ** +- ์ธํ„ฐ๋„ท์„ ํ†ตํ•ด์„œ ์„œ๋ฒ„ ์ปดํ“จํ„ฐ์— ๋ฐ์ดํ„ฐ๊ฐ€ ์ „๋‹ฌ๋œ๋‹ค. +- ๊ทธ๋Ÿฌ๋ฉด ์†ก์‹  ํ˜ธ์ŠคํŠธ์™€ **์—ญ์ˆœ์œผ๋กœ** ๊ฐ ๊ณ„์ธต์—์„œ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ถ„๋ฆฌํ•˜์—ฌ ํ•ด์„ํ•œ๋‹ค. +- ์‹ค์ œ ์„œ๋ฒ„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ๋Š” ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์š”์ฒญํ•œ http ํ˜•์‹์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ์ „๋‹ฌ๋œ๋‹ค. +- ๊ทธ๋ฆฌ๊ณ  http ํ˜•์‹์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์„œ๋ฒ„๊ฐ€ ํ•ด์„ํ•˜๊ณ , ๊ทธ์— ๋”ฐ๋ฅธ ์‘๋‹ต ๋ฉ”์„ธ์ง€๋ฅผ http ํ˜•์‹์œผ๋กœ ๋‹ค์‹œ ๋งŒ๋“ค์–ด์„œ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์‘๋‹ตํ•œ๋‹ค. + + +### ํ”„๋กœํ† ์ฝœ์ด๋ž€? +- ๊ทœ์•ฝ + +๋„คํŠธ์›Œํฌ์—์„œ ํ•„์š”ํ•œ ํ”„๋กœํ† ์ฝœ์€ ํฌ๊ฒŒ HTTP, TCP, UDP ๊ฐ€ ์žˆ์„ ๊ฒƒ์ด๋‹ค. +ํ•ด๋‹น ํ”„๋กœํ† ์ฝœ๋“ค์€ ๊ฐ๊ฐ ๋‹ค๋ฅธ ๊ณ„์ธต์—์„œ ํ•„์š”ํ•œ ๊ทœ์•ฝ์ด๋‹ค. + + + +### OSI 7๊ณ„์ธต ๋ชจ๋ธ์ด๋ž€? +- ๊ฐ ๊ณ„์ธต์—์„œ ํ•ด์•ผํ•  ์ผ์„ ์ฑ…์ž„๋ถ„๋ฆฌํ•œ๋‹ค. + +**์‘์šฉ ๊ณ„์ธต(Application Layer)** +- ์ตœ์ƒ์œ„ ๊ณ„์ธต + +**ํ‘œํ˜„ ๊ณ„์ธต(Presentation Layer)** +- ๊ณ„์ธต ๊ฐ„ ๋ฐ์ดํ„ฐ๋ฅผ ์ ์ ˆํžˆ ํ‘œํ˜„ํ•˜๋Š” ๋ถ€๋ถ„์„ ๋‹ด๋‹นํ•œ๋‹ค. +- ์ด๋ฏธ์ง€๋ฅผ ์••์ถ•, ๋ฐ์ดํ„ฐ๋ฅผ ์•”ํ˜ธํ™” + +**์„ธ์…˜ ๊ณ„์ธต(Session Layer)** +- ํ†ต์‹  ์„ธ์…˜์„ ๊ตฌ์„ฑ + +**์ „์†ก ๊ณ„์ธต(Transport Layer)** +- ์ปดํ“จํ„ฐ๋กœ ๋“ค์–ด์˜จ ๋„คํŠธ์›Œํฌ ๋ฐ์ดํ„ฐ๋ฅผ ์–ด๋Š ํฌํŠธ(์–ด๋Š ํ”„๋กœ์„ธ์Šค)๋กœ ๋ณด๋‚ผ์ง€ ๋‹ด๋‹น +- TCP protocol์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด? + - ์‹ ๋ขฐ์„ฑ ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด์žฅํ•˜๋Š” ์—ญํ•  + - ๋…ผ๋ฆฌ์ ์œผ๋กœ ์—ฐ๊ฒฐ - 3 way handshake + - ๋ฐ์ดํ„ฐ ์ˆœ์„œ ๋ณด์žฅ + +**๋„คํŠธ์›Œํฌ ๊ณ„์ธต(Network Layer)** +- IP ์ฃผ์†Œ๋ฅผ ํ†ตํ•ด ์–ด๋Š ์ปดํ“จํ„ฐ๋กœ ๋ณด๋‚ผ์ง€ ๋‹ด๋‹น + +**๋ฐ์ดํ„ฐ๋งํฌ ๊ณ„์ธต(Data Link Layer)** +- Mac ์ฃผ์†Œ + +**๋ฌผ๋ฆฌ ๊ณ„์ธต(Physical Layer)** +- ๋””์ง€ํ„ธ ์‹ ํ˜ธ + + + +### TCP/IP 4๊ณ„์ธต ๋ชจ๋ธ์ด๋ž€? +- ์‹ค์ œ ๋Œ€๋ถ€๋ถ„์˜ ์ธํ„ฐ๋„ท ํ†ต์‹ ์€ TCP/IP ํ†ต์‹ ์„ ์‚ฌ์šฉํ•œ๋‹ค. OSI 7๊ณ„์ธต์„ ๋‹จ์ˆœํ™” ํ•œ๋‹ค. + +**์‘์šฉ ๊ณ„์ธต(Application Layer)** +- Http, Telnet, ssh, ftp ๊ฐ™์€ ํ”„๋กœํ† ์ฝœ์ด ์—ฌ๊ธฐ์—์„œ ์‚ฌ์šฉ + +> **๊ฐœ์ธ์ ์ธ ์ƒ๊ฐ ์ •๋ฆฌ** +> +> ์šฐ๋ฆฌ๊ฐ€ ๊ฐœ๋ฐœํ•˜๊ณ  ์žˆ๋Š” Spring Boot Server๋Š” tomcat์„ ๋‚ด์žฅํ•˜๊ณ  ์žˆ๋‹ค. +> ๊ฐœ๋ฐœ์ž๋Š” tomcat ๋ฐ Spring Web์„ ๊ธฐ๋Šฅ์„ ์ด์šฉํ•ด ์ฝ”๋“œ ์ˆ˜์ค€์—์„œ Session(tomcat์ด ์ง€์›ํ•˜๋Š” session), Presentation(๋ฐ์ดํ„ฐ ์••์ถ•), Application(thymeleaf, tomcat์˜ ๋ฐ์ดํ„ฐ ์ž…์ถœ๋ ฅ) ๋ฅผ ๊ฑด๋“œ๋ฆด ์ˆ˜ ์žˆ๋‹ค. +> ๊ทธ๋ž˜์„œ ๊ฒฝ๊ณ„๊ฐ€ ๋ชจํ˜ธํ•˜๋‹ค. ๋”ฐ๋ผ์„œ OSI 7 ๊ณ„์ธต์—์„œ 5,6,7์˜ ๊ณ„์ธต์ด ํ•˜๋‚˜๋กœ ํ•ฉ์ณ์ง„ ๊ฒƒ ๊ฐ™๋‹ค. + + +**์ „์†ก ๊ณ„์ธต(Transport Layer)** +- ์‹ ๋ขฐ์„ฑ ์žˆ๋Š” ๋ฐ์ดํ„ฐ ์ „์†ก -> **TCP ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ๋งŒ** +- UDP๋Š” TCP์˜ ๋งŽ์€ ๊ธฐ๋Šฅ๋“ค์ด ์ œ์™ธ๋œ๋‹ค. ์‹ ๋ขฐ์„ฑ์„ ํ™•๋ณดํ•˜์ง€ ๋ชปํ•˜๋ฉฐ Application ๊ณ„์ธต์—์„œ ์ด๋ฅผ ๋‹ด๋‹น ํ•ด์•ผํ•œ๋‹ค. + +**์ธํ„ฐ๋„ท ๊ณ„์ธต(Internet Layer)** +- IP +- ์ปดํ“จํ„ฐ๊ฐ„ ๋ผ์šฐํŒ…์„ ๋‹ด๋‹นํ•œ๋‹ค. + +**๋„คํŠธ์›Œํฌ ์ธํ„ฐํŽ˜์ด์Šค ๊ณ„์ธต(Network Interface Layer)** +- ๋ฌผ๋ฆฌ์  ๊ณ„์ธต + + +### HTTP vs HTTPS +- Application Layer์™€ Transport Layer ์‚ฌ์ด์— SSL/TLS ๊ณ„์ธต์ด ์กด์žฌํ•œ๋‹ค. +- HTTP๋Š” ๋ณด์•ˆ์— ์ทจ์•ฝํ•˜๊ธฐ ๋•Œ๋ฌธ์— HTTPS๊ฐ€ ์ด๋ฅผ ๋ณด์™„ํ•œ๋‹ค. + + +--- +### ์ธํ„ฐ๋„ท +- ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌํ•ด์ฃผ๋Š” ๊ฑฐ๋Œ€ํ•œ network ๋ง + +**์ธํ„ฐ๋„ท ๊ตฌ์„ฑ** +- ์ธํ„ฐ๋„ท์€ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ํ˜•ํƒœ์˜ network์™€ ๊ทธ ์•ˆ์˜ sub-network๋กœ ๊ตฌ์„ฑ๋œ๋‹ค. +- network edge, access network, network core + +**network edge** +- ๋์— ์žˆ๋Š” entity +- end system +- web browser, ์Šค๋งˆํŠธํฐ, ๊ฐœ๋ฐœํ•  server + +**access network** +- internet๊ณผ ์—ฐ๊ฒฐ๋˜๋Š” ์ฒซ ๋ถ€๋ถ„ +- ๋žœ์„ , ์™€์ดํŒŒ์ด ๋“ฑ + +**network core** +- ๋ฐ์ดํ„ฐ๋ฅผ ์‹ค์–ด ๋‚˜๋ฅด๋Š” ์—ญํ•  +- router + +--- +### ์ธํ„ฐ๋„ท ํ†ต์‹  +- end system ๊ฐ„ ๋ฐ์ดํ„ฐ(Packet)๋ฅผ ์ฃผ๊ณ  ๋ฐ›๋Š” ๊ฒƒ +- ์ฃผ๊ณ  ๋ฐ›๋Š” ๋ฐ์ดํ„ฐ ํ˜•์‹์€ TCP or UDP, IPv4 or IPv6 ์— ๋”ฐ๋ผ ํ˜•ํƒœ๊ฐ€ ๋‹ฌ๋ผ์ง„๋‹ค. + +**IP** +- ์ธํ„ฐ๋„ท ์ƒ์—์„œ ๋Œ€์ƒ์„ ์‹๋ณ„ํ•˜๋Š” ์ˆ˜๋‹จ +- ๋ฌธ์ œ์  + - ๋ผ์šฐํ„ฐ๋“ค์€ OSI 7๊ณ„์ธต์—์„œ 3๊ณ„์ธต๊นŒ์ง€๋งŒ ๋ณด๊ณ  ๋ฐ์ดํ„ฐ๋ฅผ ์‘๋‹ต ์š”์ฒญ. + - ํŒจํ‚ท์ด ์†Œ์‹ค๋œ๋‹ค๋ฉด? + +**Port** +- ๊ฐ™์€ IP ๋‚ด ํ”„๋กœ์„ธ์Šค ๊ตฌ๋ถ„ ์šฉ๋„ + +**TCP** +- 3 way-handshake๋ฅผ ํ†ตํ•ด ์ƒํƒœํ™•์ธ์„ ํ•จ์œผ๋กœ์จ ๋…ผ๋ฆฌ์  ์—ฐ๊ฒฐ ํ™•์ธ +- ๋ฐ์ดํ„ฐ ์ „๋‹ฌ ๋ณด์ฆ + - ํŒจํ‚ท์ด ์†์‹ค๋  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•˜๋‹ค๋Š” ๊ฒƒ์„ ์ƒ๋Œ€์—๊ฒŒ ์•Œ๋ ค์คŒ +- ๋ฐ์ดํ„ฐ ์ˆœ์„œ ๋ณด์žฅ + - ํŒจํ‚ท์— sequence number๋ฅผ ๋ถ™ํžˆ๊ณ  ํŒจํ‚ท ๊ฐ„์˜ ์ˆœ์„œ๋ฅผ ํŠน์ •ํ•œ๋‹ค. + - ๋„์ฐฉ ์ˆœ์„œ๊ฐ€ ์ž˜๋ชป๋˜์—ˆ๋‹ค๋ฉด ์ž˜๋ชป๋œ ๊ณณ๋ถ€ํ„ฐ ๋‹ค์‹œ ๋‹ฌ๋ผ๊ณ  ์š”์ฒญํ•œ๋‹ค. + +**UDP** +- IP, PORT, checksum ์ •๋„๋งŒ ์žˆ๋‹ค. +- TCP์™€ ๊ฐ™์€ ๊ณ„์ธต์ด์ง€๋งŒ ๋งŽ์€ ๊ธฐ๋Šฅ์ด ์ œ์™ธ +- Application์—์„œ ๋งŽ์€ ์ œ์–ด๊ฐ€ ํ•„์š” +- HTTP/3๋Š” UDP ๊ธฐ๋ฐ˜ + + +--- +### Web Server์™€ WAS + +**web server** +- ์ •์ ์ธ ์ž์› ์ œ๊ณต +- Apache, Nginx + +**WAS** +- ๋™์  ๋ฆฌ์†Œ์Šค ์ œ๊ณต +- web server ๊ธฐ๋Šฅ๋„ ์ œ๊ณต +- Tomcat + +์š”์ฆ˜์€ web server์™€ WAS๋ฅผ ํ˜ผ์šฉํ•œ๋‹ค. +Web Server๋Š” WAS ์•ž๋‹จ์— ์œ„์น˜ํ•˜์—ฌ ๋งŽ์€ ์—ญํ• ์„ ๋‹ด๋‹นํ•œ๋‹ค. +- reverse proxy +- ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ +- ๋ณด์•ˆ +- ์ •์  ๋ฆฌ์†Œ์Šค ์ œ๊ณต +- WAS ์—๋Ÿฌ ์‹œ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์—๋Ÿฌ ํŽ˜์ด์ง€ ์ œ๊ณต ๋“ฑ \ No newline at end of file diff --git a/keyword/chapter01/keyword.md b/keyword/chapter01/keyword.md new file mode 100644 index 0000000..d75bf4d --- /dev/null +++ b/keyword/chapter01/keyword.md @@ -0,0 +1,124 @@ +# ๐ŸŽฏ ํ•ต์‹ฌ ํ‚ค์›Œ๋“œ + +- ์™ธ๋ž˜ํ‚ค +- ๊ธฐ๋ณธํ‚ค +- ER ๋‹ค์ด์–ด๊ทธ๋žจ +- ๋ณตํ•ฉ ํ‚ค +- ์—ฐ๊ด€๊ด€๊ณ„ +- ์ •๊ทœํ™” +- ๋ฐ˜ ์ •๊ทœํ™” +--- +### **์™ธ๋ž˜ํ‚ค** + +- ํ•œ ํ…Œ์ด๋ธ”์˜ ์ปฌ๋Ÿผ์ด ๋‹ค๋ฅธ ํ…Œ์ด๋ธ”์˜ Uniqueํ•œ Key(๋ณดํ†ต ๊ธฐ๋ณธํ‚ค)๋ฅผ ์ฐธ์กฐ +- ํ…Œ์ด๋ธ” ๊ฐ„ ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ๋‚˜ํƒ€๋ƒ„ +- Nullable + +**ํŠน์ง•** +- ์ฐธ์กฐ ๋ฐ์ดํ„ฐ๊ฐ€ ์‚ญ์ œ๋˜๊ฑฐ๋‚˜, ์ˆ˜์ • ๋ฐœ์ƒ ์‹œ ์—ฐ๊ด€๋œ ํ…Œ์ด๋ธ”์˜ ๋ฐ์ดํ„ฐ๋ฅผ ํ•จ๊ป˜ ์ˆ˜์ •๊ฐ€๋Šฅ + - ex. cascade +- ์—ฐ๊ด€๋œ ํ…Œ์ด๋ธ”์— ์—†๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ์ž…๋ ฅ๋˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ + - ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ + +> ์ฐธ๊ณ : ์™ธ๋ž˜ํ‚ค๋กœ ์ธํ•œ ์„ฑ๋Šฅ์ €ํ•˜๋กœ, ํ˜„์—…์—์„œ๋Š” ์™ธ๋ž˜ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๋‹ค. + + +--- +### **๊ธฐ๋ณธํ‚ค** + +- ๊ฐ ํ–‰์—์„œ Unique ํ•˜๊ฒŒ ์‹๋ณ„ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ’ +- Not Null +- ์ฃผ๋กœ ์ธ์กฐํ‚ค๋ฅผ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉ + +- -- +### **ER ๋‹ค์ด์–ด๊ทธ๋žจ** + +- ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์„ค๊ณ„ ์‹œ ์‚ฌ์ „์— ๊ทธ๋ฆฌ๋Š” diagram +- ์‹ค์ œ ๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ์ฒญ์‚ฌ์ง„ + +**๊ตฌ์„ฑ์š”์†Œ** +- **entity** + - ํ…Œ์ด๋ธ”์— ๋Œ€์‘ +- **attritbute** + - ํ…Œ์ด๋ธ” ๋‚ด์˜ ์ปฌ๋Ÿผ์— ๋Œ€์‘ +- **relationship** + - ์—”ํ„ฐํ‹ฐ ๊ฐ„ ์—ฐ๊ด€์„ฑ + - entity ๊ฐ„ ์ƒํ˜ธ์ž‘์šฉ + +--- +### ๋ณตํ•ฉ ํ‚ค +- ๋‘ ๊ฐœ ์ด์ƒ์˜ ์ปฌ๋Ÿผ์„ ์กฐํ•ฉํ•œ **๊ณ ์œ  ์‹๋ณ„์ž** +- ํ•˜๋‚˜์˜ ์ปฌ๋Ÿผ๋งŒ์œผ๋กœ ๊ณ ์œ ์„ฑ์„ ๋ณด์žฅ ๋ชปํ•  ๋•Œ ์‚ฌ์šฉ ๊ฐ€๋Šฅ + +---- +### **์—ฐ๊ด€๊ด€๊ณ„** +- ํ…Œ์ด๋ธ” ๊ฐ„ ์ƒํ˜ธ์ž‘์šฉ์„ ์ •์˜ +- ์ฃผ๋กœ ์™ธ๋ž˜ํ‚ค๋ฅผ ํ†ตํ•ด ๊ตฌํ˜„ + +**์ข…๋ฅ˜** +- **1:1** + - ํ•œ ์—”ํ„ฐํ‹ฐ๊ฐ€ ๋‹ค๋ฅธ ํ•˜๋‚˜์˜ ์—”ํ„ฐํ‹ฐ๋งŒ์„ ๊ฐ€์งˆ ๋•Œ + - ํ•˜๋‚˜์˜ ํ…Œ์ด๋ธ”์„ ๊ณจ๋ผ์„œ ์™ธ๋ž˜ํ‚ค ์„ค์ • + +- **1:N** + - ํ•œ ์—”ํ„ฐํ‹ฐ๊ฐ€ ๋‹ค๋ฅธ ์—”ํ„ฐํ‹ฐ๋ฅผ ์—ฌ๋Ÿฌ ๊ฐœ ๊ฐ€์งˆ ๋•Œ + - ํ•˜๋‚˜์˜ ํ…Œ์ด๋ธ”์„ ๊ณจ๋ผ์„œ ์™ธ๋ž˜ํ‚ค ์„ค์ • + +- **N:M** + - ํ•˜๋‚˜์˜ ์—”ํ„ฐํ‹ฐ๋Š” ๋‹ค๋ฅธ ์—”ํ„ฐํ‹ฐ๋ฅผ ์—ฌ๋Ÿฌ๊ฐœ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๊ณ , ๊ทธ์˜ ์—ญ๋„ ์กด์žฌํ•  ๋•Œ + - ๋ณดํ†ต ์ƒˆ๋กœ์šด ์—ฐ๊ด€๊ด€๊ณ„ ํ…Œ์ด๋ธ”์„ ์ƒ์„ฑํ•˜์—ฌ ๋‘ ๊ฐœ์˜ 1:N ๊ด€๊ณ„๋กœ ํ’€์–ด๋‚ธ๋‹ค. + +**์—ฐ๊ด€๊ด€๊ณ„ ๊ด€๋ฆฌ ์ข…๋ฅ˜** +- ๋‹จ๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„ +- ์–‘๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„ + +--- +### **์ •๊ทœํ™”** + +- **๋ชฉ์ ** + - ์ค‘๋ณต ์ œ๊ฑฐ + - ์ค‘๋ณต์ด ์žˆ์œผ๋ฉด, ์ˆ˜์ • ์‹œ ์ผ๊ด€์„ฑ์žˆ๋Š” ๋ฐ์ดํ„ฐ ์œ ์ง€ํ•˜๊ธฐ ์–ด๋ ค์›€ + - ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ ์œ ์ง€ + - ๋ฐ์ดํ„ฐ ๋ณ€๊ฒฝ ์‹œ ๋ฐœ์ƒํ•˜๋Š” ์ด์ƒ ํ˜„์ƒ์„ ๋ฐฉ์ง€ + +- **์ด์ƒ ํ˜„์ƒ** + - ๋ณดํ†ต ๋ฐ์ดํ„ฐ์˜ ์ค‘๋ณต์œผ๋กœ ๋ฐœ์ƒ + - ์‚ฝ์ž…, ๊ฐฑ์‹ , ์‚ญ์ œ ์‹œ ์ •๊ทœํ™”๋˜์ง€ ์•Š์€ ๋ฐ์ดํ„ฐ๋กœ ์ธํ•ด ๋ฐœ์ƒํ•˜๋Š” ์˜๋„์น˜ ์•Š์€ ์ƒํ™ฉ์„ ์˜๋ฏธ + +- **๋‹จ๊ณ„** + - **1NF** + - ๊ฐ ์ปฌ๋Ÿผ์ด ๋” ์ด์ƒ ๋ถ„ํ•ด๋˜์ง€ ์•Š์Œ + - **2NF** + - 1NF ๋งŒ์กฑ + - ๋ถ€๋ถ„ ํ•จ์ˆ˜ ์ข…์†์„ฑ์„ ์ œ๊ฑฐ + - **3NF** + - 2NF ๋งŒ์กฑ + - ์ดํ–‰์  ์ข…์†์„ฑ์„ ์ œ๊ฑฐ + - ๊ธฐ๋ณธ ํ‚ค๊ฐ€ ์•„๋‹Œ ์ปฌ๋Ÿผ์ด ๊ธฐ๋ณธ ํ‚ค๊ฐ€ ์•„๋‹Œ ์ปฌ๋Ÿผ์— ์ข…์†๋˜์ง€ ์•Š์•„์•ผํ•œ๋‹ค. + - **BCNF** + - 3NF ๋งŒ์กฑ + - ํ›„๋ณดํ‚ค์— ์˜ํ•œ ํ•จ์ˆ˜ ์ข…์†์„ฑ ์ œ๊ฑฐ + +> ์ฐธ๊ณ : **๋ถ€๋ถ„ํ•จ์ˆ˜ ์ข…์†์„ฑ** +> ๊ธฐ๋ณธํ‚ค์˜ ์ผ๋ถ€์— ์ข…์†๋˜๋Š” ์ปฌ๋Ÿผ์ด ์žˆ๋Š” ์ƒํ™ฉ + +> ์ฐธ๊ณ : **์ดํ–‰์  ์ข…์†์„ฑ** +> ๊ธฐ๋ณธํ‚ค๊ฐ€ ์•„๋‹Œ ์†์„ฑ์ด ๋‹ค๋ฅธ ์†์„ฑ์— ์ข…์†์„ฑ์„ ๊ฐ€์งˆ ๋•Œ + +- **์ฃผ์˜์‚ฌํ•ญ** + - ์ง€๋‚˜์นœ ์ •๊ทœํ™”๋Š” Join์œผ๋กœ ์ธํ•œ ๋ณต์žกํ•œ ์ฟผ๋ฆฌ๊ฐ€ ํ•„์š”ํ•˜๊ณ , ์„ฑ๋Šฅ์ €ํ•˜๋กœ ์ด์–ด์ง + - ๋”ฐ๋ผ์„œ ์กฐํšŒ ์„ฑ๋Šฅ์„ ํ–ฅ์ƒ ์‹œํ‚ค๊ธฐ ์œ„ํ•ด ๋ฐ˜์ •๊ทœํ™”๊ฐ€ ๊ฐ€๋Šฅ + +--- + +### **๋ฐ˜์ •๊ทœํ™”** +- ์ •๊ทœํ™”๋œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ๋ณต์žกํ•œ Join ์—ฐ์‚ฐ์œผ๋กœ ์ธํ•ด ์„ฑ๋Šฅ์ €ํ•˜ ์‹œ ๊ณ ๋ ค +- ํ…Œ์ด๋ธ” ๋ณ‘ํ•ฉ +- ์ปฌ๋Ÿผ์œผ๋กœ ๊ณ„์‚ฐ๋œ ๊ฐ’ ๋ฐ ์ค‘๋ณต๋œ ๊ฐ’์„ ์ถ”๊ฐ€ + +**๋ชฉ์ ** +- Query ์„ฑ๋Šฅ ์ตœ์ ํ™” + + +**๊ณ ๋ ค์‚ฌํ•ญ** +- ๋ฐ์ดํ„ฐ ์ค‘๋ณต ๋ฐ ์ด์ƒํ˜„์ƒ ๋ฐœ์ƒ ๊ฐ€๋Šฅ \ No newline at end of file diff --git a/keyword/chapter03/keyword.md b/keyword/chapter03/keyword.md new file mode 100644 index 0000000..c89210d --- /dev/null +++ b/keyword/chapter03/keyword.md @@ -0,0 +1,159 @@ +# REST API + +๊ธฐ๋ณธ์ ์œผ๋กœ API๋ฅผ ์„ค๊ณ„ํ•  ๋•Œ, **๋ฆฌ์†Œ์Šค๋ฅผ ์‹๋ณ„ํ•˜๊ณ , URI ๊ณ„์ธต ๊ตฌ์กฐ๋ฅผ ํ™œ์šฉ**ํ•œ๋‹ค. +๋ฆฌ์†Œ์Šค์™€ ํ–‰์œ„๋ฅผ ๋ถ„๋ฆฌํ•˜๋ผ. ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ฒƒ์€ ๋ฆฌ์†Œ์Šค๋ฅผ ์‹๋ณ„ํ•˜๋Š” ๊ฒƒ. +๋ฆฌ์†Œ์Šค์™€ ํ•ด๋‹น ๋ฆฌ์†Œ์Šค๋ฅผ ๋Œ€์ƒ์œผ๋กœ ํ•˜๋Š” ํ–‰์œ„๋ฅผ ๋ถ„๋ฆฌํ•˜๋ผ. +๊ทธ๋ ‡๋‹ค๋ฉด ์ด ํ–‰์œ„๋Š” ์–ด๋–ป๊ฒŒ ๊ตฌ๋ถ„ํ• ๊นŒ? ๋ฐ”๋กœ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค. + + +## HTTP ๋ฉ”์„œ๋“œ ์ข…๋ฅ˜ +- GET + - ๋ฆฌ์†Œ์Šค ์กฐํšŒ + - ์„œ๋ฒ„์— ์ „๋‹ฌํ•˜๊ณ  ์‹ถ์€ ๋ฐ์ดํ„ฐ๋Š” query(์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ, ์ฟผ๋ฆฌ์ŠคํŠธ๋ง)์„ ํ†ตํ•ด์„œ ์ „๋‹ฌ + - ๋ฉ”์„ธ์ง€ ๋ฐ”๋””๊ฐ€ ๊ฐ€๋Šฅ์€ ํ•˜์ง€๋งŒ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ๊ณณ์ด ๋งŽ์•„์„œ ๊ถŒ์žฅํ•˜์ง€ ์•Š๋Š”๋‹ค. +- POST + - ๋ฉ”์„ธ์ง€ ๋ฐ”๋””๋ฅผ ํ†ตํ•ด ์„œ๋ฒ„๋กœ ์š”์ฒญ ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌ + - ์„œ๋ฒ„๋Š” ์š”์ฒญ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌ + - ๋งŒ๋Šฅ -> ์š”์ฒญ ๋ฐ์ดํ„ฐ๋ฅผ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•  ์ง€ ์ •ํ•ด์ง„ ๊ฒƒ์ด ์—†์Œ + - ์ปจํŠธ๋กค URI + - ๋‹ค๋ฅธ ๋ฉ”์„œ๋“œ๋กœ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์• ๋งคํ•œ ๊ฒฝ์šฐ์—๋„ ์‚ฌ์šฉ +- PUT + - ๋ฆฌ์†Œ์Šค๋ฅผ ๋Œ€์ฒด, ํ•ด๋‹น ๋ฆฌ์†Œ์Šค๊ฐ€ ์—†์œผ๋ฉด ์ƒ์„ฑ, ์‰ฝ๊ฒŒ ์ด์•ผ๊ธฐ ํ•ด์„œ ๋ฎ์–ด์“ฐ๊ธฐ + - **ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋ฆฌ์†Œ์Šค ์œ„์น˜๋ฅผ ์•Œ๊ณ  URI ์ง€์ •** + - ์ด๊ฒŒ POST์™€์˜ ์ฐจ์ด์  +- PATCH + - ๋ฆฌ์†Œ์Šค ๋ถ€๋ถ„ ๋ณ€๊ฒฝ +- DELETE + - ๋ฆฌ์†Œ์Šค ์‚ญ์ œ +- HEAD + - GET๊ณผ ๋™์ผํ•˜์ง€๋งŒ, ๋ฉ”์„ธ์ง€ ๋ถ€๋ถ„์ด ์—†๊ณ  ์ƒํƒœ ์ค„๊ณผ ํ—ค๋”๋งŒ ๋ฐ˜ํ™˜ +- OPTIONS + - ๋Œ€์ƒ ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•œ ํ†ต์‹  ๊ฐ€๋Šฅ ์˜ต์…˜(๋ฉ”์„œ๋“œ)๋ฅผ ์„ค๋ช… + - ์ฃผ๋กœ CORS์—์„œ ์‚ฌ์šฉ +- CONNECT + - ๋Œ€์ƒ ๋ฆฌ์†Œ์Šค๋กœ ์‹๋ณ„๋˜๋Š” ์„œ๋ฒ„์— ๋Œ€ํ•œ ํ„ฐ๋„์„ ์„ค์ • +- TRACE + - ๋Œ€์ƒ ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•œ ๊ฒฝ๋กœ๋ฅผ ๋”ฐ๋ผ ๋ฉ”์„ธ์ง€ ๋ฃจํ”„๋ฐฑ ํ…Œ์ŠคํŠธ๋ฅผ ์ˆ˜ํ–‰ + + + +## HTTP ๋ฉ”์„œ๋“œ์˜ ์†์„ฑ +- ์•ˆ์ „ + - ํ˜ธ์ถœํ•ด๋„ ๋ฆฌ์†Œ์Šค๋ฅผ **๋ณ€๊ฒฝํ•˜์ง€ ์•Š๋Š”๋‹ค.** +- ๋ฉฑ๋“ฑ + - ์—ฌ๋Ÿฌ ๋ฒˆ ํ˜ธ์ถœํ•ด๋„ ๊ฒฐ๊ณผ๊ฐ€ ๋˜‘๊ฐ™๋‹ค + - GET -> O + - PUT -> O + - DELETE -> O + - POST -> X + - ์ž๋™ ๋ณต๊ตฌ ๋ฉ”์ปค๋‹ˆ์ฆ˜ + - ์„œ๋ฒ„๊ฐ€ ์ •์ƒ์‘๋‹ต์„ ๋ชป์ฃผ์—ˆ์„ ๋•Œ ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๊ฐ™์€ ์š”์ฒญ์„ ๋‹ค์‹œ ํ•ด๋„ ๋˜๋Š”๊ฐ€? + - ์™ธ๋ถ€ ์š”์ธ์œผ๋กœ ์ค‘๊ฐ„์— ๋ฆฌ์†Œ์Šค๊ฐ€ ๋ณ€๊ฒฝ๋˜๋Š” ๊ฒƒ๊นŒ์ง€๋Š” ๊ณ ๋ คํ•˜์ง€ ์•Š๋Š”๋‹ค. +- ์บ์‹œ๊ฐ€๋Šฅ + - ์‘๋‹ต ๊ฒฐ๊ณผ ๋ฆฌ์†Œ์Šค๋ฅผ ์บ์‹œํ•ด์„œ ์‚ฌ์šฉํ•ด๋„ ๋˜๋Š”๊ฐ€? + - GET, HEAD, POST, PATCH ์บ์‹œ ๊ฐ€๋Šฅ + - ์‹ค์ œ๋กœ๋Š” GET, HEAD ์ •๋„๋งŒ ์บ์‹œ๋กœ ์‚ฌ์šฉ + - POST, PATCH๋Š” ๋ณธ๋ฌธ ๋‚ด์šฉ๊นŒ์ง€ ์บ์‹œ ํ‚ค๋กœ ๊ณ ๋ คํ•ด์•ผํ•˜๋Š”๋ฐ, ๊ตฌํ˜„์ด ์‰ฝ์ง€ ์•Š์Œ + + +## HTTP ๋ฉ”์„œ๋“œ ํ™œ์šฉ + +**๋ฐ์ดํ„ฐ ์ „๋‹ฌ๋ฐฉ์‹์€ ํฌ๊ฒŒ 2๊ฐ€์ง€** +- ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ํ†ตํ•œ ๋ฐ์ดํ„ฐ ์ „์†ก + - GET + - ์ฃผ๋กœ ์ •๋ ฌ ํ•„ํ„ฐ(๊ฒ€์ƒ‰์–ด) +- ๋ฉ”์„ธ์ง€ ๋ฐ”๋””๋ฅผ ํ†ตํ•œ ๋ฐ์ดํ„ฐ ์ „์†ก + - POST, PUT, PATCH + - ํšŒ์› ๊ฐ€์ž…, ์ƒํ’ˆ ์ฃผ๋ฌธ, ๋ฆฌ์†Œ์Šค ๋“ฑ๋ก, ๋ฆฌ์†Œ์Šค ๋ณ€๊ฒฝ โ€ฆ + +**ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์„œ๋ฒ„์—๊ฒŒ ์š”์ฒญํ•˜๋Š” ๋ฐฉ์‹์€ ํฌ๊ฒŒ 4๊ฐ€์ง€** +- ์ •์  ๋ฐ์ดํ„ฐ ์กฐํšŒ + - ์ด๋ฏธ์ง€, ์ •์  ํ…์ŠคํŠธ ๋ฌธ์„œ + - GET + - ์ผ๋ฐ˜์ ์œผ๋กœ ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ ์—†์ด ๋ฆฌ์†Œ์Šค ๊ฒฝ๋กœ๋กœ ๋‹จ์ˆœํ•˜๊ฒŒ ์กฐํšŒ ๊ฐ€๋Šฅ +- ๋™์  ๋ฐ์ดํ„ฐ ์กฐํšŒ + - ์ฃผ๋กœ ๊ฒ€์ƒ‰, ๊ฒŒ์‹œํŒ ๋ชฉ๋ก์—์„œ ์ •๋ ฌ ํ•„ํ„ฐ(๊ฒ€์ƒ‰์–ด) + - ์กฐํšŒ ์กฐ๊ฑด์„ ์ค„์—ฌ์ฃผ๋Š” ํ•„ํ„ฐ, ์กฐํšŒ ๊ฒฐ๊ณผ๋ฅผ ์ •๋ ฌํ•˜๋Š” ์ •๋ ฌ ์กฐ๊ฑด์— ์ฃผ๋กœ ์‚ฌ์šฉ + - GET + - ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌ +- HTML FORM์„ ํ†ตํ•œ ๋ฐ์ดํ„ฐ ์ „์†ก + - GET, POST๋งŒ ์ง€์› + - GET + - ์กฐํšŒ ๊ฐ€๋Šฅ + - ์ „์†ก ๋ฐ์ดํ„ฐ๋ฅผ url encoding ์ฒ˜๋ฆฌํ•œ๋‹ค. + - ์˜ˆ) abc๊น€ -> abc%EA%B9%80 + - POST + - ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ์™€ ๊ฐ™์€ ํ˜•์‹(key,value)์˜ ๋ฐ์ดํ„ฐ๊ฐ€ Body์— ํฌํ•จ๋˜์–ด ์ „๋‹ฌ๋œ๋‹ค. + - ํŒŒ์ผ์—…๋กœ๋“œ + - POST + - multipart/form-data + - ๋‹ค๋ฅธ ์ข…๋ฅ˜์˜ ์—ฌ๋Ÿฌ ํŒŒ์ผ๊ณผ ํผ์˜ ๋‚ด์šฉ ํ•จ๊ป˜ ์ „์†ก + + +- HTML API๋ฅผ ํ†ตํ•œ ๋ฐ์ดํ„ฐ ์ „์†ก + - ์„œ๋ฒ„ to ์„œ๋ฒ„ + - ๋ฐฑ์—”๋“œ ์‹œ์Šคํ…œ ํ†ต์‹  + - ์•ฑ ํด๋ผ์ด์–ธํŠธ + - ์›น ํด๋ผ์ด์–ธํŠธ + - React, VueJs ๊ฐ™์€ ์›น ํด๋ผ์ด์–ธํŠธ์™€ API ํ†ต์‹  + - ์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ†ตํ•œ ํ†ต์‹  (Ajax) + + +## HTTP API ์„ค๊ณ„ ์˜ˆ์‹œ +- HTTP API - ์ปฌ๋ ‰์…˜ + - POST ๊ธฐ๋ฐ˜ ๋“ฑ๋ก + - ๋ณดํ†ต ์ปฌ๋ ‰์…˜ ์‚ฌ์šฉ +- HTTP API - ์Šคํ† ์–ด + - PUT ๊ธฐ๋ฐ˜ ๋“ฑ๋ก + - ์ •์  ์ปจํ…์ธ , ์›๊ฒฉ ํŒŒ์ผ ๊ด€๋ฆฌ +- HTML FORM + - ์›น ํŽ˜์ด์ง€ + - GET, POST๋งŒ ์ง€์› + + +**ํšŒ์› ๊ด€๋ฆฌ ์‹œ์Šคํ…œ ์˜ˆ์‹œ** + +1. API ์„ค๊ณ„ - POST ๊ธฐ๋ฐ˜ ๋“ฑ๋ก (**์ปฌ๋ ‰์…˜**) -> ์ฃผ๋กœ ์‚ฌ์šฉ +- ํšŒ์› ๋ชฉ๋ก + - GET + - /members +- ํšŒ์› ๋“ฑ๋ก + - POST + - /members + - **์„œ๋ฒ„๊ฐ€ ์ƒˆ๋กœ ๋“ฑ๋ก๋œ ๋ฆฌ์†Œ์Šค URI์„ ๊ด€๋ฆฌํ•œ๋‹ค.** + - ex. Location: /members/100 +- ํšŒ์› ์กฐํšŒ + - GET + - /members/{id} +- ํšŒ์› ์ˆ˜์ • + - PATCH, PUT, POST + - members/{id} +- ํšŒ์› ์‚ญ์ œ + - DELETE + - members/{id} + +์ปฌ๋ ‰์…˜์€ ์„œ๋ฒ„๊ฐ€ ๊ด€๋ฆฌํ•˜๋Š” ๋ฆฌ์†Œ์Šค ๋””๋ ‰ํ† ๋ฆฌ์ด๋‹ค. ์„œ๋ฒ„๊ฐ€ ๋ฆฌ์†Œ์Šค์˜ URI์„ ์ƒ์„ฑํ•˜๊ณ  ๊ด€๋ฆฌํ•œ๋‹ค. +์—ฌ๊ธฐ์„œ ์ปฌ๋ ‰์…˜์€ /members ์ด๋‹ค. + + +2. API ์„ค๊ณ„ - PUT ๊ธฐ๋ฐ˜ ๋“ฑ๋ก (**์Šคํ† ์–ด**) + +- ํŒŒ์ผ ๋ชฉ๋ก + - GET + - /files +- ํŒŒ์ผ ์กฐํšŒ + - GET + - /files/{filename} +- ํŒŒ์ผ ๋“ฑ๋ก + - PUT + - /files/{filename} +- ํŒŒ์ผ ์‚ญ์ œ + - DELETE + - /files/{filename} +- ํŒŒ์ผ ๋Œ€๋Ÿ‰ ๋“ฑ๋ก + - POST + - /files + +ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋ฆฌ์†Œ์Šค URI์„ ์•Œ๊ณ  ์žˆ์–ด์•ผ ํ•œ๋‹ค. +**ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์ง์ ‘ ๋ฆฌ์†Œ์Šค์˜ URI์„ ์ง€์ •ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.** +์ฆ‰, ์Šคํ† ์–ด๋Š” ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๊ด€๋ฆฌํ•˜๋Š” ๋ฆฌ์†Œ์Šค ์ €์žฅ์†Œ์ด๋‹ค. \ No newline at end of file diff --git a/keyword/chapter05/keyword.md b/keyword/chapter05/keyword.md new file mode 100644 index 0000000..ab26fbe --- /dev/null +++ b/keyword/chapter05/keyword.md @@ -0,0 +1,50 @@ +### Domain +๋„๋ฉ”์ธ์˜ ์ •์˜๋Š” ๋ณดํ†ต ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง๊ณผ ๊ด€๋ จ๋œ ๊ฐ์ฒด๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. +Java๋Š” ๊ฐ์ฒด์ง€ํ–ฅ ์–ธ์–ด๋กœ ๊ฐ์ฒด์ง€ํ–ฅ์ ์œผ๋กœ ์ž‘์„ฑ๋œ ํ”„๋กœ๊ทธ๋žจ์˜ ๊ฐ์ฒด๋ฅผ ๋ณดํ†ต Domain์ด๋ผ๊ณ  ์นญํ•ฉ๋‹ˆ๋‹ค. + +Spring Boot + RDBMS ๋กœ ๊ฐœ๋ฐœ์„ ์ง„ํ–‰ํ•  ๋•Œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. +๋ณดํ†ต ํŽธ๋ฆฌํ•œ Mapping์„ ์œ„ํ•ด์„œ Table ํ˜•์‹์— ๋งž๊ฒŒ Java ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด์„œ ์กฐํšŒ๋ฅผ ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. +Table ํ˜•ํƒœ์™€ ๊ฐ์ฒด์ง€ํ–ฅ์˜ Domain ํ˜•ํƒœ๋Š” ๋ชฉ์ ์ด ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ๊ฐ์˜ ํ˜•ํƒœ๊ฐ€ ๋ถˆ์ผ์น˜ํ•  ์ˆ˜ ๋ฐ–์— ์—†์Šต๋‹ˆ๋‹ค. + +์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ ๋งŒ๋“ค์–ด์ง„ ๊ธฐ์ˆ ์ด ๋ฐ”๋กœ ORM ์ž…๋‹ˆ๋‹ค. ๋Œ€ํ‘œ์ ์œผ๋กœ Spring์—๋Š” JPA ๊ธฐ์ˆ ์„ ์‚ฌ์šฉํ•˜๋Š”๋ฐ, +ORM์„ ์‚ฌ์šฉํ•จ์œผ๋กœ์จ Domain ๊ฐ์ฒด๋ฅผ RDBMS์˜ table์— ์ž˜ ๋งคํ•‘ํ•˜๋ฉด ์ด ๋‘˜์˜ ๋ถ€์กฐํ™”๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +### ์–‘๋ฐฉํ–ฅ ๋งคํ•‘ + +Spring ORM ๊ธฐ์ˆ ์ธ JPA๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์„œ๋กœ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ๋Š” mapping ๊ธฐ์ˆ ์ž…๋‹ˆ๋‹ค. + +์˜ˆ๋ฅผ ๋“ค์–ด, `Member`์™€ `Team`์ด๋ผ๋Š” Table์ด ์กด์žฌํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค. RDBMS์˜ ๊ด€์ ์œผ๋กœ ๋ฐ”๋ผ๋ณด๋ฉด, `Member` : `Team` ์€ **N:1** ์˜ ๊ด€๊ณ„์ž…๋‹ˆ๋‹ค. Member table์— Team์˜ foregin key๊ฐ€ ์กด์žฌํ•œ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +์ด ๋•Œ, ๋‹จ๋ฐฉํ–ฅ ๋งคํ•‘๋งŒ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด `Member` ๊ฐ์ฒด์— `Team`์ด๋ผ๋Š” ๊ฐ์ฒด๋งŒ ์ƒ์„ฑ๋˜๊ณ , `Team`์ด๋ผ๋Š” ๊ฐ์ฒด์—๋Š” `Member`์™€ ๊ด€๋ จ๋œ ์ •๋ณด๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +๋งŒ์•ฝ `Team`์—๋„ `List` ์™€ ๊ฐ™์€ ์ž๋ฃŒํ˜•์„ ํ†ตํ•ด ํ•ด๋‹น ํŒ€์— ์กด์žฌํ•˜๋Š” Member๋“ค์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํ˜•ํƒœ๋ฅผ ์›ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๋ฐ”๋กœ ์–‘๋ฐฉํ–ฅ ๋งคํ•‘์ž…๋‹ˆ๋‹ค. + +์–‘๋ฐฉํ–ฅ ๋งคํ•‘์€ ์ฃผ์˜ํ•  ์ ์ด ์กด์žฌํ•˜๋Š”๋ฐ, ๋ฌดํ•œ๋ฃจํ”„๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. `toString()`, `equals()`, `hashCode()` ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์ฃผ์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์กฐํšŒํ•  ๋•Œ ๋˜ํ•œ ๋ฌดํ•œ ๋ฃจํ”„๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ ์ฃผ์˜ํ•˜์—ฌ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +์–‘๋ฐฉํ–ฅ ๋งคํ•‘์€ `mappedBy` ๋ฅผ ํ†ตํ•ด ์—ฐ๊ด€๊ด€๊ณ„์˜ ์ฃผ์ธ์„ ์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์œ„์˜ ์˜ˆ์‹œ๋ฅผ ๋‹ค์‹œ ๊ฐ€์ ธ์˜จ๋‹ค๋ฉด Team์— `List`๊ฐ€ ์กด์žฌํ•  ๋•Œ, `mappedBy = team` ์„ `@OneToMany` ์˜ ์–ด๋…ธํ…Œ์ด์…˜์— ์ ์–ด์ค€๋‹ค๋ฉด ์–ด๋–ค ์ผ์ด ์ผ์–ด๋‚ ๊นŒ์š”? + +์œ„์˜ ์˜๋ฏธ๋Š” `Member` ๊ฐ์ฒด์— ์žˆ๋Š” `Team team`์— ๋”ฐ๋ผ์„œ `List` ๊ฐ€ ๊ฑฐ์šธ์ฒ˜๋Ÿผ ์‚ฌ์šฉ๋œ๋‹ค๋Š” ๊ฒƒ์œผ๋กœ Member๊ฐ€ ์—ฐ๊ด€๊ด€๊ณ„์˜ ์ฃผ์ธ์ด ๋˜์–ด Member์˜ Team team์„ ์ˆ˜์ •ํ•ด์•ผ๋งŒ ์—ฐ๊ด€๊ด€๊ณ„๊ฐ€ ์ˆ˜์ •๋  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. `Team` ๊ฐ์ฒด์˜ `List`๋ฅผ ์ˆ˜์ •ํ•˜๋”๋ผ๋„ ์—ฐ๊ด€๊ด€๊ณ„๋Š” ๋ณ€๋™๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +cascade ์˜ต์…˜๋„ ์•Œ์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ALL๋กœ ์„ค์ •์ด ๋˜์–ด์žˆ๋‹ค๋ฉด ์œ„์˜ ์˜ˆ์‹œ์—์„œ Team์„ ์‚ญ์ œํ•˜๋ฉด Team์— ์†Œ์†๋œ Member๋“ค์ด ์‚ญ์ œ๋˜๋Š” ํ˜„์ƒ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋งค์šฐ ์ฃผ์˜ํ•ด์„œ ์‚ฌ์šฉํ•ด์•ผํ•˜๋Š” ์˜ต์…˜์ž…๋‹ˆ๋‹ค. + + +### N + 1 ๋ฌธ์ œ + +ํ•˜๋‚˜์˜ ์ฟผ๋ฆฌ๋กœ ์ธํ•ด์„œ N๊ฐœ์˜ ์ฟผ๋ฆฌ๊ฐ€ ์ˆ˜ํ–‰๋˜์–ด ์„ฑ๋Šฅ์ €ํ•˜๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ์„ N+1 ๋ฌธ์ œ๋ผ๊ณ  ์ด์•ผ๊ธฐ ํ•ฉ๋‹ˆ๋‹ค. +JPA๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด N + 1 ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +์˜ˆ๋ฅผ ๋“ค์–ด Member์™€ Team์˜ ์˜ˆ์‹œ๋กœ ๋‹ค์‹œ ๊ฐ€๋ณด๋ฉด, ๋งŒ์•ฝ ๋ชจ๋“  Member๋“ค์„ ์กฐํšŒํ•˜๋Š” ์ฟผ๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ–ˆ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ด๋•Œ Lazy ๋กœ๋”ฉ ๋ฐฉ์‹์œผ๋กœ ์„ค์ •ํ•ด๋†“์€ ์ƒํ™ฉ์ž…๋‹ˆ๋‹ค. + +Lazy ๋กœ๋”ฉ์œผ๋กœ ํ•˜์˜€์„ ๋•Œ๋Š”, Member์˜ Team ๊ฐ์ฒด๋Š” ํ”„๋ก์‹œ๋กœ ๋“ค์–ด๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ ๊ฐ€์ ธ์˜จ ๋ชจ๋“  Member list๋ฅผ for๋ฌธ์„ ๋Œ๋ฉด์„œ Team์˜ ํ•„๋“œ์— ์ ‘๊ทผํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด ์ด ๋•Œ ์ง€์—ฐ๋กœ๋”ฉ์ด ์ˆ˜ํ–‰๋˜๋ฉด์„œ JPA๋Š” DB์— ์ ‘๊ทผํ•ด Team์„ ์กฐํšŒํ•ด์„œ ๊ฐ€์ ธ์˜ค๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. Member๊ฐ€ 10000๋ช…์ด๋ผ๋ฉด 10000๋ฒˆ์˜ ์ฟผ๋ฆฌ๊ฐ€ ์ˆ˜ํ–‰๋˜๊ฒŒ ๋˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋ฌผ๋ก  JPA๊ฐ€ ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ๊ฐ€ ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ์— ์กด์žฌํ•˜๋Š” Team์ด๋ผ๋ฉด DB์— ์ ‘๊ทผํ•˜์ง€ ์•Š์•„ ์‹ค์ œ๋กœ 10000๋ฒˆ์„ ์ˆ˜ํ–‰ํ•˜์ง„ ์•Š๊ฒ ์ง€๋งŒ, ์ด๋Š” N+1 ๋ฌธ์ œ๋ผ๊ณ  ์ด์•ผ๊ธฐ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +์ด ๋•Œ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๋Œ€ํ‘œ์ ์ธ ๋ฐฉ๋ฒ•์œผ๋กœ๋Š” Fetch Join๊ณผ @EntityGraph๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐ”๋กœ Join์„ ์ˆ˜ํ–‰ํ•ด์„œ ๋ฏธ๋ฆฌ Member์— ๊ด€๋ จ๋œ Team ๊ฐ์ฒด๋“ค์„ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ๋˜๋ฉด Member์˜ Team ๊ฐ์ฒด ๋‚ด์—๋Š” ์ด๋ฏธ ๋ฐ์ดํ„ฐ๊ฐ€ ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ฟผ๋ฆฌ๋ฅผ ์ถ”๊ฐ€๋กœ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +์ถ”๊ฐ€์ ์œผ๋กœ Lazy ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด ๋ฌด์กฐ๊ฑด ํ”„๋ก์‹œ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹™๋‹ˆ๋‹ค. +Member์˜ Team ๊ฐ์ฒด๊ฐ€ @ManyToOne์œผ๋กœ ๋˜์–ด์žˆ๊ณ , Lazy ๋ฐฉ์‹์œผ๋กœ ์„ค์ •๋˜์–ด์žˆ์–ด๋„, + +```java +@Query("SELECT m FROM Member m JOIN FETCH m.team") +List findAllMembersWithTeams(); + +``` +๋งŒ์•ฝ ์•„๋ž˜์ฒ˜๋Ÿผ JPQL fetch join์„ ์‚ฌ์šฉํ•ด์„œ ๊ฐ€์ ธ์˜จ๋‹ค๋ฉด Member ๋‚ด๋ถ€์˜ Team ๊ฐ์ฒด๋Š” ํ”„๋ก์‹œ ๊ฐ์ฒด๊ฐ€ ์•„๋‹Œ ์‹ค์ œ ๊ฐ์ฒด๊ฐ€ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค. \ No newline at end of file diff --git a/keyword/chaptor04/keyword.md b/keyword/chaptor04/keyword.md new file mode 100644 index 0000000..22bc484 --- /dev/null +++ b/keyword/chaptor04/keyword.md @@ -0,0 +1,119 @@ +# IoC (Inversion of Control) + +IoC๋Š” ์ œ์–ด์˜ ์—ญ์ „(Inversion of Control)์ž…๋‹ˆ๋‹ค. + +์ผ๋ฐ˜์ ์ธ ์ฝ”๋”ฉ ๋ฐฉ์‹์—์„œ๋Š” ๊ฐ์ฒด ๊ฐ„ ์˜์กด๊ด€๊ณ„๊ฐ€ ์กด์žฌํ•  ๋•Œ, ๊ฐ์ฒด ๋‚ด์—์„œ ํ•„์š”ํ•œ ๊ฐ์ฒด๋ฅผ ์ง์ ‘ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. + +**๊ธฐ์กด ์ฝ”๋“œ** + +```java +public class MemberService { + // MemberRepository๋Š” interface ๋ผ๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค. + private final MemberRepository memberRepository = new MemoryMemberRepository(); + + ... +} +``` + +MemberService์—์„œ ์ง์ ‘ `MemoryMemberRepository`๋ผ๋Š” ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์‚ฌ์‹ค SOLID์—์„œ DIP(Dependency Inversion Principle)๋ฅผ ์œ„๋ฐ˜ํ•˜๊ณ  ์žˆ๋Š” ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค. + +- **DIP**: ํ”„๋กœ๊ทธ๋ž˜๋จธ๋Š” "์ถ”์ƒํ™”์— ์˜์กดํ•ด์•ผ์ง€, ๊ตฌ์ฒดํ™”์— ์˜์กดํ•˜๋ฉด ์•ˆ๋œ๋‹ค." + +`MemberRepository`๊ฐ€ interface์ผ ๋•Œ, MemberService๋ผ๋Š” ํด๋ผ์ด์–ธํŠธ๋Š” `new MemoryMemberRepository();`๋ผ๋Š” ์ฝ”๋“œ๋กœ ๊ตฌ์ฒดํ™”์— ์˜์กดํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” `MemberRepository`๋ผ๋Š” ์ธํ„ฐํŽ˜์ด์Šค์˜ ๊ตฌํ˜„์ฒด๋ฅผ ๋ฐ”๊ฟ”์•ผ ํ•˜๋Š” ์ƒํ™ฉ์—์„œ Client Code๊ฐ€ ์ˆ˜์ •๋˜์–ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ๋ฅผ ์•ผ๊ธฐํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰, `new MemoryMemberRepository();` ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•ด์•ผ ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด๋Š” SOLID์˜ OCP(Open/Closed Principle) ์œ„๋ฐ˜์œผ๋กœ๋„ ์ด์–ด์ง‘๋‹ˆ๋‹ค. + +- **OCP**: ์†Œํ”„ํŠธ์›จ์–ด ์š”์†Œ๋Š” ํ™•์žฅ์—๋Š” ์—ด๋ ค ์žˆ์œผ๋‚˜ ๋ณ€๊ฒฝ์—๋Š” ๋‹ซํ˜€ ์žˆ์–ด์•ผ ํ•œ๋‹ค. + +์ด๋ฅผ ๊ทน๋ณตํ•˜๊ธฐ ์œ„ํ•ด IoC๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +**IoC๊ฐ€ ์ ์šฉ๋œ ์ฝ”๋“œ** + +```java +public class MemberService { + private final MemberRepository memberRepository; + + public MemberService(MemberRepository memberRepository) { + this.memberRepository = memberRepository; + } + + ... +} + +public class AppConfig { + public MemberService memberService() { + return new MemberService(memberRepository()); + } + + public MemberRepository memberRepository() { + return new MemoryMemberRepository(); + } +} +``` + +๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ํ•„์š”ํ•œ ์˜์กด๊ด€๊ณ„๋ฅผ ์„ค์ •ํ•ด์ฃผ๋Š” ์ž‘์—…์„ ์™ธ๋ถ€ ์ฝ”๋“œ์—์„œ ์ œ์–ดํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์„ค์ •ํ•˜๋Š” ์ž‘์—…์„ ์™ธ๋ถ€์—์„œ ํ•˜๋Š” ๊ฒƒ์ด ๋ฐ”๋กœ IoC์ž…๋‹ˆ๋‹ค. `AppConfig` ํด๋ž˜์Šค์—์„œ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๊ด€๋ฆฌํ•˜๋Š” ์ฑ…์ž„์„ ๋‹ด๋‹นํ•˜๋ฉฐ, ๊ธฐ์กด์˜ `MemberService`์—์„œ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์ฃผ์ž…ํ•˜๋Š” ์ฑ…์ž„์„ ๋ถ„๋ฆฌํ•จ์œผ๋กœ์จ SRP(Single Responsibility Principle) ๊ฐœ๋…๋„ ์ ์šฉ๋œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +--- + +# ํ”„๋ ˆ์ž„์›Œํฌ์™€ API์˜ ์ฐจ์ด + +- **ํ”„๋ ˆ์ž„์›Œํฌ**: ์ฝ”๋“œ์˜ ์‹คํ–‰ ํ๋ฆ„์ด ์ด๋ฏธ ์ •ํ•ด์ ธ ์žˆ๋Š” ํ”„๋กœ๊ทธ๋žจ์ž…๋‹ˆ๋‹ค. +- **API**: ํŠน์ • ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ interface์ž…๋‹ˆ๋‹ค. + +์šฐ๋ฆฌ๋Š” Spring Framework์˜ ์ •ํ•ด์ง„ ๋™์ž‘ ํ๋ฆ„์— ๋งž์ถฐ์„œ ์ฝ”๋“œ ์ž‘์—…์„ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ Framework๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ฐœ๋ฐœํ•  ๋•Œ๋Š” Framework์˜ ๋™์ž‘ ๋ฐฉ์‹์„ ์ดํ•ดํ•˜๊ณ  ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. + +API๋ผ๋Š” ๋ง์€ ๋‹ค์–‘ํ•œ ๊ณณ์—์„œ ์“ฐ์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ ์‹œ API ๋ช…์„ธ์„œ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ, ์™ธ๋ถ€ API๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ, Java์—์„œ ์ œ๊ณตํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๋งํ•  ๋•Œ ๋“ฑ์ž…๋‹ˆ๋‹ค. ์ด๋“ค์˜ ๊ณตํ†ต์ ์€ ๊ฐœ๋ฐœ์ž๊ฐ€ API๊ฐ€ ์ œ๊ณตํ•˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŠน์ • ๊ธฐ๋Šฅ์„ ์ œ๊ณต๋ฐ›๋Š”๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +- **Framework**: ๋™์ž‘ ํ๋ฆ„์— ๋งž์ถฐ์„œ ๊ฐœ๋ฐœํ•ด์•ผ ํ•จ. +- **API**: ํŠน์ • ๊ธฐ๋Šฅ์„ ์ œ๊ณต๋ฐ›๊ธฐ ์œ„ํ•ด ์ž์œ ๋กญ๊ฒŒ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•จ. + +--- + +# AOP (Aspect-Oriented Programming) + +AOP๋Š” ๊ด€์  ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์ž…๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ ํด๋ž˜์Šค์—์„œ ๋ฐ˜๋ณต์ ์œผ๋กœ ๋‚˜ํƒ€๋‚˜๋Š” ๊ณตํ†ต์ ์ธ ๊ธฐ๋Šฅ์„ **ํšก๋‹จ ๊ด€์‹ฌ์‚ฌ**๋ผ๊ณ  ํ•˜๋ฉฐ, ์ผ๋ฐ˜์ ์œผ๋กœ ๋กœ๊น…, ๋ณด์•ˆ, ํŠธ๋žœ์žญ์…˜ ๊ด€๋ฆฌ๊ฐ€ ํฌํ•จ๋ฉ๋‹ˆ๋‹ค. AOP๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ด๋Ÿฌํ•œ ๊ณตํ†ต ๊ธฐ๋Šฅ์„ ๋ถ„๋ฆฌํ•˜์—ฌ ์ฝ”๋“œ์˜ ์œ ์ง€๋ณด์ˆ˜์„ฑ๊ณผ ์žฌ์‚ฌ์šฉ์„ฑ์„ ๋†’์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +- **Aspect**: ๊ด€์‹ฌ์‚ฌ๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ: ๋กœ๊น…, ํŠธ๋žœ์žญ์…˜ +- **JoinPoint**: Aspect๊ฐ€ ์‚ฝ์ž…๋  ์ˆ˜ ์žˆ๋Š” ์ง€์ . ์˜ˆ: ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ, ์˜ˆ์™ธ ๋ฐœ์ƒ +- **Pointcut**: JoinPoint ์ค‘ Aspect๊ฐ€ ์ ์šฉ๋  ๊ณณ์„ ์„ ์ •ํ•˜๋Š” ํ‘œํ˜„์‹ +- **Advice**: Aspect๊ฐ€ ์‹ค์ œ๋กœ ์ˆ˜ํ–‰ํ•  ์ž‘์—…. ํŠน์ • Pointcut์—์„œ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. + - **Before Advice**: ๋ฉ”์„œ๋“œ ์‹คํ–‰ ์ „ + - **After Returning Advice**: ๋ฉ”์„œ๋“œ ์ •์ƒ ์‹คํ–‰ ํ›„ + - **After Throwing Advice**: ๋ฉ”์„œ๋“œ ์‹คํ–‰ ์ค‘ ์˜ˆ์™ธ ๋ฐœ์ƒ ํ›„ + - **After (Finally) Advice**: ๋ฉ”์„œ๋“œ ์‹คํ–‰ ํ›„ (์ •์ƒ์ด๋“  ์˜ˆ์™ธ๋“ ) + - **Around Advice**: ๋ฉ”์„œ๋“œ ์‹คํ–‰ ์ „ํ›„, ์‹คํ–‰ ์—ฌ๋ถ€ ๊ฒฐ์ • ๊ฐ€๋Šฅ +- **Weaving**: Aspect๋ฅผ ์‹ค์ œ ์ฝ”๋“œ์— ์ ์šฉํ•˜๋Š” ๊ณผ์ • + +**AOP์˜ ์žฅ์ ** + +- **๋ชจ๋“ˆํ™”**: ํšก๋‹จ ๊ด€์‹ฌ์‚ฌ๋ฅผ Aspect๋กœ ๋ถ„๋ฆฌํ•ด ์ฝ”๋“œ์˜ ์‘์ง‘๋„๋ฅผ ๋†’์ด๊ณ , ํŠน์ • ๊ธฐ๋Šฅ ๋ณ€๊ฒฝ์ด๋‚˜ ์ถ”๊ฐ€๊ฐ€ ์‰ฌ์›Œ์ง. +- **์œ ์ง€๋ณด์ˆ˜์„ฑ**: ์ฝ”๋“œ๊ฐ€ ๊ฐ„๊ฒฐํ•ด์ง€๊ณ , ํ•ต์‹ฌ ๋กœ์ง๊ณผ ๋ถ€๊ฐ€์ ์ธ ๊ด€์‹ฌ์‚ฌ๊ฐ€ ๋ถ„๋ฆฌ๋˜์–ด ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์šฉ์ดํ•จ. +- **์žฌ์‚ฌ์šฉ์„ฑ**: ๊ณตํ†ต ๊ธฐ๋Šฅ์„ ์žฌ์‚ฌ์šฉํ•ด ์ฝ”๋“œ ์ค‘๋ณต์„ ์ค„์ผ ์ˆ˜ ์žˆ์Œ. + +**Spring AOP** + +Spring Framework๋Š” ์ฃผ๋กœ **ํ”„๋ก์‹œ ๊ธฐ๋ฐ˜ AOP**๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. **@Aspect** ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•˜์—ฌ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. + +--- + +# ์„œ๋ธ”๋ฆฟ + +Servlet๋Š” ๊ณต์‹ Java API๋กœ, ๋™์  ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ตฌ์ถ•ํ•˜๋Š” ๋ฐ ์ฃผ์š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ Servlet์„ ํŽธ๋ฆฌํ•˜๊ฒŒ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ํ™˜๊ฒฝ์„ ์ œ๊ณตํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ Tomcat์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ Tomcat์€ Servlet Container๋ผ๊ณ ๋„ ๋ถˆ๋ฆฝ๋‹ˆ๋‹ค. + +Tomcat์€ ํฌ๊ฒŒ ๋‘ ๊ฐ€์ง€ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค: **catalina**์™€ **coyote**. + +1. **๋„คํŠธ์›Œํฌ ์š”์ฒญ์„ ๋ฐ›๊ณ  ์‘๋‹ต**: coyote +2. **์š”์ฒญ์„ ๋ฐ›์•„ Servlet์„ ํ†ตํ•ด ๋™์  ์ž‘์—…์„ ์‹คํ–‰**: catalina (Servlet Container) + +HTTP Protocol ํ˜•์‹์— ๋งž๊ฒŒ ์š”์ฒญ ๋ฉ”์‹œ์ง€๋ฅผ ํŒŒ์‹ฑํ•˜๊ณ , ์‘๋‹ต ๋ฉ”์‹œ์ง€๋ฅผ ์‰ฝ๊ฒŒ ์ƒ์„ฑํ•˜๋„๋ก ๋•๋Š” ์—ญํ• ์„ ํ•˜๋Š” ๊ฒƒ์ด Servlet Java API์ž…๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ Servlet์„ ๊ด€๋ฆฌํ•˜๋Š” Servlet Container๊ฐ€ Tomcat์˜ catalina์ž…๋‹ˆ๋‹ค. + +Tomcat์˜ **coyote**๋Š” ๋„คํŠธ์›Œํฌ ์š”์ฒญ๊ณผ ์‘๋‹ต์„ ๊ด€๋ฆฌํ•˜๋ฉฐ, ์Šค๋ ˆ๋“œ๋ฅผ ์ด์šฉํ•ด ๋‹ค์ˆ˜์˜ ํด๋ผ์ด์–ธํŠธ์™€ ๋™์‹œ์— ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. + +Spring Boot๋Š” Tomcat์„ ๋‚ด์žฅํ•˜๊ณ , Servlet์„ ์ƒ์†๋ฐ›์€ `DispatcherServlet`์„ ์ œ๊ณตํ•˜์—ฌ ๊ฐœ๋ฐœ์ž๊ฐ€ ํŽธ๋ฆฌํ•˜๊ฒŒ ์„œ๋ฒ„ ๊ฐœ๋ฐœ์„ ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋งŽ์€ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. `DispatcherServlet`์€ Spring Container์™€ ์—ฐ๊ฒฐ๋˜์–ด, ๋“ฑ๋ก๋œ `Controller` Bean ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•ด ๋™์ž‘์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. + +--- + +**Servlet Container์˜ ์—ญํ• ** + +- HTTP Protocol ํ˜•์‹์— ๋งž์ถฐ ์š”์ฒญ ๋ฉ”์‹œ์ง€๋ฅผ ์‰ฝ๊ฒŒ ๊ด€๋ฆฌ +- `HttpServletRequest`, `HttpServletResponse` ๊ฐ์ฒด ์ œ๊ณต +- Thread Pool์„ ์ด์šฉํ•ด ๋‹ค์ˆ˜์˜ ํด๋ผ์ด์–ธํŠธ ์š”์ฒญ ์ฒ˜๋ฆฌ + diff --git a/keyword/chatper06/keyword.md b/keyword/chatper06/keyword.md new file mode 100644 index 0000000..1fef61c --- /dev/null +++ b/keyword/chatper06/keyword.md @@ -0,0 +1,21 @@ +### ์ง€์—ฐ๋กœ๋”ฉ๊ณผ ์ฆ‰์‹œ๋กœ๋”ฉ์˜ ์ฐจ์ด + +์ง€์—ฐ๋กœ๋”ฉ์€ ์œ„์˜ ์„ค๋ช…๊ณผ ์ผ์น˜ํ•ฉ๋‹ˆ๋‹ค. Lazy ์˜ต์…˜์„ ์ฃผ์–ด์„œ ์‹ค์ œ๋กœ ๊ฐ์ฒด์˜ โ€œํ•„๋“œโ€ ์— ์ ‘๊ทผํ•  ๋•Œ ๊ทธ ๋•Œ ์ฟผ๋ฆฌ๊ฐ€ ๋‚˜๊ฐ€๋Š” ๋ฐฉ์‹์œผ๋กœ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. ๋ฌผ๋ก  fetch join์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ฏธ๋ฆฌ joinํ•˜์—ฌ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค. + +์ฆ‰์‹œ๋กœ๋”ฉ์€ ์—ฐ๊ด€์ด ์žˆ๋Š” ๊ฐ์ฒด๋ฅผ ์กฐํšŒํ•  ๋•Œ eager๋กœ ์„ค์ • ๋˜์–ด์žˆ๋Š” ๊ฐ์ฒด๋“ค์„ ๋ชจ๋‘ ํƒ€๊ณ  ๋“ค์–ด๊ฐ€์„œ ์ „๋ถ€ join์„ ํ•œ ๋’ค์— ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค. eager ์„ค์ •์€ ์˜ˆ์ƒ์น˜ ๋ชปํ•œ ์ฟผ๋ฆฌ๊ฐ€ ๋Œ์•„๊ฐˆ ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ผ๋‹จ lazy๋กœ ์„ค์ •ํ•˜๊ณ  ํ•„์š”ํ•  ๊ฒฝ์šฐ fetch join์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์ด ์„ ํ˜ธ๋œ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. + +### Fetch Join +Fetch Join์ด ๋ฐ”๋กœ N+1 ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ํ•ด๊ฒฐ์ฑ… ์ค‘ ํ•˜๋‚˜๊ฐ€ ๋˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. +JPQL์˜ Fetch Join์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด, ์กฐํšŒํ•  ๋•Œ ๋ฏธ๋ฆฌ ๊ฐ์ฒด๋“ค์„ join์„ ํ•ด์„œ ๊ฐ€์ ธ์˜ค๊ธฐ ๋•Œ๋ฌธ์— +Lazy๋กœ ์„ค์ •์„ ํ–ˆ๋”๋ผ๋„ N+1 ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +### @EntityGraph +Fetch Join๊ณผ ํ•จ๊ป˜ N+1 ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๋‹ค๋ฅธ ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. + +### JPQL +JPA์˜ ๊ฐ์ฒด์ง€ํ–ฅ ์ฟผ๋ฆฌ ์–ธ์–ด๋กœ ์—”ํ„ฐํ‹ฐ ๊ฐ์ฒด๋ฅผ ๋Œ€์ƒ์œผ๋กœ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. SQL๋กœ ๊ฒฐ๊ตญ ๋ฒˆ์—ญ๋˜์–ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ฟผ๋ฆฌ๊ฐ€ ๋ณด๋‚ด์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. SQL๊ณผ ๋‹ค๋ฅธ ์ ์€ ์—”ํ„ฐํ‹ฐ๋ฅผ ๋Œ€์ƒ์œผ๋กœ ์ฟผ๋ฆฌ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +### QueryDSL +JPA๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋™์ ์ฟผ๋ฆฌ๋ฅผ ์ž‘์„ฑํ•˜๋Š”๋ฐ ์–ด๋ ค์›€์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์ด๊ณ  Spring ๊ณต์‹์ŠคํŽ™์€ ์•„๋‹ˆ๋ฉฐ, ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ฒ˜์Œ ์‚ฌ์šฉํ•  ๋•Œ ์„ค์ •์ด ๋‹ค์†Œ ๊นŒ๋‹ค๋กœ์šด ๋ฉด์ด ์žˆ์Šต๋‹ˆ๋‹ค. + +Java ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด์„œ ๋™์ ์œผ๋กœ ์ฟผ๋ฆฌ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ์˜ค๋Š” ์•„์ฃผ ํฐ ์ด์ ์ด ์žˆ๋Š”๋ฐ ์ปดํŒŒ์ผ ์‹œ์ ์— ์˜ค๋ฅ˜๋ฅผ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. \ No newline at end of file diff --git a/mission/chapter00/mission.md b/mission/chapter00/mission.md new file mode 100644 index 0000000..66ac3c7 --- /dev/null +++ b/mission/chapter00/mission.md @@ -0,0 +1,51 @@ +๐Ÿ”ฅ **๋ฏธ์…˜** +--- +- 1๋ฒˆ (๋„ˆ๋””๋„ˆ๋ฆฌ ํ™ˆํŽ˜์ด์ง€ ์ ‘์†ํ•˜๋Š” ๊ณผ์ • ์ ์–ด๋ณด๊ธฐ) +1. **URL ์ž…๋ ฅ ๋ฐ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ํ™•์ธ** + - ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ๋ฅผ ํ™•์ธ + - ์˜ˆ๋ฅผ ๋“ค์–ด HTTP -> HTTPS ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ์ฒ˜๋ฆฌ +2. **์บ์‹œ ํ™•์ธ** + - ๋ธŒ๋ผ์šฐ์ € ๋‚ด ์บ์‹ฑ ๊ฐ€๋Šฅํ•œ ๋ฐ์ดํ„ฐ์ธ์ง€ ํ™•์ธํ•œ๋‹ค. ์บ์‹ฑ ๋ถˆ๊ฐ€๋Šฅ ๋ฐ์ดํ„ฐ๋Š” ์š”์ฒญํ•œ๋‹ค. +3. **HTTP ์š”์ฒญ ๋ฉ”์„ธ์ง€ ์ƒ์„ฑ** + - ํ˜„์žฌ ์˜ˆ์‹œ๋Š” ๋„ˆ๋””๋„ˆ๋ฆฌ ํ™ˆํŽ˜์ด์ง€ ์ ‘์†์ด๊ธฐ ๋•Œ๋ฌธ์— GET ์š”์ฒญ ๋ฉ”์„ธ์ง€ ์ƒ์„ฑ + - ์‚ฌ์šฉ์ž์˜ ์š”์ฒญ์— ๋”ฐ๋ผ POST ์š”์ฒญ, key value ํ˜•ํƒœ์˜ ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ ์ƒ์„ฑ ๊ฐ€๋Šฅ +4. **DNS ์กฐํšŒ** + - ๋„๋ฉ”์ธ ์ด๋ฆ„์„ ํ†ตํ•ด์„œ IP ์ฃผ์†Œ๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค. + - DNS ๋˜ํ•œ ์บ์‹ฑ์ด ์ผ์–ด๋‚  ์ˆ˜ ์žˆ๋‹ค. ๋ธŒ๋ผ์šฐ์ € ์บ์‹ฑ๊ณผ OS ์บ์‹ฑ์ด ์žˆ๋‹ค. +5. **TCP 3 way handshake** + - ํด๋ผ์ด์–ธํŠธ ์„œ๋ฒ„ ๊ฐ„ ์—ฐ๊ฒฐ ํ™•์ธ +6. **SSL/TLS handshake** + - HTTPS ์ธ ๊ฒฝ์šฐ ์ˆ˜ํ–‰ +7. **HTTP ์š”์ฒญ ๋ฉ”์„ธ์ง€ ์ „์†ก** + - Internet Layer, Network Interface Layer ์ˆœ์„œ๋Œ€๋กœ ๋‚ด๋ ค๊ฐ€์„œ ํ•„์š” ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค. + - IP ๋ผ์šฐํŒ…๊ณผ ARP ํ”„๋กœ์„ธ์Šค ๋“ฑ์ด ๋ฐœ์ƒ + - ์ธํ„ฐ๋„ท ๋ง์„ ํ†ตํ•ด ์š”์ฒญ ๋ฐ์ดํ„ฐ๊ฐ€ ์„œ๋ฒ„์—๊ฒŒ ๋„๋‹ฌ๋œ๋‹ค. +8. **์„œ๋ฒ„ ์ปดํ“จํ„ฐ์—๊ฒŒ ์š”์ฒญ ๋ฐ์ดํ„ฐ ๋„๋‹ฌ** + - ์„œ๋ฒ„ ์ปดํ“จํ„ฐ๋Š” ์š”์ฒญ ๋ฐ์ดํ„ฐ๋ฅผ ์•„๋žซ ๊ณ„์ธต์—์„œ ์œ— ๊ณ„์ธต ์ˆœ์œผ๋กœ ํ™•์ธ + - ๋„ˆ๋””๋„ˆ๋ฆฌ ์„œ๋ฒ„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—๊ฒŒ ํ•„์š”ํ•œ ์š”์ฒญ ๋ฐ์ดํ„ฐ ์ „๋‹ฌ +9. **๋„ˆ๋””๋„ˆ๋ฆฌ ์„œ๋ฒ„์˜ ์‘๋‹ต ๋ฉ”์„ธ์ง€ ์ƒ์„ฑ** + - ๋„ˆ๋””๋„ˆ๋ฆฌ ์„œ๋ฒ„๋Š” ์‘๋‹ต HTTP ๋ฐ์ดํ„ฐ๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์•„๋ž˜ ๊ณ„์ธต์œผ๋กœ ๋ณด๋ƒ„ + - ๊ฐ ๊ณ„์ธต๋“ค์€ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ + - ์ธํ„ฐ๋„ท ๋ง์œผ๋กœ ๋ณด๋‚ด์ง +10. **ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์‘๋‹ต ๋ฐ์ดํ„ฐ ๋„๋‹ฌ** + - ์ตœํ•˜์œ„ ๊ณ„์ธต๋ถ€ํ„ฐ ์œ„ ๊ณ„์ธต ์ˆœ์œผ๋กœ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”์ถœํ•˜๊ณ  ์›น ๋ธŒ๋ผ์šฐ์ €๋Š” HTTP ์‘๋‹ต ๋ฉ”์„ธ์ง€ ํ™•์ธ +11. **๋ธŒ๋ผ์šฐ์ € ๋ Œ๋”๋ง** + - ํ˜น์‹œ ํ•„์š”ํ•œ ์ถ”๊ฐ€ ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ๋‹ค๋ฉด ์ถ”๊ฐ€ ์š”์ฒญ์„ ๋ณด๋ƒ„. + - HTTP/1.1 ๊ธฐ์ค€์œผ๋กœ ์—ฐ๊ฒฐ์„ ๋Š์ง€ ์•Š๊ณ (keep-alive), ์ด๋ฏธ์ง€, JS, CSS๋ฅผ ์ถ”๊ฐ€ ์š”์ฒญ + + +**์บ์‹ฑ์ด๋ž€?** +- ํฌ๊ฒŒ ๋ธŒ๋ผ์šฐ์ €์บ์‹œ์™€ ๊ณต์œ ์บ์‹œ๋กœ ๋‚˜๋‰œ๋‹ค. + +1. ๋ธŒ๋ผ์šฐ์ € ์บ์‹œ + - ์ฟ ํ‚ค, ๋กœ์ปฌ์Šคํ† ๋ฆฌ์ง€ ๋“ฑ์„ ํฌํ•จํ•œ ์บ์‹œ(private cache) + - ๋ธŒ๋ผ์šฐ์ € ์ž์ฒด๊ฐ€ ์‚ฌ์šฉ์ž๋ฅผ ์œ„ํ•ด ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์˜๋ฏธํ•œ๋‹ค. +2. ๊ณต์œ  ์บ์‹œ + - ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„ ์‚ฌ์ด์— ์‚ฌ์šฉ์ž ๊ฐ„ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋Š” ์‘๋‹ต์„ ์ €์žฅ + - ๋Œ€ํ‘œ์  ์˜ˆ๋กœ๋Š” ํ”„๋ก์‹œ ์„œ๋ฒ„๊ฐ€ ์บ์‹ฑํ•˜๋Š” ๊ฒƒ + - ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ๋ฅผ ๋‘ฌ์„œ ๋‚ด๋ถ€์„œ๋ฒ„๋กœ ํฌ์›Œ๋“œ ํ•œ๋‹ค๊ณ  ํ˜ธ์นญ + - CDN ์„œ๋ฒ„๋ฅผ ๋‘ฌ์„œ ์บ์‹ฑ ๊ฐ€๋Šฅ + +--- +- 2๋ฒˆ + แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2024-09-16 แ„‹แ…ฉแ„’แ…ฎ 6 00 33(2) \ No newline at end of file diff --git a/mission/chapter02/java_mission.md b/mission/chapter02/java_mission.md new file mode 100644 index 0000000..9b73e11 --- /dev/null +++ b/mission/chapter02/java_mission.md @@ -0,0 +1,82 @@ +# ์ถ”๊ฐ€๊ณผ์ œ + +### 1. Static, JVM Memory, ClassLoader + +### JVM Memory + +**JVM memory** ๊ตฌ์กฐ๋Š” **๋ฉ”์„œ๋“œ ์˜์—ญ, ์Šคํƒ ์˜์—ญ, ํž™ ์˜์—ญ**์œผ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค. + +- **๋ฉ”์„œ๋“œ ์˜์—ญ** + - ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰ํ•˜๋Š”๋ฐ ํ•„์š”ํ•œ ๊ณตํ†ต ๋ฐ์ดํ„ฐ๋ฅผ ๊ด€๋ฆฌํ•œ๋‹ค. ํ”„๋กœ๊ทธ๋žจ์˜ ๋ชจ๋“  ์˜์—ญ์—์„œ ๊ณต์œ ํ•œ๋‹ค. + - ํด๋ž˜์Šค ์ •๋ณด : ํด๋ž˜์Šค์˜ ์‹คํ–‰์ฝ”๋“œ(๋ฐ”์ดํŠธ ์ฝ”๋“œ), ํ•„๋“œ, ๋ฉ”์„œ๋“œ, ์ƒ์„ฑ์ž ์ฝ”๋“œ ๋“ฑ ๋ชจ๋“  ์‹คํ–‰์ฝ”๋“œ๊ฐ€ ์กด์žฌ + - static ์˜์—ญ : static ๋ณ€์ˆ˜๋“ค์„ ๋ณด๊ด€ํ•œ๋‹ค. + - ๋Ÿฐํƒ€์ž„ ์ƒ์ˆ˜ ํ’€ : ๊ณตํ†ต ๋ฆฌํ„ฐ๋Ÿด ์ƒ์ˆ˜๋ฅผ ๋ณด๊ด€ํ•œ๋‹ค. ํ”„๋กœ๊ทธ๋žจ์„ ํšจ์œจ์ ์œผ๋กœ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ์ƒ์ˆ˜๋“ค๊ณผ ๋ฆฌํ„ฐ๋Ÿด ๋ฌธ์ž๊ฐ€ ์žˆ์œผ๋ฉด ๊ณตํ†ต์œผ๋กœ ๋ฌถ์–ด์„œ ๊ด€๋ฆฌํ•œ๋‹ค. +- **์Šคํƒ ์˜์—ญ** + - ์‹ค์ œ ํ”„๋กœ๊ทธ๋žจ์ด ์‹คํ–‰๋˜๋Š” ์˜์—ญ์ด๋‹ค. ๋ฉ”์„œ๋“œ๋ฅผ ์‹คํ–‰ํ•  ๋•Œ๋งˆ๋‹ค ํ•˜๋‚˜์”ฉ ์Šคํƒ ์˜์—ญ์— ์Œ“์ด๊ฒŒ ๋œ๋‹ค. + - ์ž๋ฐ” ์‹คํ–‰ ์‹œ, ํ•˜๋‚˜์˜ ์‹คํ–‰ ์Šคํƒ์ด ์ƒ์„ฑ๋œ๋‹ค. ๊ฐ ์Šคํƒ ํ”„๋ ˆ์ž„์€ ์ง€์—ญ ๋ณ€์ˆ˜, ์ค‘๊ฐ„ ์—ฐ์‚ฐ ๊ฒฐ๊ณผ, ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ ์ •๋ณด ๋“ฑ์„ ํฌํ•จํ•œ๋‹ค. + - ์Šคํƒ ์˜์—ญ์€ ๊ฐ ์Šค๋ ˆ๋“œ ๋ณ„๋กœ ํ•˜๋‚˜์˜ ์‹คํ–‰ ์Šคํƒ์ด ์ƒ์„ฑ๋œ๋‹ค. ๋”ฐ๋ผ์„œ ์Šค๋ ˆ๋“œ ์ˆ˜ ๋งŒํผ ์Šคํƒ ์˜์—ญ์ด ์ƒ์„ฑ๋œ๋‹ค. +- **ํž™ ์˜์—ญ** + - ๊ฐ์ฒด(์ธ์Šคํ„ด์Šค)๊ฐ€ ์ƒ์„ฑ๋˜๋Š” ์˜์—ญ์ด๋‹ค. new ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ด ์˜์—ญ์— ์กด์žฌํ•˜๊ฒŒ ๋œ๋‹ค. ๋ฐฐ์—ด๋„ ์ด ์˜์—ญ์— ์ƒ์„ฑ๋œ๋‹ค. + +### static + +**static ๋ณ€์ˆ˜** + +- **ํด๋ž˜์Šค ๊ณต์šฉ ๋ณ€์ˆ˜** + - ํด๋ž˜์Šค์—์„œ ๊ณต์šฉ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ๋ณ€์ˆ˜ + + **์ฐธ๊ณ :** ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜(heap ์˜์—ญ), ์ง€์—ญ๋ณ€์ˆ˜(stack ์˜์—ญ) + + +**static method** + +- ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ์—†์ด ๋ฐ”๋กœ ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ด์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค. +- ์ •์  ๋ฉ”์†Œ๋“œ ๋‚ด๋ถ€์—์„œ๋Š” ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜์— ์ ‘๊ทผ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค. + - ์ •์  ๋ฉ”์„œ๋“œ๋Š” ์ฐธ์กฐ ๊ฐ’์˜ ๊ฐœ๋…์ด ์—†๋‹ค. ํŠน์ • ์ธ์Šคํ„ด์Šค์˜ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์ฐธ์กฐ ๊ฐ’์„ ์•Œ์•„์•ผ ํ•˜๋Š”๋ฐ, ์ •์  ๋ฉ”์„œ๋“œ๋Š” ์ฐธ์กฐ๊ฐ’ ์—†์ด ํ˜ธ์ถœํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ์ •์  ๋ฉ”์„œ๋“œ ๋‚ด๋ถ€์—์„œ ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜๋‚˜ ์ธ์Šคํ„ด์Šค ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค. +- ์œ ํ‹ธ๋ฆฌํ‹ฐ์„ฑ ๋ฉ”์†Œ๋“œ์—์„œ ๋งŽ์ด ํ™œ์šฉ๋œ๋‹ค. + +### ClassLoader + +ํด๋ž˜์Šค ๋กœ๋”๋Š” ํด๋ž˜์Šค ํŒŒ์ผ์„ ๋ฉ”๋ชจ๋ฆฌ์— ๋กœ๋“œํ•˜๋Š” ์—ญํ• ์„ ํ•˜๋ฉฐ, ์ด ๊ณผ์ •์—์„œ static ์š”์†Œ๋„ ํ•จ๊ป˜ Method ์˜์—ญ์— ํ• ๋‹น๋œ๋‹ค. + +static ๋งด๋ฒ„๋Š” ํด๋ž˜์Šค ๋กœ๋”๊ฐ€ ํ•ด๋‹น ํด๋ž˜์Šค๋ฅผ ๋กœ๋“œํ•œ ํ›„ ์ดˆ๊ธฐํ™” ๋˜๊ธฐ ๋•Œ๋ฌธ์—, ํด๋ž˜์Šค ๋กœ๋”ฉ ์‹œ์ ์™€ static ์ดˆ๊ธฐํ™” ์‹œ์ ์€ ๋ฐ€์ ‘ํ•œ ๊ด€๊ณ„๊ฐ€ ์žˆ๋‹ค. + +### 2. Collection interface + +์ปฌ๋ ‰์…˜ ํ”„๋ ˆ์ž„์›Œํฌ๋Š” ๊ฐ์ฒด๋ฅผ ์ €์žฅํ•˜๊ณ  ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋œ๋‹ค. + +Collection Interface๊ฐ€ ์ตœ์ƒ๋‹จ์— ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฅผ ๊ตฌํ˜„ํ•œ ๋‹ค์–‘ํ•œ ์ปฌ๋ ‰์…˜๋“ค์€ ๊ธฐ๋ณธ์ ์œผ๋กœ ๊ณตํ†ต์ ์ธ ๋ฉ”์†Œ๋“œ๋ฅผ ์ œ๊ณตํ•œ๋‹ค. ๋˜ํ•œ ๋‹คํ˜•์„ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ, ๋‹ค์–‘ํ•œ ์ปฌ๋ ‰์…˜ ํƒ€์ž…๋“ค์„ ๊ฐ™์€ ํƒ€์ž…์œผ๋กœ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ๋‹ค. + +add, remove, size, isEmpty, contains, iterator, clear์™€ ๊ฐ™์€ ๋ฉ”์†Œ๋“œ๊ฐ€ collection ์ธํ„ฐํŽ˜์ด์Šค์— ์ œ๊ณต๋œ๋‹ค. + +์ฃผ์˜ํ•  ์ ์€ Map์€ Collection ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ์•„๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜, keyset()๊ณผ ๊ฐ™์€ ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ Collection์˜ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๋‹ค. + +### **์ปฌ๋ ‰์…˜์ด ์ œ๊ณตํ•˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค** + +- Collection + - ๋ฃจํŠธ ์ธํ„ฐํŽ˜์ด์Šค๋กœ ๋ฉ”์†Œ๋“œ๋ฅผ ์ œ๊ณตํ•œ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ์ปฌ๋ ‰์…˜ ํด๋ž˜์Šค๊ฐ€ ์ด ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ƒ์†๋ฐ›๋Š”๋‹ค. +- List + - ์ˆœ์„œ๊ฐ€ ์žˆ์–ด, ์ธ๋ฑ์Šค๋ฅผ ํ†ตํ•ด ์ ‘๊ทผ ๊ฐ€๋Šฅ. ์ค‘๋ณต ํ—ˆ์šฉ +- Set + - ์ค‘๋ณต ์š”์†Œ๋ฅผ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. ์ธ๋ฑ์Šค๋ฅผ ํ†ตํ•ด ์ ‘๊ทผ ๋ถˆ๊ฐ€ํ•˜๋‹ค. +- Queue + - ์ฃผ๋กœ ์š”์†Œ๊ฐ€ ์ฒ˜๋ฆฌ๋˜๊ธฐ ์ „์— ๋ณด๊ด€ํ•˜๋Š” ์ปฌ๋ ‰์…˜์ด๋‹ค. +- Map + - ํ‚ค์™€ ์Œ์œผ๋กœ ์š”์†Œ๋ฅผ ์ €์žฅํ•˜๊ณ , Collection ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ƒ์†๋ฐ›์ง€ ์•Š๋Š”๋‹ค. + +### ๊ตฌํ˜„์ฒด + +- List + - ArrayList โ†’ ๋‚ด๋ถ€์ ์œผ๋กœ ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•œ๋‹ค. + - LinkedList โ†’ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. +- Set + - HashSet โ†’ ํ•ด์‹œ ํ…Œ์ด๋ธ” + - LinkedHashSet โ†’ ํ•ด์‹œ ํ…Œ์ด๋ธ”๊ณผ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ + - TreeSet โ†’ ๋ ˆ๋“œ-๋ธ”๋ž™ํŠธ๋ฆฌ +- Queue + - LinkedList โ†’ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ + - ArrayDeque โ†’ ๋ฐฐ์—ด ๊ธฐ๋ฐ˜์˜ ์›ํ˜• ํ +- Map + - HashMap โ†’ ํ•ด์‹œ ํ…Œ์ด๋ธ” + - LinkedHashMap โ†’ ํ•ด์‹œ ํ…Œ์ด๋ธ” + ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ + - TreeMap โ†’ ๋ ˆ๋“œ-๋ธ”๋ž™ํŠธ๋ฆฌ \ No newline at end of file diff --git a/mission/chapter02/misson.md b/mission/chapter02/misson.md new file mode 100644 index 0000000..f154f5c --- /dev/null +++ b/mission/chapter02/misson.md @@ -0,0 +1,90 @@ +## 1 + +```sql +SELECT + r.name AS restaurant_name, + m.content AS mission_content, + mm.status AS mission_status, + m.point +FROM + member_mission mm +JOIN + mission m ON mm.id2 = m.id +JOIN + restaurant r ON m.id2 = r.id +WHERE + mm.member_id = (์‚ฌ์šฉ์ž์˜ id) +ORDER BY + mm.updated_at DESC +LIMIT ? OFFSET ?; +``` + +## 2 +```sql +INSERT INTO review ( + restaurant_id, + member_id, // erd์— ๋ˆ„๋ฝ๋˜์—ˆ์ง€๋งŒ, ์žˆ์–ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์Œ + score, + content, + created_at, + updated_at +) VALUES ( + (๊ฐ€๊ฒŒ์˜ ID), + (์‚ฌ์šฉ์ž์˜ ID), + (๋ฆฌ๋ทฐ ์ ์ˆ˜), + (๋ฆฌ๋ทฐ ๋‚ด์šฉ), + NOW(), + NOW() +); + +``` +## 3 +```sql +// ์„ ํƒํ•œ ์ง€์—ญ ๋‚ด์—์„œ ์„ฑ๊ณตํ•œ ๋ฏธ์…˜ ๊ฐœ์ˆ˜ + +SELECT + COUNT(*) +FROM + member_mission mm +JOIN + mission m ON mm.id2 = m.id +JOIN + restaurant r ON m.id2 = r.id +WHERE + r.address = (์ง€์—ญ์˜ ์ด๋ฆ„) + AND mm.member_id = (ํšŒ์›์˜ id) + AND mm.status = '์™„๋ฃŒ'; + + +// (ํ˜„์žฌ ์„ ํƒ ๋œ ์ง€์—ญ์—์„œ ๋„์ „์ด ๊ฐ€๋Šฅํ•œ ๋ฏธ์…˜ ๋ชฉ๋ก, ํŽ˜์ด์ง• ํฌํ•จ) + +SELECT + r.name AS restaurant_name, + r.type AS restaurant_type, + m.content AS mission_content +FROM + restaurant r +JOIN + mission m ON r.id = m.id2 +LEFT JOIN + member_mission mm ON m.id = mm.id2 AND mm.status != '์™„๋ฃŒ' +WHERE + r.address = (์ง€์—ญ์˜ ์ด๋ฆ„) +ORDER BY + m.created_at DESC +LIMIT ? OFFSET ?; + +``` + +## 4 +```sql +SELECT + m.name, + m.email, + m.phone_number, + m.point +FROM + member m +WHERE + m.id = (memberId); +``` \ No newline at end of file diff --git a/mission/chaptor01/java_mission.md b/mission/chaptor01/java_mission.md new file mode 100644 index 0000000..a27a0c2 --- /dev/null +++ b/mission/chaptor01/java_mission.md @@ -0,0 +1,125 @@ + ๐Ÿ”ฅ ์ถ”๊ฐ€๋ฏธ์…˜ +--- +### ์ž๋ฐ”์˜ ์ ‘๊ทผ ์ œ์–ด์ž 4๊ฐ€์ง€ +- **public** + - ๋ชจ๋“  ํŒŒ์ผ์—์„œ ์ ‘๊ทผ ํ—ˆ์šฉ +- **protected** + - ๊ฐ™์€ ํŒจํ‚ค์ง€์—์„œ ์ ‘๊ทผ ํ—ˆ์šฉ + - ์ƒ์†๋ฐ›์€ ํด๋ž˜์Šค์—์„œ ์ ‘๊ทผ ํ—ˆ์šฉ +- **default(package-private)** + - ์ ‘๊ทผ ์ œ์–ด์ž๋ฅผ ๋ช…์‹œํ•˜์ง€ ์•Š์œผ๋ฉด default + - ๊ฐ™์€ ํŒจํ‚ค์ง€์—์„œ ์ ‘๊ทผ ํ—ˆ์šฉ +- **private** + - ํด๋ž˜์Šค ๋‚ด์—์„œ๋งŒ ์ ‘๊ทผ ๊ฐ€๋Šฅ + + +**protected ์‚ฌ์šฉ ์˜ˆ์‹œ** +```java + +@SuperBuilder +@NoArgsConstructor(access = PROTECTED) +public abstract class AdditionalInfo { + + @JsonProperty("์ถ”๊ฐ€์ •๋ณด") + @Builder.Default + protected Map addtionalInfoMap = new HashMap<>(); + + public Optional getAdditionalInfo(String key) { + return Optional.ofNullable(addtionalInfoMap.get(key)); + } +} + +@SuperBuilder +@NoArgsConstructor(access = PROTECTED) +@ToString +public class CurriculumCode extends AdditionalInfo { + + @JsonProperty("๊ต๊ณผ๊ณผ์ •") + @Builder.Default + private Map> codeMap = new HashMap<>(); + +... +} + +``` + + +--- +### ํด๋ž˜์Šค์™€ ์ธํ„ฐํŽ˜์ด์Šค + +- **ํด๋ž˜์Šค** + - ์ธ์Šคํ„ด์Šค ๊ฐ์ฒด์˜ ์„ค๊ณ„๋„ + - ํ•„๋“œ, ๋ฉ”์†Œ๋“œ๋ฅผ ์ •์˜ + - ์ƒ์†์„ ํ†ตํ•ด ํ™•์žฅ ๊ฐ€๋Šฅ + +> ์ฐธ๊ณ : ์ถ”์ƒํด๋ž˜์Šค +> ์ถ”์ƒํด๋ž˜์Šค๋Š” ํ•ด๋‹น ํด๋ž˜์Šค๋ฅผ ์ธ์Šคํ„ด์Šคํ™” ํ•  ์ˆ˜ ์—†์œผ๋ฉฐ, ๋ฐ˜๋“œ์‹œ ์ƒ์† ๋ฐ›์€ ํด๋ž˜์Šค๋งŒ ์ธ์Šคํ„ด์Šคํ™” ๊ฐ€๋Šฅํ•˜๋‹ค. + +- **์ธํ„ฐํŽ˜์ด์Šค** + - ๊ตฌํ˜„๋˜์ง€ ์•Š์€ ๋ฉ”์†Œ๋“œ๋“ค์˜ ์ง‘ํ•ฉ + - ๋ฉ”์†Œ๋“œ์˜ ์ ‘๊ทผ์ œ์–ด์ž๋Š” ์ž๋™์œผ๋กœ public + - ๋‹ค์ค‘ ์ƒ์† ์ง€์› + +> ์ฐธ๊ณ : ์ธํ„ฐํŽ˜์ด์Šค๋Š” โ€˜**default ๋ฉ”์†Œ๋“œ**โ€™ ๊ตฌํ˜„ ๊ฐ€๋Šฅ +> +> Java์˜ Function package -> ์ถ”์ƒ ๋ฉ”์†Œ๋“œ ํ•˜๋‚˜์™€ default ๋ฉ”์†Œ๋“œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ธํ„ฐํŽ˜์ด์Šค +> ๊ฐ์ฒดํ™”๋œ ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค์— default ๋ฉ”์†Œ๋“œ๊ฐ€ ์กด์žฌํ•˜์—ฌ ์ถ”๊ฐ€ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค. + +--- +### ์ƒ์† +- ์ƒ์œ„ ํด๋ž˜์Šค์˜ ํ•„๋“œ, ๋ฉ”์†Œ๋“œ๋“ค์„ ๋ฌผ๋ ค๋ฐ›์„ ์ˆ˜ ์žˆ์Œ +- ํ™•์žฅ์„ฑ, ์ฝ”๋“œ์˜ ์žฌ์‚ฌ์šฉ์„ฑ, ๋‹คํ˜•์„ฑ ์ œ๊ณต +- ํด๋ž˜์Šค๋Š” ๋‹ค์ค‘ ์ƒ์†์ด ๋ถˆ๊ฐ€๋Šฅ +- ์ธํ„ฐํŽ˜์ด์Šค๋Š” ๋‹ค์ค‘ ์ƒ์†์ด ๊ฐ€๋Šฅ +- ์ƒ์œ„ ํด๋ž˜์Šค์˜ ํ•„๋“œ, ๋ฉ”์†Œ๋“œ์— ์ ‘๊ทผํ•  ๋•Œ **super** ๊ฐ€ ์‚ฌ์šฉ๋œ๋‹ค. ํŠนํžˆ ์ƒ์„ฑ์ž ํ˜ธ์ถœ ์‹œ ์‚ฌ์šฉ๋œ๋‹ค. + + +--- +### ๋ฉด์ ‘ ์˜ˆ์ƒ ์งˆ๋ฌธ + +**Q. protected ์ ‘๊ทผ ์ œ์–ด์ž๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์–ด๋–ค ์ƒํ™ฉ์—์„œ ์œ ์šฉํ• ๊นŒ์š”?** +- ์ƒ์† ์‹œ, ํ•˜์œ„ ํด๋ž˜์Šค์—์„œ ์ƒ์œ„ ํด๋ž˜์Šค์˜ ํ•„๋“œ, ๋ฉ”์†Œ๋“œ์— ์ ‘๊ทผ๊ฐ€๋Šฅ ํ•˜๋„๋ก ํ•  ๋•Œ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค. + + +**Q. ์ž๋ฐ”์—์„œ ๋‹ค์ค‘ ์ƒ์†์„ ์ง์ ‘ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?** + +- **๋‹ค์ด์•„๋ชฌ๋“œ ๋ฌธ์ œ**๊ฐ€ ๋ฐœ์ƒ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. +- ๋‘ ๋ถ€๋ชจ ํด๋ž˜์Šค๊ฐ€ ๋™์ผํ•œ ๋ฉ”์†Œ๋“œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ , ํ•˜์œ„ ํด๋ž˜์Šค๊ฐ€ ๋‘ ๋ถ€๋ชจ ํด๋ž˜์Šค๋ฅผ ๋ชจ๋‘ ์ƒ์† ๋ฐ›์œผ๋ฉด, ์–ด๋–ค ๋ถ€๋ชจ์˜ ๋ฉ”์†Œ๋“œ๋ฅผ ์ƒ์†๋ฐ›์„ ์ง€ ๋ชจํ˜ธํ•ด์ง‘๋‹ˆ๋‹ค. + +**๋‹ค์ด์•„๋ชฌ๋“œ** +``` + A + / \ + B C + \ / + D + +``` + +์ƒ์œ„ํด๋ž˜์Šค A๋ฅผ ์ƒ์†๋ฐ›๋Š” B,C๊ฐ€ ์žˆ๊ณ , B,C๋ฅผ ์ƒ์†๋ฐ›๋Š” D๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค. +D ํด๋ž˜์Šค๋Š” A ํด๋ž˜์Šค์˜ ๋ฉ”์†Œ๋“œ๋ฅผ ๋‘ ๋ฒˆ ์ƒ์†๋ฐ›์•„ B์™€ C์ค‘ ์–ด๋–ค ๊ฒƒ์„ ์ƒ์†๋ฐ›์•„์•ผ ํ•  ์ง€ ๊ณค๋ž€ํ•ด์ง‘๋‹ˆ๋‹ค. + +java interface๋Š” **super** ํ‚ค์›Œ๋“œ๋ฅผ ํ†ตํ•ด์„œ ์–ด๋–ค ๋ถ€๋ชจ ํด๋ž˜์Šค์˜ ๋ฉ”์†Œ๋“œ๋ฅผ ์ƒ์†๋ฐ›์„ ์ง€ ์„ ํƒ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. + +```java +interface A { + default void method() { + ... + } +} + +interface B extends A { +} + +interface C extends A { +} + +class D implements B, C { + + @Override + public void method() { + B.super.method(); + } +} + +``` \ No newline at end of file diff --git a/mission/chaptor01/mission.md b/mission/chaptor01/mission.md new file mode 100644 index 0000000..e1c2931 --- /dev/null +++ b/mission/chaptor01/mission.md @@ -0,0 +1,3 @@ +๐Ÿ”ฅ **๋ฏธ์…˜** +--- +![KakaoTalk_Photo_2024-09-27-14-48-50](https://github.com/user-attachments/assets/b8cb3acd-51b2-4519-99f8-6223fa3ae491) diff --git a/mission/chaptor03/java_mission.md b/mission/chaptor03/java_mission.md new file mode 100644 index 0000000..6c2eda2 --- /dev/null +++ b/mission/chaptor03/java_mission.md @@ -0,0 +1,410 @@ +# โœš ์ถ”๊ฐ€๋ฏธ์…˜ + +## **1. ์ œ๋„ค๋ฆญ๊ณผ ์™€์ผ๋“œ์นด๋“œ** + +### ์ œ๋„ค๋ฆญ์ด ํ•„์š”ํ•œ ์ด์œ  + +์ค‘๋ณต์ฝ”๋“œ๋ฅผ ์ œ๊ฑฐํ•˜๊ธฐ ์œ„ํ•ด์„œ, ๋‹คํ˜•์„ฑ์„ ํ†ตํ•ด ์ค‘๋ณต ํ•ด๊ฒฐ์„ ์‹œ๋„ํ•  ์ˆ˜ ์žˆ๋‹ค. +```java + public class ObjectBox { + private Object value; + public void set(Object object) { + this.value = object; + } + public Object get() { + return value; + } +} +``` + +- ์œ„์™€ ๊ฐ™์€ ์ฝ”๋“œ๋Š” **ํƒ€์ž… ์•ˆ์ •์„ฑ**์ด ๋งค์šฐ ๋–จ์–ด์ง€๊ฒŒ ๋œ๋‹ค. +- ์‹ค์ œ ๋ฐ์ดํ„ฐ๋ฅผ ObjectBox์— ๋‹ด๊ณ  ์ด๋ฅผ ๊ฐ€์ ธ์˜ค๋ฉด ๋ฆฌํ„ดํƒ€์ž…์€ Object ์—ฌ์„œ ์ด๋ฅผ ๋‹ค์šด์บ์ŠคํŒ…์„ ํ†ตํ•ด์„œ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค. +- ๋งค๊ฐœ๋ณ€์ˆ˜๋„ Object ์ด๊ธฐ ๋•Œ๋ฌธ์— ์ปดํŒŒ์ผ ํƒ€์ž„์— ์–ด๋–ค ๊ฐ’์ด ๋“ค์–ด์˜ค๋”๋ผ๋„ ์ปดํŒŒ์ผ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค. + + +### ์ œ๋„ค๋ฆญ ์ ์šฉ + +```java + public class GenericBox { + private T value; + public void set(T value) { + this.value = value; + } + public T get() { + return value; + } +} +``` + +- T๋ผ๋Š” ํƒ€์ž… ๋งค๊ฐœ ๋ณ€์ˆ˜๋ฅผ ์ง€์ •ํ•ด์„œ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ๋˜๋ฉด, ์ปดํŒŒ์ผ ํƒ€์ž„์— ํƒ€์ž… ์•ˆ์ •์„ฑ ๋ณด์žฅ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. + ์šฐ๋ฆฌ๋Š” ์ œ๋„ค๋ฆญ์„ ํ†ตํ•ด์„œ **์ฝ”๋“œ ์žฌ์‚ฌ์šฉ๊ณผ ํƒ€์ž… ์•ˆ์ •์„ฑ** ๋‘ ๋งˆ๋ฆฌ ํ† ๋ผ๋ฅผ ์žก์„ ์ˆ˜ ์žˆ๋‹ค. +- **์ œ๋„ค๋ฆญ์„ ํ†ตํ•ด์„œ ์‚ฌ์šฉํ•  ํƒ€์ž…์— ๋Œ€ํ•œ ๊ฒฐ์ •์„ ๋‚˜์ค‘์œผ๋กœ ๋ฏธ๋ฃจ๋Š” ๊ฒƒ์ด๋‹ค.** + + +**์ œ๋„ค๋ฆญ ํƒ€์ž…์„ ์ง€์ •ํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ** +```java +GenericBox integerBox = new GenericBox(); // ๋น„์ถ”์ฒœ + +GenericBox integerBox = new GenericBox<>(); // ๋™์ผํ•œ ์ฝ”๋“œ +``` +- ์ œ๋„ค๋ฆญ ํƒ€์ž…์„ ์ง€์ •ํ•˜์ง€ ์•Š๊ณ  ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๊ธด ํ•˜์ง€๋งŒ, ์ถ”์ฒœํ•˜์ง€ ์•Š๋Š”๋‹ค. + + + +### ํƒ€์ž… ์ถ”๋ก  + +- ์ œ๋„ค๋ฆญ ํƒ€์ž… +```java +GenericBox integerBox = new GenericBox() // ํƒ€์ž… ์ง์ ‘ ์ž…๋ ฅ GenericBox integerBox2 = new GenericBox<>() // ํƒ€์ž… ์ถ”๋ก  + +``` +- ์ œ๋„ค๋ฆญ ๋ฉ”์„œ๋“œ +```java +Integer i = 10; + +Integer result = GenericMethod.genericMethod(i); // ํƒ€์ž… ์ง์ ‘ ์ž…๋ ฅ +Integer result2 = GenericMethod.genericMethod(i); // ํƒ€์ž… ์ถ”๋ก  + +``` + + +### ํƒ€์ž… ๋งค๊ฐœ๋ณ€์ˆ˜ ์ƒํ•œ ์ œํ•œ +```java +public class AnimalHospitalV2 { + + private T animal; + + public void set(T animal) { + this.animal = animal; + } + + public void checkup() {โ€จ // T์˜ ํƒ€์ž…์„ ๋ฉ”์„œ๋“œ๋ฅผ ์ •์˜ํ•˜๋Š” ์‹œ์ ์—๋Š” ์•Œ ์ˆ˜ ์—†๋‹ค. Object์˜ ๊ธฐ๋Šฅ๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅ โ€จโ€จ System.out.println("๋™๋ฌผ ์ด๋ฆ„: " + animal.getName()); // ์ปดํŒŒ์ผ ์˜ค๋ฅ˜ + animal.sound(); // ์ปดํŒŒ์ผ ์˜ค๋ฅ˜ + } + + public T getBigger(T target) { + // ์ปดํŒŒ์ผ ์˜ค๋ฅ˜ + return animal.getSize() > target.getSize() ? animal : target; + } +} + +``` + +์œ„์™€ ๊ฐ™์€ ์ œ๋„ค๋ฆญ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๋ฉด, `Animal` ์ด๋ผ๋Š” ํด๋ž˜์Šค์˜ `getName`, `sound`, `getSize` ์™€ ๊ฐ™์€ ๊ธฐ๋Šฅ๋“ค์€ ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•œ๋‹ค. ์‹ค์ œ ๊ฐ์ฒด๊ฐ€ ์ƒ์„ฑ๋  ๋•Œ, ์–ด๋–ค ํƒ€์ž… ์ธ์ž๊ฐ€ ๋“ค์–ด์˜ฌ์ง€ ๋ชจ๋ฅด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. + + +๋”ฐ๋ผ์„œ ์šฐ๋ฆฌ๋Š” `extends` ๋ฅผ ํ†ตํ•ด **ํƒ€์ž… ๋งค๊ฐœ๋ณ€์ˆ˜์˜ ์ƒํ•œ์„ ์„ ์ง€์ •**ํ•œ๋‹ค. +```java + public class AnimalHospitalV3 { + +... +``` + +์ด๋ฅผ ํ†ตํ•ด, ํƒ€์ž… ์ธ์ž๋กœ ๋“ค์–ด์˜ค๋Š” ๊ฐ์ฒด๋Š” Animal์˜ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๋Š” ๋ณด์žฅ์ด ์ƒ๊ธฐ๊ธฐ ๋•Œ๋ฌธ์— Animal์ด ์ œ๊ณตํ•˜๋Š” ๊ธฐ๋Šฅ๋“ค์„ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค. + + +### ์ œ๋„ค๋ฆญ ๋ฉ”์„œ๋“œ +```java + public static T genericMethod(T t) { + System.out.println("generic print: " + t); + return t; + } + + public static T numberMethod(T t) { + System.out.println("bound print: " + t); + return t; + } + +``` + +์ œ๋„ค๋ฆญ ํƒ€์ž…๊ณผ ์ œ๋„ค๋ฆญ ๋ฉ”์„œ๋“œ๋Š” ๋ณ„๊ฐœ์˜ ๊ธฐ๋Šฅ์ด๋‹ค. ํ•˜์ง€๋งŒ ํ•จ๊ป˜ ์‚ฌ์šฉ์€ ๊ฐ€๋Šฅํ•˜๋‹ค. + +**์ œ๋„ค๋ฆญ ๋ฉ”์„œ๋“œ์˜ ํŠน์ง•** +- ์ œ๋„ค๋ฆญ ๋ฉ”์„œ๋“œ๋Š” ๋ฉ”์„œ๋“œ ๋‚ด์—์„œ ์ œ๋„ค๋ฆญ์„ ๋„์ž…ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค. +- ๋ฆฌํ„ด ํƒ€์ž… ์™ผ์ชฝ์— ์ œ๋„ค๋ฆญ ํƒ€์ž…์„ ๋ช…์‹œํ•œ๋‹ค. +- static ๋ฉ”์†Œ๋“œ๋ฅผ ์ œ๋„ค๋ฆญ ๋ฉ”์†Œ๋“œ๋กœ ๋งŒ๋“ค ๋•Œ, (ํด๋ž˜์Šค)์ œ๋„ค๋ฆญ ํƒ€์ž…๊ณผ ํ˜ธํ™˜ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค. + - ์™œ๋ƒํ•˜๋ฉด, ์‹ค์ œ ์ œ๋„ค๋ฆญ ํด๋ž˜์Šค๊ฐ€ ์ƒ์„ฑ๋˜๊ธฐ ์ „๊นŒ์ง€๋Š” (ํด๋ž˜์Šค)์ œ๋„ค๋ฆญ ํƒ€์ž…์— ์–ด๋–ค ํƒ€์ž…์ด ๋“ค์–ด์˜ฌ ์ง€ ๋ชจ๋ฅด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. +- ์ธ์Šคํ„ด์Šค ๋ฉ”์„œ๋“œ๋Š” (ํด๋ž˜์Šค)์ œ๋„ค๋ฆญ ํƒ€์ž…๊ณผ ํ˜ธํ™˜ ๊ฐ€๋Šฅํ•˜๋‹ค. ์šฐ์„ ์ˆœ์œ„๋Š” ์ธ์Šคํ„ด์Šค ๋ฉ”์„œ๋“œ๊ฐ€ ๋จผ์ € ๊ฐ€์ ธ๊ฐ„๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ํ˜ผ๋™์„ ์ค„์ด๊ธฐ ์œ„ํ•ด ์ค‘๋ณตํ•ด์„œ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋„๋ก ํ•˜์ž. +- ์ œ๋„ค๋ฆญ ๋ฉ”์„œ๋“œ๋„ ๋™์ผํ•˜๊ฒŒ `extends` ๋กœ ์ƒํ•œ์„ ์ง€์ •๊ฐ€๋Šฅํ•˜๋‹ค. + - ์ƒํ•œ์„ ์ง€์ •ํ•˜๋ฉด ์ง€์ •ํ•œ ํด๋ž˜์Šค์˜ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๋‹ค. + + + +### ์™€์ผ๋“œ ์นด๋“œ + +- ์ œ๋„ค๋ฆญ ํƒ€์ž…์„ ์กฐ๊ธˆ ๋” ํŽธ๋ฆฌํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์ œ๊ณตํ•˜๋Š” ๊ธฐ๋Šฅ์ด๋‹ค. +- `?` ์„ ํ†ตํ•ด์„œ ์ •์˜ํ•œ๋‹ค. +- ๋™์ผํ•˜๊ฒŒ ์ƒํ•œ์„  ์ง€์ •์ด ๊ฐ€๋Šฅํ•˜๋‹ค. +- ์™€์ผ๋“œ์นด๋“œ๋Š” ํ•˜ํ•œ์„  ์ง€์ •๋„ ๊ฐ€๋Šฅํ•˜๋‹ค. + +**์ œ๋„ค๋ฆญ ๋ฉ”์„œ๋“œ vs ์™€์ผ๋“œ ์นด๋“œ** +```java + static void printGenericV1(Box box) { + System.out.println("T = " + box.get()); + } + + static void printWildcardV1(Box box) { + System.out.println("? = " + box.get()); + } + + // ์ƒํ•œ์„  ์ง€์ • + static T printAndReturnGeneric(Box box) { + T t = box.get(); + System.out.println("์ด๋ฆ„ = " + t.getName()); + return t; + } + + // ์ƒํ•œ์„  ์ง€์ • + static Animal printAndReturnWildcard(Box box) { + Animal animal = box.get(); + System.out.println("์ด๋ฆ„ = " + animal.getName()); + return animal; + } +} + +``` + +**์™€์ผ๋“œ ์นด๋“œ๋Š” ์ œ๋„ค๋ฆญ ํƒ€์ž…์ด๋‚˜, ์ œ๋„ค๋ฆญ ๋ฉ”์„œ๋“œ๋ฅผ ์„ ์–ธํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋‹ค. ์™€์ผ๋“œ ์นด๋“œ๋Š” ์ด๋ฏธ ๋งŒ๋“ค์–ด์ง„ ์ œ๋„ค๋ฆญ ํƒ€์ž…์„ ํ™œ์šฉํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.** + +๊ทธ๋ ‡๋‹ค๋ฉด ์™€์ผ๋“œ ์นด๋“œ, ์ œ๋„ค๋ฆญ ๋ฉ”์†Œ๋“œ ์ค‘ ๋ฌด์—‡์„ ์จ์•ผํ• ๊นŒ? ๋ณดํ†ต ๋‹จ์ˆœํ•œ ์™€์ผ๋“œ ์นด๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋˜, ์ œ๋„ค๋ฆญ ๋ฉ”์„œ๋“œ๊ฐ€ ํ•„์š”ํ•œ ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. ์ด๋Ÿด ๋• ์ œ๋„ค๋ฆญ ๋ฉ”์„œ๋“œ๋ฅผ ์จ์•ผํ•œ๋‹ค. + +**ํƒ€์ž… ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ๊ผญ ํ•„์š”ํ•œ ๊ฒฝ์šฐ** +```java + static T printAndReturnGeneric(Box box) { + T t = box.get(); + System.out.println("์ด๋ฆ„ = " + t.getName()); + return t; +} + +static Animal printAndReturnWildcard(Box box) { + Animal animal = box.get();โ€จ System.out.println("์ด๋ฆ„ = " + animal.getName());โ€จ return animal; +} + +... + +Dog dog = WildcardEx.printAndReturnGeneric(dogBox) + +Animal animal = WildcardEx.printAndReturnWildcard(dogBox) + +``` + +์™€์ผ๋“œ ์นด๋“œ๋Š” ๋ฆฌํ„ดํƒ€์ž…์„ ๋ช…ํ™•ํ•˜๊ฒŒ ์ง€์ •ํ•  ์ˆ˜ ์—†๋Š” ๋ฐ˜๋ฉด, ์ œ๋„ค๋ฆญ ๋ฉ”์„œ๋“œ๋Š” ๋ช…ํ™•ํ•œ ํƒ€์ž…์„ ๋ฆฌํ„ดํ•  ์ˆ˜ ์žˆ๋‹ค. + + +## ํ•˜ํ•œ ์™€์ผ๋“œ ์นด๋“œ +```java + public class WildcardMain2 { + public static void main(String[] args) { + Box objBox = new Box<>(); + Box animalBox = new Box<>(); + Box dogBox = new Box<>(); + Box catBox = new Box<>(); + + // Animal ํฌํ•จ ์ƒ์œ„ ํƒ€์ž… ์ „๋‹ฌ ๊ฐ€๋Šฅ + writeBox(objBox); + writeBox(animalBox); + writeBox(dogBox); // ์ปดํŒŒ์ผ ์—๋Ÿฌ, ํ•˜ํ•œ์ด Animal + writeBox(catBox); // ์ปดํŒŒ์ผ ์—๋Ÿฌ, ํ•˜ํ•œ์ด Animal + + Animal animal = animalBox.get(); + System.out.println("animal = " + animal); + } + + static void writeBox(Box box) { + box.set(new Dog("๋ฉ๋ฉ์ด", 100)); + } +} + +``` + +- ํ•˜ํ•œ์„ Animal๋กœ ์ œํ•œํ–ˆ๊ธฐ ๋•Œ๋ฌธ์—, Animal์˜ ํ•˜์œ„ ํƒ€์ž…์ธ Dog, Cat์€ ์ „๋‹ฌํ•  ์ˆ˜ ์—†๋‹ค. + + +### ํƒ€์ž… ์ด๋ ˆ์ด์ € + +์ œ๋„ค๋ฆญ์€ ์ž๋ฐ” ์ปดํŒŒ์ผ ๋‹จ๊ณ„์—์„œ๋งŒ ์‚ฌ์šฉ๋˜๊ณ , ์ปดํŒŒ์ผ ์ดํ›„์—๋Š” ์ œ๋„ค๋ฆญ ์ •๋ณด๊ฐ€ ์‚ญ์ œ๋œ๋‹ค. ์ปดํŒŒ์ผ ์ „์ธ `.java` +์—๋Š” ์ œ๋„ค๋ฆญ์˜ ํƒ€์ž… ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์กด์žฌํ•˜์ง€๋งŒ, ์ปดํŒŒ์ผ ์ดํ›„์ธ ์ž๋ฐ” ๋ฐ”์ดํŠธ์ฝ”๋“œ `.class`์—๋Š” ํƒ€์ž… ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด๋‹ค. + +**์ปดํŒŒ์ผ ์ „** +```java + public class GenericBox { + + private T value; + + public void set(T value) { + this.value = value; + } + + public T get() { + return value; + } +} + +``` + +**์ปดํŒŒ์ผ ์ดํ›„** +```java + public class GenericBox { + + private Object value; + + public void set(Object value) { + this.value = value; + } + + public Object get() { + return value; +} + +``` +- ์ปดํŒŒ์ผ ์ดํ›„์—๋Š” T๊ฐ€ Object ํƒ€์ž…์œผ๋กœ ๋Œ€์ฒด๋œ๋‹ค. +- ์ƒํ•œ ์ œํ•œ์ด ์žˆ์„ ๊ฒฝ์šฐ, T๊ฐ€ ๋ช…์‹œํ•œ ์ƒํ•œ์œผ๋กœ ๋Œ€์ฒด๋œ๋‹ค. + + +```java +Integer result = (Integer) box.get(); //์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ์บ์ŠคํŒ… ์ถ”๊ฐ€ +``` + +- ๊ทธ๋ฆฌ๊ณ  ์‹ค์ œ๋กœ ์ด๋ฅผ ์ƒ์„ฑํ•œ ํด๋ž˜์Šค์—์„œ๋Š” ์ง€์ •ํ•œ ํƒ€์ž…์œผ๋กœ ์บ์ŠคํŒ…ํ•œ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค. +- ์ž๋ฐ” ์ปดํŒŒ์ผ๋Ÿฌ๋Š” ์ปดํŒŒ์ผ ์‹œ์ ์— ์ œ๋„ค๋ฆญ์„ ์‚ฌ์šฉํ•œ ์ฝ”๋“œ์— ๋ฌธ์ œ๊ฐ€ ์—†๋Š”์ง€ ๊ฒ€์ฆ์„ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค. +- ๋Ÿฐํƒ€์ž„ ์‹œ์—๋Š” ์ œ๋„ค๋ฆญ ์ •๋ณด๊ฐ€ ์ง€์›Œ์ง€๋Š” ๊ฒƒ์„ ํƒ€์ž… ์ด๋ ˆ์ด์ €๋ผ๊ณ  ํ•œ๋‹ค. + +### ํƒ€์ž… ์ด๋ ˆ์ด์ € ๋ฐฉ์‹์˜ ํ•œ๊ณ„ +์ž๋ฐ”๋Š” ์ž๋ฐ” ์•„๋ž˜๋ฒ„์ „๊ณผ ํ˜ธํ™˜์„ฑ์„ ์œ„ํ•ด์„œ ์ œ๋„ค๋ฆญ์„ ํƒ€์ž… ์ด๋ ˆ์ด์ € ๋ฐฉ์‹์œผ๋กœ ์ง€์›ํ•œ๋‹ค. ์ด์— ๋”ฐ๋ผ์„œ ๋ฐœ์ƒํ•˜๋Š” ํ•œ๊ณ„์ ์ด ์กด์žฌํ•œ๋‹ค. + +```java + class EraserBox { + + public boolean instanceCheck(Object param) { + return param instanceof T; // ์˜ค๋ฅ˜ + } + + public void create() { + return new T(); // ์˜ค๋ฅ˜ + } +} + +``` + +- `instance of T` ๋Š” ๊ฒฐ๊ตญ ๋Ÿฐํƒ€์ž„์—๋Š” `instance of Object`๋กœ ๋ฐ”๋€Œ์–ด๋ฒ„๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์— ๋ชจ๋“  ๊ฐ’์ด true๋กœ ๋ฐ˜ํ™˜๋˜์–ด ๋ฒ„๋ฆฐ๋‹ค. ๋”ฐ๋ผ์„œ instance of ๋ฅผ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. +- `new T()` ๋Š” ๊ฒฐ๊ตญ ๋Ÿฐํƒ€์ž„์—๋Š” `new Object()` ๋กœ ๋ฐ”๋€Œ์–ด๋ฒ„๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์— ๊ฐœ๋ฐœ์ž๊ฐ€ ์˜๋„ํ•œ ๋ฐ”์™€ ๋‹ฌ๋ผ์„œ `new`๋ฅผ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. + + +---- +## **2. ๋ž˜ํผ ํด๋ž˜์Šค** + +### ๊ธฐ๋ณธํ˜•์˜ ํ•œ๊ณ„ +์ž๋ฐ”๋Š” ๊ฐ์ฒด ์ง€ํ–ฅ ์–ธ์–ด์ด๋‹ค. ์ž๋ฐ”์—๋Š” ๊ฐ์ฒด๊ฐ€ ์•„๋‹Œ ๊ธฐ๋ณธํ˜•์ด ์กด์žฌํ•˜๋Š”๋ฐ, ๊ธฐ๋ณธํ˜•์—๋Š” ํ•œ๊ณ„๊ฐ€ ์กด์žฌํ•œ๋‹ค. +- **๊ฐ์ฒด๊ฐ€ ์•„๋‹˜** + - ๋ฉ”์„œ๋“œ๋ฅผ ์ œ๊ณตํ•˜์ง€ ๋ชปํ•œ๋‹ค. + - ๊ฐ์ฒด ์ฐธ์กฐ๊ฐ€ ํ•„์š”ํ•œ ์ปฌ๋ ‰์…˜ ํ”„๋ ˆ์ž„์›Œํฌ, ์ œ๋„ค๋ฆญ์„ ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•œ๋‹ค. +- **null ๊ฐ’์„ ๊ฐ€์งˆ ์ˆ˜ ์—†์Œ** + - ๋•Œ๋กœ๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ์—†๋Š” ์ƒํƒœ๋ฅผ ํ‘œํ˜„ํ•˜๊ณ  ์‹ถ์ง€๋งŒ ์ด๋ฅผ ํ‘œํ˜„ํ•˜์ง€ ๋ชปํ•œ๋‹ค. + +### ๋ž˜ํผ ํด๋ž˜์Šค์˜ ํŠน์ง• +- ๊ธฐ๋ณธํ˜•์˜ ๊ฐ์ฒด ๋ฒ„์ „ +- ๋ถˆ๋ณ€ +- equals๋กœ ๋น„๊ตํ•ด์•ผํ•จ + +int, Integer๋ฅผ ์˜ˆ์‹œ๋กœ ๋“ค์–ด ์„ค๋ช…ํ•œ๋‹ค. + +**๋ž˜ํผ ํด๋ž˜์Šค ์ƒ์„ฑ - ๋ฐ•์‹ฑ(Boxing)** +```java +Integer i = Integer.valueof(10); +``` +- ์ตœ์ ํ™”: ๊ฐœ๋ฐœ์ž๋“ค์ด ์ผ๋ฐ˜์ ์œผ๋กœ ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” -128 ~ 127 ๋ฒ”์œ„์˜ Integer ํด๋ž˜์Šค๋ฅผ ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•ด๋‘๊ณ , ํ•ด๋‹น ๋ฒ”์œ„์˜ ๊ฐ’์„ ์กฐํšŒํ•˜๋ฉด ๋ฏธ๋ฆฌ ์ƒ์„ฑ๋œ Integer ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. + - ๋งˆ์น˜ ๋ฌธ์ž์—ด ํ’€๊ณผ ๋น„์Šทํ•˜๊ฒŒ ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ์ˆซ์ž๋ฅผ ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•˜๊ณ  ์žฌ์‚ฌ์šฉํ•œ๋‹ค. + +**์–ธ๋ฐ•์‹ฑ(UnBoxing)** +```java +Integer i = Integer.valueof(10); +int unBoxedInt = i.intValue(); +``` + + +**๋น„๊ต๋Š” equals() ์‚ฌ์šฉ** +- ๋ž˜ํผ ํด๋ž˜์Šค๋Š” ๊ฐ์ฒด์ด๊ธฐ ๋•Œ๋ฌธ์— == ๋น„๊ต๋ฅผ ํ•˜๋ฉด ์ธ์Šคํ„ด์Šค์˜ ์ฐธ์กฐ๊ฐ’์„ ๋น„๊ต +- ๋ž˜ํผ ํด๋ž˜์Šค๋Š” ๊ฐ์ฒด ๋‚ด๋ถ€์˜ ๊ฐ’์„ ๋น„๊ตํ•˜๋„๋ก equals()๋ฅผ ์žฌ์ •์˜ํ•ด๋‘์—ˆ๋‹ค. ๊ฐ’ ๋น„๊ต๋ฅผ ์œ„ํ•ด์„œ๋Š” equals()๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค. + + +### ์˜คํ†  ๋ฐ•์‹ฑ, ์–ธ๋ฐ•์‹ฑ +- ์ž๋ฐ” 1.5๋ถ€ํ„ฐ ์˜คํ†  ๋ฐ•์‹ฑ, ์˜คํ†  ์–ธ๋ฐ•์‹ฑ์„ ์ง€์›ํ•œ๋‹ค. +```java +int value = 7; +Integer boxedValue = value // ์˜คํ†  ๋ฐ•์‹ฑ + +int unboxedValue = boxedValue // ์˜คํ†  ์–ธ๋ฐ•์‹ฑ +``` +- ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ valueOf, xxxValue() ๋“ฑ์˜ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๋Š” ๊ธฐ๋Šฅ์ด๋‹ค. + + +### ๋ž˜ํผ ํด๋ž˜์Šค์˜ ์ฃผ์š” ๋ฉ”์„œ๋“œ + +- `valueOf()` : ๋ž˜ํผ ํƒ€์ž…์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ์ˆซ์ž, ๋ฌธ์ž์—ด์„ ๋ชจ๋‘ ์ง€์›ํ•œ๋‹ค. +- `parseInt()` : ๋ฌธ์ž์—ด์„ ๊ธฐ๋ณธํ˜•์œผ๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค. +- `compareTo()` : ๊ฐ’ ๋น„๊ต๋ฅผ ์ง€์›ํ•œ๋‹ค. ๋‚ด ๊ฐ’์ด ํฌ๋ฉด 1, ๊ฐ™์œผ๋ฉด 0, ๋‚ด ๊ฐ’์ด ์ž‘์œผ๋ฉด -1 +- `sum(), min(), max()` : ๊ฐ„๋‹จํ•œ ๋ง์…ˆ, ์ž‘์€ ๊ฐ’, ํฐ ๊ฐ’์„ ๋น„๊ตํ•˜๋Š” static ๋ฉ”์†Œ๋“œ๋ฅผ ์ง€์› + + +### ๋ž˜ํผ ํด๋ž˜์Šค์™€ ์„ฑ๋Šฅ +๋ž˜ํผ ํด๋ž˜์Šค๊ฐ€ ๊ธฐ๋ณธํ˜•๋ณด๋‹ค ์ข‹์€ ๊ฒƒ ๊ฐ™์€๋ฐ, ๊ตณ์ด ๊ธฐ๋ณธํ˜•์ด ์กด์žฌํ•˜๋Š” ์ด์œ ๋Š”? +์„ฑ๋Šฅ์ฐจ์ด๋ฅผ ๋น„๊ตํ•ด๋ณด์ž. + +```java +// ๊ธฐ๋ณธํ˜• +int iterations = 1_000_000_000; +long sumPrimitive = 0; +for(int i = 0; i < iterations; i++) { + sumPrimitive += i; +} + +// ๋ž˜ํผ ํด๋ž˜์Šค +Long sumWrapper = 0L; +for(int i = 0; i < iterations; i++) { + sumPrimitive += i; // ์˜คํ†  ๋ฐ•์‹ฑ ๋ฐ•์ƒ +} + +``` + +- ์ด ๋‘˜์˜ ์„ฑ๋Šฅ์ฐจ์ด๋ฅผ ๋น„๊ตํ•ด๋ณด๋ฉด, ์‹œ์Šคํ…œ๋งˆ๋‹ค ๋‹ค๋ฅด๊ฒ ์ง€๋งŒ ๊ธฐ๋ณธํ˜• ๊ณ„์‚ฐ์ด 5๋ฐฐ ์ •๋„ ๋น ๋ฅด๋‹ค. +- ๋ž˜ํผ ํด๋ž˜์Šค๋Š” ๊ฐ์ฒด์ด๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ์ฒด ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๋ฅผ ํฌํ•จํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ถ”๊ฐ€๋กœ ์‚ฌ์šฉํ•œ๋‹ค. + +์‚ฌ์‹ค ๊ทธ๋ ‡๊ฒŒ ์œ ์˜๋ฏธํ•œ ์ฐจ์ด๋Š” ์•„๋‹ˆ์ง€๋งŒ, CPU ์—ฐ์‚ฐ์„ ์•„์ฃผ ๋งŽ์ด ์ˆ˜ํ–‰ํ•˜๋Š” ํŠน์ˆ˜ํ•œ ์ƒํ™ฉ์—๋Š” ๊ธฐ๋ณธํ˜•์„ ๊ณ ๋ คํ•ด๋ณด์ž. ์ผ๋ฐ˜์ ์ธ ๊ฒฝ์šฐ๋Š” ์œ ์ง€๋ณด์ˆ˜ํ•˜๊ธฐ ๋” ๋‚˜์€ ๊ฒƒ์„ ์„ ํƒํ•˜์ž. + + +--- +## **3. Optional** + +> **๊ณต์‹ API ๋ฌธ์„œ : Optional์„ ๋งŒ๋“  ์˜๋„** +> +> ๋ฉ”์†Œ๋“œ๊ฐ€ ๋ฐ˜ํ™˜ํ•  ๊ฒฐ๊ณผ ๊ฐ’์ด '์—†์Œ'์„ ๋ช…๋ฐฑํ•˜๊ฒŒ ํ‘œํ˜„ํ•  ํ•„์š”๊ฐ€ ์žˆ๊ณ , **null์„ ๋ฐ˜ํ™˜ํ•˜๋ฉด ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฐ€๋Šฅ์„ฑ์ด ๋†’์€ ์ƒํ™ฉ์—์„œ ๋ฉ”์†Œ๋“œ์˜ ๋ฐ˜ํ™˜ ํƒ€์ž…์œผ๋กœ Optional์„ ์‚ฌ์šฉํ•˜์ž**๋Š” ๊ฒƒ์ด Optional์„ ๋งŒ๋“  ์ฃผ๋œ ๋ชฉ์ ์ด๋‹ค. + + +### Optional ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์‚ฌ์šฉํ•˜๊ธฐ + +- `Optional`์— ์ ˆ๋Œ€ `null`์„ ํ• ๋‹นํ•˜์ง€ ์•Š๋Š”๋‹ค. ๋น„์–ด์žˆ๋‹ค๋ฉด `Optional.empty()`๋ฅผ ์‚ฌ์šฉ +- `Optional.get()` ํ˜ธ์ถœ์ „์— ๋ฐ˜๋“œ์‹œ ๊ฐ์ฒด๊ฐ€ ๊ฐ’์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•  ๊ฒƒ +- ๊ฐ’์ด ์—†๋Š” ๊ฒฝ์šฐ, `orElse()`๋ฅผ ํ†ตํ•ด ๋””ํดํŠธ ๊ฐ’์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. + - ์ฃผ์˜ํ•  ์ ์œผ๋กœ๋Š” `orElse()`์˜ ๊ด„ํ˜ธ ์•ˆ์—์„œ ์ƒˆ๋กœ์šด ๊ฐ’์„ ์ƒ์„ฑํ•˜์ง€ ๋ง์ž. ์™œ๋ƒํ•˜๋ฉด ์ด ์ฝ”๋“œ๋Š” ํ•ญ์ƒ ์‹คํ–‰๋˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ’์ด ์žˆ๋Š” ์ƒํ™ฉ์—๋„ ์˜๋ฏธ์—†๋Š” ๊ฐ์ฒด๊ฐ€ ๊ณ„์† ์ƒ์„ฑ๋  ์ˆ˜ ์žˆ๋‹ค. +- `orElseGet(Supplier)` ๋Š” `Optional`์˜ ๊ฐ’์ด ์—†์„ ๋•Œ๋งŒ ์‹คํ–‰๋œ๋‹ค. ๋”ฐ๋ผ์„œ ์ƒˆ๋กœ์šด ๊ฐ’์„ ์ƒ์„ฑํ•ด๋„ ๋œ๋‹ค. +- ๊ฐ’์ด ์—†๋Š” ๊ฒฝ์šฐ, `orElseThrow()`๋ฅผ ํ†ตํ•ด์„œ ์˜ˆ์™ธ๋ฅผ ๋˜์งˆ ์ˆ˜ ์žˆ๋”ฐ. +- `ifPresent()` : ๊ฐ’์ด ์žˆ๋Š” ๊ฒฝ์šฐ์— ์ด๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , ์—†๋Š” ๊ฒฝ์šฐ์— ์•„๋ฌด ๋™์ž‘๋„ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ +- `Optional`์„ ํ•„๋“œ ํƒ€์ž…์œผ๋กœ ์‚ฌ์šฉํ•˜์ง€ ๋ง์ž. + - **`Optional`์€ ๋ฐ˜ํ™˜ ํƒ€์ž…์„ ์œ„ํ•ด ์„ค๊ณ„๋œ ํƒ€์ž…**์ด๋‹ค. + - ํด๋ž˜์Šค์˜ ํ•„๋“œ, ํ˜น์€ ๋ฉ”์†Œ๋“œ์˜ ์ธ์ž๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ `Optional` ๋„์ž… ์˜๋„์— ๋ฐ˜ํ•˜๋Š” ํŒจํ„ด +- ๋‹จ์ง€ ๊ฐ’์„ ์–ป์„ ๋ชฉ์ ์ด๋ผ๋ฉด `Optional` ๋Œ€์‹  `null` ๋น„๊ต๋ฅผ ํ•˜์ž. + - `Optional`์€ ๋น„์‹ผ ์—ฐ์‚ฐ์ด๊ธฐ ๋•Œ๋ฌธ์— ๊ณผ๋„ํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜์ง€ ๋ง์•„์•ผ ํ•œ๋‹ค. ๋‹จ์ˆœ๊ฐ’ ํ˜น์€ `null`์„ ์–ป์„ ๋ชฉ์ ์ด๋ผ๋ฉด `Optinoal` ๋Œ€์‹  `null` ๋น„๊ต๋กœ๋„ ์ถฉ๋ถ„ํ•˜๋‹ค. +- `Optinoal`์„ ๋นˆ ์ปฌ๋ ‰์…˜์ด๋‚˜ ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•˜์ง€ ๋ง ๊ฒƒ + - ๊ฐ’์ด ์—†๋Š” ๊ฒฝ์šฐ๋Š” ๋น„์–ด์žˆ๋Š” ์ปฌ๋ ‰์…˜๊ณผ ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•˜๋ฉด ๋œ๋‹ค. +- `Optional`์„ ์ปฌ๋ ‰์…˜์˜ ์›์†Œ๋กœ ์‚ฌ์šฉํ•˜์ง€ ๋ง ๊ฒƒ + - ํŠนํžˆ `Map`๊ณผ ๊ฐ™์€ ๊ฒฝ์šฐ `getOrDefault()` ์™€ ๊ฐ™์€ ๋ฉ”์†Œ๋“œ๋กœ `null` ๋ฐฉ์ง€๋ฅผ ์ถฉ๋ถ„ํžˆ ํ•  ์ˆ˜ ์žˆ๋‹ค. +- `Optional.of()`๋Š” null์ด ์•„๋‹Œ๊ฒŒ ํ™•์‹คํ•  ๋•Œ, `Optinal.ofNullable()`์€ `null`์ผ ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ์„ ๋•Œ ์‚ฌ์šฉ +- ๋‚ด๋ถ€ ๊ฐ’ ๋น„๊ต ์‹œ, `Optional.equals` ์‚ฌ์šฉ ๊ณ ๋ ค + - ๋‚ด๋ถ€ ๊ฐ’ ๋น„๊ต ๊ฐ€๋Šฅํ•˜๋„๋ก ์ด๋ฏธ ๊ตฌํ˜„์ด ๋˜์–ด์žˆ๋‹ค. ๋”ฐ๋ผ์„œ ๊ตณ์ด ๊บผ๋‚ด์„œ ๋น„๊ตํ•  ํ•„์š” ์—†์Œ +- ๊ฐ’์— ๋Œ€ํ•ด ๋ฏธ๋ฆฌ ์ •์˜๋œ ๊ทœ์น™์ด ์žˆ๋Š” ๊ฒฝ์šฐ `filter` ์‚ฌ์šฉ ๊ณ ๋ ค + - `stream` ์ฒ˜๋Ÿผ ํ•„ํ„ฐ๋ฅผ ์ œ๊ณตํ•˜์—ฌ ๋‚ด๋ถ€์— ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌํ˜„ํ•œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๋‹ค. + +์ถœ์ฒ˜: +1. ****๊น€์˜ํ•œ์˜ ์‹ค์ „ ์ž๋ฐ” ์ค‘๊ธ‰ 1ํŽธ - ์ž๋ฐ”์˜ ๋‹ค์–‘ํ•œ ์ค‘๊ธ‰ ๊ธฐ๋Šฅ**** +2. https://dev-coco.tistory.com/178 + diff --git a/mission/chaptor03/mission.md b/mission/chaptor03/mission.md new file mode 100644 index 0000000..ca8012a --- /dev/null +++ b/mission/chaptor03/mission.md @@ -0,0 +1,167 @@ +**1. ํ™ˆ ํ™”๋ฉด** +**GET /api/v1/home** +* **์„ค๋ช…**: ํ™ˆ ํ™”๋ฉด์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค. +* **URL**: /api/v1/home +* **Method**: GET +* **์š”์ฒญ ํ—ค๋”**: + * Authorization: token +* **์‘๋‹ต** +```javascript +{ + "isSuccess": true, + "code": "COMMON200", + "message": "์„ฑ๊ณต", + "result": { + "completedMissionCount": 7, + "missions": [ + { + "restaurantName": "์‹๋‹น์ด๋ฆ„", + "restaurantCategory": "์ค‘์‹", + "missionExpirationDate": "2024-12-31", + "missionDescription": 10000, + "points": 500 + }, + { + "restaurantName": "์‹๋‹น์ด๋ฆ„", + "restaurantCategory": "์ค‘์‹", + "missionExpirationDate": "2024-12-31", + "missionDescription": 10000, + "points": 500 + }, + ] + } +} + +``` +

+**2. ๋งˆ์ด ํŽ˜์ด์ง€ ๋ฆฌ๋ทฐ ์ž‘์„ฑ** +**POST /api/v1/my-page/reviews** +* **์„ค๋ช…**: ๋งˆ์ด ํŽ˜์ด์ง€ ๋ฆฌ๋ทฐ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. +* **URL**: /api/v1/my-page/reviews +* **Method**: POST +* **์š”์ฒญ ํ—ค๋”**: + * Authorization: token +- **์š”์ฒญ BODY**: +```javascript +{ + "missionId": 1, + "restaurantId" : 1 + "rating": 5, + "content": "๋‚ด์šฉ" +} + +``` +* **์‘๋‹ต** +```javascript +{ + "isSuccess": true, + "code": "COMMON200", + "message": "์„ฑ๊ณต", + "result": { + "reviewId": 1 + } +} + +``` +

+**3. ๋ฏธ์…˜ ๋ชฉ๋ก ์กฐํšŒ(์ง„ํ–‰์ค‘, ์ง„ํ–‰ ์™„๋ฃŒ)** +**GET /api/v1/missions** +* **์„ค๋ช…**: ๋ฏธ์…˜ ๋ชฉ๋ก์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค. +* **URL**: /api/v1/missions +* **Method**: GET +* **์š”์ฒญ ํ—ค๋”**: + * Authorization: token +- **์š”์ฒญ ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ:** + - status : progress or completed +- **์š”์ฒญ BODY**: +```javascript +{ + "regionName": "์•ˆ์•”๋™" +} +``` +* **์‘๋‹ต** +```javascript +{ + "isSuccess": true, + "code": "COMMON200", + "message": "์„ฑ๊ณต", + "result": { + "missions": [ + { + "restaurantId": 1, + "restaurantName": "์‹๋‹น์ด๋ฆ„", + "restaurantCategory": "ํ•œ์‹", + "missionPoints": 500 + }, + { + "restaurantId": 2, + "restaurantName": "์‹๋‹น์ด๋ฆ„", + "restaurantCategory": "์–‘์‹", + "missionPoints": 500 + } + ] + } +} + + +``` +

+**4. ๋ฏธ์…˜ ์„ฑ๊ณต ๋ˆ„๋ฅด๊ธฐ** +**POST /api/v1/missions/{mission-id}/completed** +* **์„ค๋ช…**: ํŠน์ • ๋ฏธ์…˜์˜ ์„ฑ๊ณต ํ›„ ์‚ฌ์žฅ๋‹˜๊ป˜ ์š”์ฒญํ•ฉ๋‹ˆ๋‹ค. +* **URL**: /api/v1/missions/{mission-id}/completed +* **Method**: POST +* **์š”์ฒญ ํ—ค๋”**: + * Authorization: token +* **์‘๋‹ต** +```javascript +{ + "isSuccess": true, + "code": "COMMON200", + "message": "์„ฑ๊ณต", + "result": { + "missionId": 1, + "bossAuthCode": "9201982309" + } +} +``` +

+**5. ํšŒ์› ๊ฐ€์ž… ํ•˜๊ธฐ(์†Œ์…œ ๋กœ๊ทธ์ธ ๊ณ ๋ ค X)** +**POST /api/v1/users/sign-up** +* **์„ค๋ช…**: ํšŒ์› ๊ฐ€์ž… ํ•˜๊ธฐ +* **URL**: /api/v1/users/sign-up +* **Method**: POST +* **์š”์ฒญ BODY** +```javascript +{ + "name": "ํ™๊ธธ๋™", + "gender": "๋‚จ์ž", + "birthYear": 2000, + "birthMonth": 1, + "birthDay": 1, + "address": "์ธ์ฒœ๊ด‘์—ญ์‹œ OO๊ตฌ OO๊ธธ OO", + "detailedAddress": "OOOํ˜ธ", + "preferredFoodCategories": ["ํ•œ์‹", "์–‘์‹", "์ผ์‹"] +} +``` +- **์‘๋‹ต BODY** +```javascript +{ + "isSuccess": true, + "code": "COMMON200", + "message": "์„ฑ๊ณต", + "result": {} +} +``` +

+**6. ์—๋Ÿฌ** +- **์„ค๋ช…:** ์—๋Ÿฌ ์‘๋‹ต ํ˜•์‹์„ ์„ค๋ช… +- **์‘๋‹ต BODY** +```javascript +{ + "isSuccess": false, + "code": "COMMON500", + "message": "์„œ๋ฒ„ ์—๋Ÿฌ, ๊ด€๋ฆฌ์ž์—๊ฒŒ ๋ฌธ์˜ ๋ฐ”๋ž๋‹ˆ๋‹ค.", + "result": null +} +``` diff --git a/mission/chaptor04/code/functionalinterface/anonymousclass/Converter.java b/mission/chaptor04/code/functionalinterface/anonymousclass/Converter.java new file mode 100644 index 0000000..4dac5b1 --- /dev/null +++ b/mission/chaptor04/code/functionalinterface/anonymousclass/Converter.java @@ -0,0 +1,10 @@ +package functionalinterface.anonymousclass; + +import java.util.function.Function; + +public interface Converter extends Function { + + @Override + String apply(Integer t); + +} \ No newline at end of file diff --git a/mission/chaptor04/code/functionalinterface/anonymousclass/Main.java b/mission/chaptor04/code/functionalinterface/anonymousclass/Main.java new file mode 100644 index 0000000..517420e --- /dev/null +++ b/mission/chaptor04/code/functionalinterface/anonymousclass/Main.java @@ -0,0 +1,25 @@ +package functionalinterface.anonymousclass; + +public class Main { + + public static void main(String[] args) { + // given + Integer value = 3; + String expected = "3"; + + Converter converter = new Converter() { + @Override + public String apply(Integer value) { + return String.valueOf(value); + } + }; + + // when + String result = converter.apply(value); + + // then + boolean output = result.equals(expected); + System.out.println("output = " + output); + } + +} diff --git a/mission/chaptor04/code/functionalinterface/inheritance/Converter.java b/mission/chaptor04/code/functionalinterface/inheritance/Converter.java new file mode 100644 index 0000000..32e3415 --- /dev/null +++ b/mission/chaptor04/code/functionalinterface/inheritance/Converter.java @@ -0,0 +1,12 @@ +package functionalinterface.inheritance; + +import java.util.function.Function; + +public class Converter implements Function { + + @Override + public String apply(Integer t) { + return String.valueOf(t); + } + +} \ No newline at end of file diff --git a/mission/chaptor04/code/functionalinterface/inheritance/Main.java b/mission/chaptor04/code/functionalinterface/inheritance/Main.java new file mode 100644 index 0000000..3511b2f --- /dev/null +++ b/mission/chaptor04/code/functionalinterface/inheritance/Main.java @@ -0,0 +1,22 @@ +package inheritanceclass; + +import functionalinterface.inheritance.Converter; + +public class Main { + + public static void main(String[] args) { + // given + Integer value = 3; + String expected = "3"; + + Converter converter = new Converter(); + + // when + String result = converter.apply(value); + + // then + boolean output = result.equals(expected); + System.out.println("output = " + output); + } + +} diff --git a/mission/chaptor04/code/functionalinterface/lamda/Converter.java b/mission/chaptor04/code/functionalinterface/lamda/Converter.java new file mode 100644 index 0000000..c06eca1 --- /dev/null +++ b/mission/chaptor04/code/functionalinterface/lamda/Converter.java @@ -0,0 +1,10 @@ +package functionalinterface.lamda; + +import java.util.function.Function; + +@FunctionalInterface +public interface Converter extends Function { + + String apply(Integer t); + +} diff --git a/mission/chaptor04/code/functionalinterface/lamda/Main.java b/mission/chaptor04/code/functionalinterface/lamda/Main.java new file mode 100644 index 0000000..822608f --- /dev/null +++ b/mission/chaptor04/code/functionalinterface/lamda/Main.java @@ -0,0 +1,21 @@ +package functionalinterface.lamda; + +public class Main { + + + public static void main(String[] args) { + // given + Integer value = 3; + String expected = "3"; + + Converter converter = (i) -> String.valueOf(i); + + // when + String result = converter.apply(value); + + // then + boolean output = result.equals(expected); + System.out.println("output = " + output); + } + +} diff --git a/mission/chaptor04/code/functionalinterface/methodreference/Converter.java b/mission/chaptor04/code/functionalinterface/methodreference/Converter.java new file mode 100644 index 0000000..1c00171 --- /dev/null +++ b/mission/chaptor04/code/functionalinterface/methodreference/Converter.java @@ -0,0 +1,10 @@ +package functionalinterface.methodreference; + +import java.util.function.Function; + +@FunctionalInterface +public interface Converter extends Function { + + String apply(Integer t); + +} diff --git a/mission/chaptor04/code/functionalinterface/methodreference/Main.java b/mission/chaptor04/code/functionalinterface/methodreference/Main.java new file mode 100644 index 0000000..fcb067f --- /dev/null +++ b/mission/chaptor04/code/functionalinterface/methodreference/Main.java @@ -0,0 +1,21 @@ +package functionalinterface.methodreference; + +public class Main { + + + public static void main(String[] args) { + // given + Integer value = 3; + String expected = "3"; + + Converter converter = String::valueOf; + + // when + String result = converter.apply(value); + + // then + boolean output = result.equals(expected); + System.out.println("output = " + output); + } + +} diff --git a/mission/chaptor04/code/stream/Main.java b/mission/chaptor04/code/stream/Main.java new file mode 100644 index 0000000..9bc7c72 --- /dev/null +++ b/mission/chaptor04/code/stream/Main.java @@ -0,0 +1,33 @@ +package stream; + +import java.util.Arrays; +import java.util.List; + +public class Main { + + public static void main(String[] args) { + // given + List collectionList = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Integer[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + + // when + List collectionResult = collectionList.stream() + .map(i -> 2 * i) // Function + .toList(); + + List arrayResult = Arrays.stream(array) + .map(i -> 2 * i) // Function + .toList(); + + // then + System.out.println("collectionList = " + collectionList); + System.out.println("collectionResult = " + collectionResult); + + Arrays.stream(array) + .forEach(System.out::print); + System.out.println(); + + System.out.println("arrayResult = " + arrayResult); + } + +} \ No newline at end of file diff --git a/mission/chaptor04/java_mission.md b/mission/chaptor04/java_mission.md new file mode 100644 index 0000000..eace106 --- /dev/null +++ b/mission/chaptor04/java_mission.md @@ -0,0 +1,110 @@ + +## ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค + +ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค๋Š” ๋‹จ ํ•˜๋‚˜์˜ ์ถ”์ƒ๋ฉ”์„œ๋“œ๋งŒ์„ ๊ฐ€์ง€๋Š” ์ธํ„ฐํŽ˜์ด์Šค์ด๋‹ค. + +> ์ฐธ๊ณ : default, static ๋ฉ”์„œ๋“œ ๊ฐœ์ˆ˜์—๋Š” ์ œ์•ฝ์ด ์—†๋‹ค. + +์ผ๋ฐ˜ ์ธํ„ฐํŽ˜์ด์Šค์™€ ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค์˜ ๊ทœ์•ฝ์ด ๋‹ค๋ฅด๋‹ค. `@FunctionalInterface` ๋ผ๋Š” ์–ด๋…ธํ…Œ์ด์…˜์„ ์„ ์–ธํ•˜์—ฌ interface ์ฝ”๋“œ๊ฐ€ ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค์˜ ๊ทœ์•ฝ์— ์•ˆ ๋งž์„ ๊ฒฝ์šฐ ๋ฏธ๋ฆฌ ์ปดํŒŒ์ผ ์—๋Ÿฌ๋ฅผ ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + +ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค๋Š” ๋žŒ๋‹ค์‹์„ ๋‹ค๋ฃจ๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋œ๋‹ค. +๋žŒ๋‹ค ํ‘œํ˜„์‹์€ ํ•˜๋‚˜์˜ ๊ฐ์ฒด๋กœ ๋ณผ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ด๋ฅผ ๋‹ด์„ ์ˆ˜ ์žˆ๋Š” ์ฐธ์กฐ๋ณ€์ˆ˜๊ฐ€ ํ•„์š”ํ•œ๋ฐ ์ด๊ฒƒ์ด ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ๋˜๋Š” ๊ฒƒ์ด๋‹ค. + + +### ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค์˜ 4๊ฐ€์ง€ ์ข…๋ฅ˜ + +- Supplier : T get()์„ ์ถ”์ƒ ๋ฉ”์„œ๋“œ๋กœ ๊ฐ–๋Š”๋‹ค. ๋งค๊ฐœ๋ณ€์ˆ˜ ์—†์ด ๋ฐ˜ํ™˜ ๊ฐ’๋งŒ ์กด์žฌํ•œ๋‹ค. +- Consumer : void accept(T t)๋ฅผ ์ถ”์ƒ ๋ฉ”์„œ๋“œ๋กœ ๊ฐ–๋Š”๋‹ค. ๋งค๊ฐœ๋ณ€์ˆ˜๋งŒ ์žˆ๊ณ  ๋ฐ˜ํ™˜ ๊ฐ’์ด ์—†๋‹ค. +- Function : R apply(T t)๋ฅผ ์ถ”์ƒ๋ฉ”์„œ๋“œ๋กœ ๊ฐ–๋Š”๋‹ค. ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๋ฐ›์•„์„œ ๋ฐ˜ํ™˜ ๊ฐ’์ด ์กด์žฌํ•œ๋‹ค. +- Predicate : Boolean test(T t)๋ฅผ ์ถ”์ƒ๋ฉ”์„œ๋“œ๋กœ ๊ฐ–๋Š”๋‹ค. ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๋ฐ›์•„์„œ Boolean์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. + +์ด๋Ÿฐ ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ• 4๊ฐ€์ง€๋ฅผ ์ด๋ฒˆ ๊ณผ์ œํ•ด์„œ ์ˆ˜ํ–‰ํ•ด๋ณธ ๊ฒƒ์ด๋‹ค. + + +**๊ณผ์ œ์—์„œ ํ•œ ๊ตฌํ˜„๋ฐฉ๋ฒ• 4๊ฐ€์ง€** +- ์ต๋ช… ํด๋ž˜์Šค +- ์‹ค์ œ ์ƒ์†ํ•œ ํด๋ž˜์Šค +- ๋žŒ๋‹ค +- ๋ฉ”์„œ๋“œ ์ฐธ์กฐ + + +### **์ต๋ช… ํด๋ž˜์Šค** +ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค๋„ ์ธํ„ฐํŽ˜์ด์Šค์ด๊ธฐ ๋•Œ๋ฌธ์—, ํ•ด๋‹น ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ด๋ฅผ ์ผํšŒ์„ฑ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ์ต๋ช…ํด๋ž˜์Šค๋กœ ๊ตฌํ˜„์„ ํ•œ ๊ฒƒ์ด๋‹ค. + + +### **์‹ค์ œ ์ƒ์†ํ•œ ํด๋ž˜์Šค** +ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค๋„ ์ธํ„ฐํŽ˜์ด์Šค์ด๊ธฐ ๋•Œ๋ฌธ์—, ํ•ด๋‹น ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ด๋ฅผ ์ธ์Šคํ„ด์Šคํ™”ํ•ด์„œ ๊ตฌํ˜„์„ ํ•œ ๊ฒƒ์ด๋‹ค. + + +### **๋žŒ๋‹ค** +๋žŒ๋‹ค์‹์€ ์ต๋ช…๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ํ‘œํ˜„์‹์„ ๋งํ•œ๋‹ค. +๋ฉ”์„œ๋“œ๋ฅผ ํ•˜๋‚˜์˜ ๊ฐ„๊ฒฐํ•œ ์‹์œผ๋กœ ํ‘œํ˜„ํ•œ ๊ฒƒ์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ๋‹ค. +Java 8 ๋ถ€ํ„ฐ ์ง€์›ํ•˜๋ฉฐ, ๋žŒ๋‹ค๋ฅผ ํ†ตํ•ด ์ž๋ฐ”๋„ ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค. + +**ํŠน์ง•** +- ๋ฉ”์„œ๋“œ ์ด๋ฆ„๊ณผ ๋ฐ˜ํ™˜ํƒ€์ž…์€ ์ƒ๋žต๊ฐ€๋Šฅํ•˜๋‹ค +- ๋งค๊ฐœ๋ณ€์ˆ˜์˜ ํƒ€์ž…์„ ์ถ”๋ก ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ์—๋Š” ํƒ€์ž„์„ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ๋‹ค. +- ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ํ•˜๋‚˜์ธ ๊ฒฝ์šฐ ๊ด„ํ˜ธ๋ฅผ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ๋‹ค. +- ํ•จ์ˆ˜์˜ ๋ชธ์ฒด๊ฐ€ ํ•˜๋‚˜์˜ ๋ช…๋ น๋ฌธ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๊ฒฝ์šฐ ์ค‘๊ด„ํ˜ธ๋ฅผ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ๋‹ค. + - ์ด ๋•Œ ์„ธ๋ฏธ์ฝœ๋ก ์€ ๋ถ™์ด์ง€ ์•Š๋Š”๋‹ค. +- ํ•จ์ˆ˜์˜ ๋ชธ์ฒด๊ฐ€ return ๋ฌธ์ด ์žˆ๋Š” ๊ฒฝ์šฐ ์ค‘๊ด„ํ˜ธ๋ฅผ ์ƒ๋žตํ•  ์ˆ˜ ์—†๋‹ค. +- return ๋Œ€์‹  ํ‘œํ˜„์‹์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋ฐ˜ํ™˜๊ฐ’์€ ํ‘œํ˜„์‹์˜ ๊ฒฐ๊ด๊ฐ’์ด ๋œ๋‹ค. + + +### **๋ฉ”์„œ๋“œ ์ฐธ์กฐ** + +๋žŒ๋‹ค ํ‘œํ˜„์‹์ด ๋‹จ ํ•˜๋‚˜์˜ ๋ฉ”์„œ๋“œ๋งŒ์„ ํ˜ธ์ถœํ•˜๋Š” ๊ฒฝ์šฐ์— ํ•ด๋‹น ๋žŒ๋‹ค ํ‘œํ˜„์‹์—์„œ ๋ถˆํ•„์š”ํ•œ **๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ œ๊ฑฐ**ํ•˜๊ณ  ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค. + +ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋žŒ๋‹ค์‹์ด ์•„๋‹Œ ์ผ๋ฐ˜ ๋ฉ”์„œ๋“œ๋ฅผ ์ฐธ์กฐ์‹œ์ผœ ์„ ์–ธํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. +์ฐธ์กฐ๊ฐ€๋Šฅํ•œ ๋ฉ”์„œ๋“œ๋Š” ์ผ๋ฐ˜ ๋ฉ”์„œ๋“œ, static ๋ฉ”์„œ๋“œ, ์ƒ์„ฑ์ž๊ฐ€ ์žˆ๋‹ค. +๋ฉ”์„œ๋“œ ์ฐธ์กฐ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋žŒ๋‹ค์‹๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค๋กœ ๋ฐ˜ํ™˜๋œ๋‹ค. + +ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค์˜ ์ถ”์ƒ ๋ฉ”์„œ๋“œ์™€ ์‚ฌ์šฉํ•˜๋ ค๋Š” ๋ฉ”์„œ๋“œ์˜ **๋งค๊ฐœ๋ณ€์ˆ˜ ํƒ€์ž…, ๊ฐœ์ˆ˜, ๋ฐ˜ํ™˜ํ˜•**์ด ์ผ์น˜ํ•œ๋‹ค๋ฉด ๊ฐ„๊ฒฐํ•˜๊ฒŒ ๋ฉ”์„œ๋“œ ์ฐธ์กฐ๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. + +--- +## Stream API + +Java 8๋ถ€ํ„ฐ ์ถ”๊ฐ€๋œ ๊ธฐ๋Šฅ์œผ๋กœ, ์ปฌ๋ž™์…˜์ด๋‚˜ ๋ฐฐ์—ด๊ณผ ๊ฐ™์€ ๋ฐ์ดํ„ฐ ์†Œ์Šค๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. +ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์Šคํƒ€์ผ์„ ์ฑ„ํƒํ•˜์—ฌ ์ง๊ด€์ ์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +### ํŠน์ง• +- ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ๋กœ์ง์ด ์ถ”์ƒํ™”๋˜์–ด ์žˆ์–ด ๋‚ด๋ถ€์ ์œผ๋กœ ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + - parallelStream()์„ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐ€๋Šฅ +- ์—ฐ์‚ฐ์ด ์‹ค์ œ๋กœ ํ•„์š”ํ•  ๋•Œ๊นŒ์ง€ ์ˆ˜ํ–‰๋˜์ง€ ์•Š๊ณ , ์ตœ์ข… ์—ฐ์‚ฐ์ด ํ˜ธ์ถœ๋  ๋•Œ ์ˆ˜ํ–‰๋ฉ๋‹ˆ๋‹ค. + +### ์—ฐ์‚ฐ +- **์ค‘๊ฐ„ ์—ฐ์‚ฐ** + - ์ŠคํŠธ๋ฆผ์„ ๋ณ€ํ™˜ํ•˜๊ฑฐ๋‚˜ ํ•„ํ„ฐ๋ง์ด ๊ฐ€๋Šฅํ•˜๋‹ค. ์—ฌ๋Ÿฌ ๊ฐœ๋ฅผ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค. + - `filter`, `map`, `sorted` ๋“ฑ + - filter(Predicate predicate): ์กฐ๊ฑด์— ๋งž๋Š” ์š”์†Œ๋งŒ ํ•„ํ„ฐ๋ง + - Predicate๋Š” ๋ฆฌํ„ด ๊ฐ’์ด Boolean, ์ธ์ž ์กด์žฌ + - +- **์ตœ์ข… ์—ฐ์‚ฐ** + - ๊ฒฐ๊ณผ๋ฅผ ์ƒ์„ฑํ•˜๊ฑฐ๋‚˜ ์ฒ˜๋ฆฌ๋ฅผ ์™„๋ฃŒํ•˜๋Š” ์—ฐ์‚ฐ + - ์ŠคํŠธ๋ฆผ์ด ๋‹ซํžˆ๊ณ  ๋” ์ด์ƒ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค. + - `forEach`, `collect`, `count` ๋“ฑ + - forEach(Consumer action): ๊ฐ ์š”์†Œ์— ๋Œ€ํ•ด ์ž‘์—… ์ˆ˜ํ–‰ + - Consumer๋Š” ๋ฆฌํ„ด๊ฐ’์ด ์—†๊ณ  ์ธ์ž๋งŒ ์กด์žฌ + +### ์ƒ์„ฑ +- `Stream.of()`, `Arrays.stream()`, `Collection.stream()` + + + + +--- + +### Q1. ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค๋ž€ ๋ฌด์—‡์ธ๊ฐ€์š”? +**Answer** +ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค๋Š” ๋‹จ ํ•˜๋‚˜์˜ ์ถ”์ƒ ๋ฉ”์„œ๋“œ๋งŒ์„ ๊ฐ€์ง€๋Š” ์ธํ„ฐํŽ˜์ด์Šค์ž…๋‹ˆ๋‹ค. Java 8์—์„œ ๋„์ž…๋˜์—ˆ์œผ๋ฉฐ, ๋žŒ๋‹ค ํ‘œํ˜„์‹์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. @FunctionalInterface๋ผ๋Š” ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•˜์—ฌ ํ•ด๋‹น ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค ๊ทœ์น™์„ ์ค€์ˆ˜ํ•˜๋Š”์ง€ ๊ฒ€์ฆํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Java๋Š” Supplier, Consumer, Function, Predicate ์™€ ๊ฐ™์€ ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋Œ€ํ‘œ์ ์œผ๋กœ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. + +### Q2. ๋ฉ”์„œ๋“œ ์ฐธ์กฐ๋ž€ ๋ฌด์—‡์ด๋ฉฐ, ์–ธ์ œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‚˜์š”? +**Answer** +๋ฉ”์„œ๋“œ ์ฐธ์กฐ๋Š” ๋žŒ๋‹ค ํ‘œํ˜„์‹์ด ๋‹จ ํ•˜๋‚˜์˜ ๋ฉ”์„œ๋“œ๋งŒ ํ˜ธ์ถœํ•˜๋Š” ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ„๊ฒฐํ•œ ๋ฌธ๋ฒ•์ž…๋‹ˆ๋‹ค. ์ผ๋ฐ˜ ๋ฉ”์„œ๋“œ, ์ •์  ๋ฉ”์„œ๋“œ, ์ƒ์„ฑ์ž๋ฅผ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค์˜ ์ถ”์ƒ ๋ฉ”์„œ๋“œ์™€ ์ฐธ์กฐํ•  ๋ฉ”์„œ๋“œ์˜ ๋งค๊ฐœ๋ณ€์ˆ˜ ํƒ€์ž…, ๊ฐœ์ˆ˜, ๋ฐ˜ํ™˜ํ˜•์ด ์ผ์น˜ํ•  ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +### Q3. Predicate, Supplier, Consumer, Function ์ธํ„ฐํŽ˜์ด์Šค์˜ ์—ญํ• ๊ณผ ์ฐจ์ด์ ์— ๋Œ€ํ•ด ์„ค๋ช…ํ•ด ์ฃผ์„ธ์š”. +**Answer** +**Predicate**: Boolean test(T t)๋ผ๋Š” ์ถ”์ƒ ๋ฉ”์„œ๋“œ๋ฅผ ๊ฐ€์ง€๋ฉฐ, ์ฃผ์–ด์ง„ ์ธ์ž๋ฅผ ํ‰๊ฐ€ํ•˜์—ฌ true ๋˜๋Š” false๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ฃผ๋กœ ์กฐ๊ฑด์„ ๊ฒ€์‚ฌํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. +**Supplier**: T get() ๋ฉ”์„œ๋“œ๋ฅผ ๊ฐ€์ง€๋ฉฐ, ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๋ฐ›์ง€ ์•Š๊ณ  ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ฃผ๋กœ ๊ฐ’์„ ์ƒ์„ฑํ•˜๊ฑฐ๋‚˜ ์ œ๊ณตํ•  ๋•Œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. +**Consumer**: void accept(T t) ๋ฉ”์„œ๋“œ๋ฅผ ๊ฐ€์ง€๋ฉฐ, ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๋ฐ›์•„์„œ ์ฒ˜๋ฆฌํ•˜์ง€๋งŒ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ฃผ๋กœ ์ธ์ž๋ฅผ ์†Œ๋น„(์ถœ๋ ฅ, ๋กœ๊น… ๋“ฑ)ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. +**Function**: R apply(T t) ๋ฉ”์„œ๋“œ๋ฅผ ๊ฐ€์ง€๋ฉฐ, ์ž…๋ ฅ๊ฐ’์„ ๋ฐ›์•„์„œ ๋ณ€ํ™˜ํ•˜๊ฑฐ๋‚˜ ๊ฐ€๊ณตํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ฃผ๋กœ ๋ณ€ํ™˜ ์ž‘์—…์— ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.