




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A comprehensive review of java, its history, features, and object-oriented programming concepts. It covers the development of java as a platform-independent language, its advantages over c++, and the basics of object-oriented programming, including classes, objects, inheritance, and polymorphism.
Typology: Lecture notes
1 / 8
This page cannot be seen from the preview
Don't miss anything!
์๋ฐ์ ํน์ฑ ์ดํด์ ๋ณต์ต
1991 ๋ : Sun Microsystems ์ฌ์ James Gosling ๊ณผ Patrick Naughton ์ด ๊ฐ๋ฐํ ๊ณ ๊ธ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด ํ๋ก์ ํธ ์ฝ๋๋ช : Green ์๋๋ ์ง๋ฅํ TV ์ ๊ฐ์ ๊ฐ์ ์ฉ ๊ฐ์ ์ ํ์ ์ฌ์ฉ๋ ์ธ์ด๋ก ๊ฐ๋ฐ๋จ ๊ฐ ์ ์กฐ์ ์ฒด๋ ๋ค๋ฅธ CPU ๋ฅผ ์ฌ์ฉํ ์ ์์ผ๋ฏ๋ก ํน์ ์ปดํจํฐ ๊ตฌ์กฐ์ ๋ ๋ฆฝ์ฑ์ ๊ฐ์ง๋ ๊ฒ์ด ๊ฐ์ฅ ์ค์ํ ์ค๊ณ ๋ชฉํ์๋ค. ๊ธฐ๊ณ์ด์ ๋ ๋ฆฝ์ ์ธ ์ค๊ฐ์ค๊ฐ ์ฝ๋์ฝ๋ (intermediate code) ๋ฅผ ์์ฑํ๋ ์ด๋ ๊ฐ๋ฅ ์ธ์ด ๊ฐ๋ฐ (write-once run anywhere) C++ ๊ธฐ๋ฐ : ๊ฐ์ฒด์งํฅ๊ฐ์ฒด์งํฅ ์ธ์ด์ธ์ด ์ ๊ณ ๋ฐ์ : ๋๋
1991 ๋ Sun ์ฌ์ James Gosling๊ณผ Patrick Naughton์ ์ผ์ด๋ธ TV ์ค์์น ๋ฐ์ค์ ๊ฐ์ ๊ฐ ์ ์ ํ์ ์ฌ์ฉ๋ ์ ์๋ ์์ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด๋ฅผ ๊ฐ๋ฐํ๊ณ ์ ํ์๋ค. ๊ฐ์ ์ ํ์ ๊ฐ ์ ์กฐ ์ ์ฒด๋ ๋ค๋ฅธ CPU๋ฅผ ์ฌ์ฉํ ์ ์๊ธฐ ๋๋ฌธ์ ์ด์์ฑ(portability)์ด ์ด๋ค์๊ฒ ๊ฐ์ฅ ์ค์ํ ์ค ๊ณ ๋ชฉํ๊ฐ ๋์๋ค. ๊ทธ ๊ฒฐ๊ณผ ๊ธฐ์กด ํ๋ก๊ทธ๋๋ฐ ์ธ์ด์ฒ๋ผ ๊ธฐ๊ณ์ ์์กด์ ์ธ ์คํ ํ์ผ์ ๋ง๋ค์ด
์คํํ๋ ๋ฐฉ์์ด ์๋ ๊ธฐ๊ณ์ ๋ ๋ฆฝ์ ์ธ ์ค๊ฐ์ฝ๋(intermediate code)๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ์์ ์ฑ ํํ์๋ค. ์ด ์ค๊ฐ์ฝ๋๋ฅผ ๋ฐ์ดํธ ์ฝ๋(bytecode)๋ผ ํ๋ฉฐ, ์ด ์ฝ๋๋ ๊ฐ์๊ธฐ๊ณ(virtual machine)๋ฅผ ํตํด ๋ฒ์ญ(interpreter) ๋ฐฉ์์ผ๋ก ์คํ๋๋ค. Sun ์ฌ๋ UNIX ๊ธฐ๋ฐ ์ํฌ์คํ ์ด์ ์ด ์ฃผ๋ ฅ ์ ํ์ด๋ฏ๋ก ์ด๋ค์ C++ ์ธ์ด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ์ฌ ์ธ์ด๋ฅผ ๊ฐ๋ฐํ์๋ค. ์ด๋ ๊ฒ ํ์๋ ์ธ ์ด๊ฐ ์๋ฐ์ด์ง๋ง ์ฒ์์๋ ํฐ ๋ฐ์์ ์ป์ง ๋ชปํ์๋ค.
WWW ์ ๊ธ์ฑ์ฅ Gosling ๋ฑ์ ์ด ์ธ์ด๋ฅผ ์ด์ฉํ์ฌ 1995 ๋ ๋์ HotJava ๋ผ๊ณ ํ๋ ์น ๋ธ๋ผ์ฐ์ ๋ฅผ ๊ฐ๋ฐํจ ์ด ๋ธ๋ผ์ฐ์ ๋ ๊ธฐ์กด ๋ธ๋ผ์ฐ์ ์ ๋ฌ๋ฆฌ ์๋ฐ๋ก ์์ฑ๋ ์ ํ๋ฆฟ์ ํ๋ฆฟ (applet) ์ด๋ ํ๋ก๊ทธ๋จ์ ์น์์ ๋ค์ด๋ฐ์ ์คํํ ์ ์์ ์์ ์ฑ๊ณผ ์ด์์ฑ์ด ์ค์ํ ์ด์ ํ์ฌ๋ ๋ง์ดํฌ๋ก์ํํธ ์ธํฐ๋ท ์ต์คํ๋ก๋ฌ์์๋ ์ง์ 1996 ๋ : Sun Microsystems ์ฌ๋ ์๋ฐ์ ์ฒซ ๋ฒ์ ์ถ์ ์ค์ ์์ฉ์ ๊ฐ๋ฐํ๊ธฐ์๋ ๊ธฐ๋ฅ์ด ๋ฏธํก 1998 ๋ : Java 2 ์ถ์ ํ์ฌ๋ J2SE(Core/Desktop), J2EE(Enterprise), J2ME(Mobile) ์ธ ์ข ๋ฅ์ ๋ฒ์ ์ ์ ๊ณต
์๋ฐ๊ฐ ๊ฐ๋ฐ๋ ์๊ธฐ๋ ์ฐ์ฐํ ์ธํฐ๋ท ํนํ ์๋์์ด๋์น(WWW, World Wide Web)์ด ํญ๋ฐ ์ ์ผ๋ก ๊ธ์ฑ์ฅํ ์๊ธฐ์ ์ผ์นํ์๋ค. Gosling์ ์์ ์ด ๊ฐ๋ฐํ ์๋ฐ ์ธ์ด๋ฅผ ์ด์ฉํ์ฌ ๊ทธ ๋น ์๊น์ง๋ ์์์ ํ์ง ๋ชปํ์๋ ์๋ก์ด ๊ฐ๋ ์ ์น ๋ธ๋ผ์ฐ์ ๋ฅผ ๊ฐ๋ฐํ์๋ค. ์ด ๋ธ๋ผ์ฐ์ ๋ ์๋ฐ๋ก ์์ฑ๋ ์ ํ๋ฆฟ(applet)์ด๋ผ๊ณ ํ๋ ํ๋ก๊ทธ๋จ์ ์น์์ ๋ค์ด๋ฐ์ ์น ํ์ด์ง ๋ด์์ ์ค ํํ ์ ์์๋ค. ์ด ๊ฐ๋ ์ด ํฐ ํธ์์ ์ป์์ผ๋ฉฐ, ๊ทธ ๊ฒฐ๊ณผ ์๋ฐ ์ธ์ด๋ ์ ์ธ๊ณ์ ์ธ ๊ด์ฌ์ ๋ฐ๊ฒ ๋์๋ค. ์ดํ Sun์ฌ๋ 1996 ๋ ์ ์๋ฐ์ ์ฒซ ๋ฒ์ ์ ๊ณต์์ ์ผ๋ก ์ถ์ํ์๋ค. ํ์ง๋ง ์ฒซ ๋ฒ์ ์ ๋์ ์์ค์ ์์ฉ ํ๋ก๊ทธ๋จ์ ๊ฐ๋ฐํ๊ธฐ์๋ ๋งค์ฐ ๋ถ์กฑํ์๋ค. 1998๋ Java 2๊ฐ ์ถ ์๋๋ฉด์ ๋ณธ๊ฒฉ์ ์ผ๋ก ๋ค๋ฅธ ๋ฒ์ฉ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด์ ์ด๊นจ๋ฅผ ๋๋ํ ํ๊ฒ ๋์๋ค.
๊ทผ์ ์ด๋ ์ ๋ ํ์คํ๋๊ณ ์๋ค. ํ์ง๋ง ์ด์ฐฝ๊ธฐ์๋ ๋ง์ดํฌ๋ก์ํํธ Visual ์ธ์ด๋ค์ด ์ ๊ณต ํ๋ ํตํฉ ๊ฐ๋ฐ ํ๊ฒฝ๊ณผ ๊ฐ์ ๊ฐ๋ฐ ํ๊ฒฝ์ด ์์๋ค. ์๋ฐ์คํฌ๋ฆฝํธ๋ ์๋ฐ์ ๋จ์ ๋ฒ์ ์ผ๋ก ์ ๊ฐํ๋ ๊ฒฝ์ฐ๋ ์๋ค. ์ด๋ฆ๋ง ์ ์ฌํ ๋ฟ ์๋ฐ์คํฌ๋ฆฝํธ์ ์๋ฐ๋ ๋ค๋ฅธ ๊ฒ์ด๋ค. ์๋ฐ์คํฌ๋ฆฝํธ ๋ Netscape ์ฌ์์ ๊ฐ๋ฐํ ์คํฌ๋ฆฝํธ ์ธ์ด์ด๋ฉฐ, ์๋ฐ์ ์ ์ฌํ ๋ฌธ๋ฒ์ ๊ตฌ์กฐ๋ฅผ ์ง๋๊ณ ์์ด ๊ทธ๋ค์ด ์ด๋ฆ์ ์๋ฐ์คํฌ๋ฆฝํธ๋ก ๋ช ๋ช ํ ๊ฒ์ผ ๋ฟ ์๋ฐ์๋ ์ ํ ๋ค๋ฅธ ๊ฒ์ด๋ค.
ํ๋ก๊ทธ๋จ์ ๊ฐ์ฒด๊ฐ์ฒด (object) ๋ก ๊ตฌ์ฑ๋จ ๊ฐ์ฒด๋ ํ์ (behavior), ์ํ (state), ์๋ณ์ (identity) ๋ฅผ ๊ฐ์ง ์บก์ํ (encapsulation): ๋ฐ์ดํฐ์ ํ์๋ฅผ ํ๋๋ก ๊ฒฐํฉ ๊ฐ์ฒด๋ ๋ฉ์์ง๋ฅผ ๋ฐ์ ๊ทธ๊ฒ์ ์ฒ๋ฆฌํด์ค๋ค. ๋ด๋ถ ๊ตฌํ์ ๋ํด์๋ donโt care ํ ๊ฐ์ฒด๋ ๋ค๋ฅธ ๊ฐ์ฒด์ ๋ด๋ถ ๋ฐ์ดํฐ๋ฅผ ์ ๋ ์ง์ ์กฐ์ํ์ง ์์ ํด๋์คํด๋์ค (class) ๊ฐ์ ์ข ๋ฅ์ ๊ฐ์ฒด๋ค์ ๋ชจ์ ํด๋์ค๋ ์ด๋ฆ์ ๊ฐ์ง๋ฉฐ , ๋ฉค๋ฒ๋ณ์ (member/instance variable, field, attribute) ์ ๋ฉ์๋ (method, member function) ๋ก ๊ตฌ์ฑ๋์ด ์๋ค. ํด๋์ค ๊ฐ์ ๊ด๊ณ : use, has-a(aggregation), is-a(generalization) ์ธ์คํด์ค์ธ์คํด์ค (instance): ํด๋์ค์ ํ ๊ฐ์ฒด
๋ ํฌ๊ฒ ์ฌ์ฉ(use), ํฌํจ(has-a), ์์(is-a) ์ธ ๊ฐ์ง ์ข ๋ฅ๋ก ๋ถ๋ฅํ ์ ์๋ค. ์ฌ์ฉ ๊ด๊ณ๋ ํ ํด๋์ค์ ๊ฐ์ฒด๊ฐ ๊ทธ์๊ฒ ์ฃผ์ด์ง ์ผ์ ๋ฌ์ฑํ๊ธฐ ์ํด ๋ค๋ฅธ ํด๋์ค์ ๋์์ด ํ์ํ ๊ฒฝ์ฐ๋ฅผ ๋งํ๋ค. ํฌํจ ๊ด๊ณ๋ ํ ๊ฐ์ฒด๊ฐ ๋ฉค๋ฒ ๋ณ์๋ก ๋ค๋ฅธ ๊ฐ์ฒด๋ฅผ ๊ฐ์ง๊ณ ์๋ ๊ฒฝ์ฐ๋ฅผ ๋งํ๋ค. ์์ ๊ด๊ณ๋ ๊ฐ์ฒด์งํฅ์์ ๊ฐ์ฅ ์ค์ํ ๊ฐ๋ ์ค ํ๋์ด๋ค. ์ด๊ฒ์ ๋ํด์๋ ๋ค์ ์ฌ๋ผ์ด๋์์ ๋ณด๋ค ์์ธํ ์ค๋ช ํ๋ค. ํด๋์ค์ ํ ๊ฐ์ฒด๋ฅผ ์ธ์คํด์ค(instance)๋ผ ํ๋ค.
์์์์ (inheritance): is-a ๊ด๊ณ super/sub, base/derived, parent/child ์ธ๋ถํ (specialization), ์ผ๋ฐํ (generalization) ์ฌ์ฌ์ฉ ์ฉ์ดํ๊ฒ ํด์ค๋ค. ๊ด๋ จ ํค์๋ : extends, super ์๋ฐ๋ ๋ค์ค ์์์ ์ง์ํ์ง ์๋๋ค. ์์ ๊ณ์ธต๊ตฌ์กฐ , ์์ ์ฒด์ธ ๋คํ์ฑ (polymorphism) ์ฐ์ฐ์ ๊ฐ์ฒด์ ๋ฐ๋ผ ๋ค๋ฅธ ํ์๋ฅผ ํ๋ค. (late binding) overloading cf. overriding
๋คํ์ฑ(polymorphism)์ ๊ฐ์ฒด์งํฅ ํ๋ก๊ทธ๋๋ฐ์ ๋ ๋ค๋ฅธ ํต์ฌ ํค์๋์ด๋ค. ์ฐ๋ฆฌ๋ โ๋ฌธ์ ์ด ๋คโ, โ์ฐฝ๋ฌธ์ ์ด๋คโ์ฒ๋ผ ๊ฐ์ โ์ด๋คโ๋ผ๋ ํํ์ ์ฌ๋ฌ ์ข ๋ฅ์ ์ฌ๋ฌผ์ ์ฌ์ฉํ๋ค. ํ์ง๋ง โ์ด๋คโ ์ ๋ด๋ถ ๋ฉ์ปค๋์ฆ์ ๊ทธ๊ฒ์ ๋์์ด ๋๋ ๋ฌธ, ์ฐฝ๋ฌธ, ์๋์ ๋ฐ๋ผ ๋ค๋ฅด๋ค. ๊ฐ์ฒด์งํฅ ํ๋ก๊ทธ๋ ๋ฐ์์๋ ๊ฐ์ ์ด๋ฆ์ ๋ฉ์๋๋ฅผ ์ฌ๋ฌ ํด๋์ค์ ๋ฐ๋ณตํ์ฌ ์ฌ์ฉํ ์ ์๋ค. ํนํ, ๋คํ์ฑ์ ์์๊ณผ ๊ฒฐํฉํ์ฌ ์ฌ์ฉํ ๋ ๋์ฑ ๊ทธ ์ง๊ฐ๋ฅผ ๋ฐํํ๋ค.
๊ฐ์ฒด์งํฅ๊ณผ ๊ด๋ จํ์ฌ ๋ ๋ง์ด ๋ฑ์ฅํ๋ ์ฉ์ด๋ ์ค๋ฒ๋ก๋ฉ(overloading)์ด๋ค. ์ด๊ฒ์ ํ ํด๋ ์ค ๋ด์ ๊ฐ์ ์ด๋ฆ์ ๋ฉ์๋๋ฅผ ์ฌ๋ฌ ๊ฐ ์ ์ํ๋ ๊ฒ์ ๋งํ๋ค. ์ด ๋ ์ ํ์ ๋ฉ์๋์ ์๋ช ์ด ๋ฌ๋ผ์ผ ํ๋ค. ์ฆ, ๋ฉ์๋์ ํ๋ผ๋ฏธํฐ ๋ชฉ๋ก์ด ๋ฌ๋ผ์ผ ํ๋ค. ์ค๋ฒ๋ก๋ฉ๊ณผ ํผ๋ํ ์ ์๋ ์ฉ ์ด๋ก โoverridingโ์ด๋ผ๋ ์ฉ์ด๊ฐ ์๋ค. ์ด ์ฉ์ด๋ ์์๊ณผ ๊ด๋ จ๋ ์ฉ์ด๋ก์ ์์ ํด๋์ค์์ ๋ถ๋ชจ ํด๋์ค์ ์๋ ๋ฉ์๋๋ฅผ ์ฌ์ ์ํ๋ ๊ฒ์ ๋งํ๋ค.
&&, || ์ฐ์ฐ์์ &, | ์ฐ์ฐ์์ ์ฐจ์ด์ ์? short-circuit evaluation ์ด๋? dangling-else ๋ฌธ์ ๋? switch ๋ฌธ์์ โfall throughโ ํ์๋? new ์ฐ์ฐ์์ ์ฉ๋? ๋ฌธ์์ด ์์ฑ์ ํน์ดํ ์ ์? int[ ] nlist = new int[10]; int[ ] alist = nlist; alist[3]=2; ๊ทธ๋ฌ๋ฉด nlist[3]? call-by-value ์ call-by-reference ์ ์ฐจ์ด์ ? garbage ๋ , garbage collection ์ด๋?
]
๋ฉค๋ฒ๋ณ์๋ ๋ช ๋ฐฑํ๊ฒ ์ด๊ธฐํํ์ง ์์ผ๋ฉด ์๋์ผ๋ก ์ด๊ธฐํ ๋๋ค. ( ์ฐธ ๋๋ ๊ฑฐ์ง ) ์ด๊ธฐํํ๋ ๋ฐฉ๋ฒ์ ์ข ๋ฅ? ๊ฐ ๊ธฐ๋ณธ ํ์ ์ ์ด๊ธฐ๊ฐ์? public, private, protected, default access specifier ๋? ์์ฑ์ ( constructor ) ๋ฉ์๋๋? ์์ฑ์์ ์ข ๋ฅ๋? ๋ฉ์๋ ์๋ช ( method signature ) ์ด๋? ์จ๊ฒจ์ง ์ธ์ ( implicit argument ) ๋? ๋ชจ๋ ๋ฉ์๋๋ ์จ๊ฒจ์ง ์ธ์๋ฅผ ๊ฐ์ง๋ค. ( ์ฐธ ๋๋ ๊ฑฐ์ง ) ์์ ์ ( mutator ) ๋ฉ์๋์ ์ด๋์ ( accessor ) ๋ฉ์๋๋? ๋ค๋ฅธ ๋ง๋ก transformer, observer ๋ฉ์๋
public ๋ฉค๋ฒ๋ณ์๋ ์ด๋์ , ์์ ์ ๋ฉ์๋ ์์ด ์ฌ์ฉํ ์ ์๋ค. ํ์ง๋ง public ๋ฉค๋ฒ๋ณ์๋ ๊ฑฐ์ ์ฌ์ฉํ์ง ์๋๋ค. ๊ทธ ์ด์ ๋? super ํค์๋? super ๋ this ๋ฅผ ์ด์ฉํ ์์ฑ์ ํธ์ถ์ ์ ํ์? static ๋ฉค๋ฒ๋ณ์์ ๋ฉ์๋์ ์๋ฏธ? cf. ํด๋์ค ๋ณ์ ์์๋ฅผ ์ ์ธํ ๋ ๋ณดํต ๋ค์๊ณผ ๊ฐ์ด ์ ์ธํ๋ค. public static final int MAX = 100; ์ฌ๊ธฐ์ public, static, final ์ ์ฌ์ฉํ ์ด์ ๋? ํด๋์ค B ๊ฐ ํด๋์ค A ๋ฅผ ์์ํ์๋ค. a ๋ A ์ ์ธ์คํด์ค์ด๊ณ , b ๋ B ์ ์ธ์คํด์ค์ด๋ค. a=b ์ b=a ์ค ์ด๋ ๊ฒ์ด ์ ํจํ ๋ฌธ์ฅ์ธ๊ฐ?
package ๋? ์ด๋ค ํน์ ํจํค์ง๋ฅผ ์ฌ์ฉํ๋ ๋ ๊ฐ์ง ๋ฐฉ๋ฒ? ์๋ฐ ํด๋์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค import ์์ด ์ฌ์ฉํ ์ ์๋ ํจํค์ง๋? import java.awt.;* ์ ์ฌ์ฉํ๋ฉด java.awt ํจํค์ง์ ์๋ ๋ชจ๋ ํด๋์ค๊ฐ ํ๋ก๊ทธ๋จ์ด ์คํ๋ ๋ ํฌํจ๋๋ค. ( ์ฐธ ๋๋ ๊ฑฐ์ง )? instanceof ์ฐ์ฐ์์ ๊ธฐ๋ฅ์? cf. getClass() ๋ฉ์๋ abstract ๋ฉ์๋๋ , abstract ํด๋์ค๋? ๋ถ๋ณ ๊ฐ์ฒด (immutable object) ๋? Object ํด๋์ค๋? Wrapper ํด๋์ค๋? ์๋ฐ๋ ๋ค์ค ์์์ ์ ๊ณตํ๋? interface ๋ ?, ๊ทธ๊ฒ์ ์ฉ๋๋? ๋ด๋ถ (inner) ํด๋์ค๋?