More Related Content Similar to Java advancd ed10 (20) Java advancd ed102. 1
String Handling
๏ง Methods
. String ๊ฐ์ฒด๋ฅผ ์กฐ์ํ๊ธฐ ์ํ Method ๋ค ์ด๋ค
. Static Method ๋ valueOf ์ format ์ด ์ ๊ณต๋๋ค
< Methods >
. substring : ๋ฌธ์์ด ์๋ฅด๊ธฐ, s2 = s1.substring(0,8) ;
. concat : ๋ฌธ์์ด ์ด์ด ๋ถ์ด๊ธฐ, s2 = s1.concat(โabcdโ) ;
. split : ๋ฌธ์์ด ๋๋๊ธฐ , s2[] = s1.split(โ^โ) ; // โ^โ ๊ธฐํธ๋ก ๋ถ๋ฆฌ
. replace : ๋ฌธ์์ด ๋ณํ , s2 = s1.replace (โkwonโ โKangโ) ;
. trim : ๋ฌธ์์ด ์ข์ฐ๊ณต๋ฐฑ์ ๊ฑฐ, s2 = s1.trim() ; // ์ค๊ฐ์ ๊ณต๋ฐฑ์ ์ ๊ฑฐ๋์ง ์๋๋ค
. valueOf : ๋ค๋ฅธ ์๋ฃํ ์ ๋ณํ s1 = String.valueOf(data type) // date ๏ String , char[] ๋ ๋๋ byte[] ๋ ์๋จ
. format : ๋ค๋ฅธ ์๋ฃํ ์ ๋ณํ s1 = String.format(โTest %d %l %f %s %tc โ,,,,)
. charAt : ํน์ ํ Index ์ char ๋ฅผ ๊ตฌํจ , c1 = s1.charAt(3) ;
. getBytes : ์ ์ฒด Char ํ๋ , byte[] = s1.getBytes() ; // ์ ์ฒด ํน์ ๋ถ๋ถ์ ๊ฐ์ ธ์ฌ ์ ์๋ค
. getChars : ์ ์ฒด(๋ถ๋ถ) char ํ๋ , s1.getChars (startIndex, LastIndex, char[], dest index) ;
. euals : ๋ฌธ์์ด ์ ์ฒด๊ฒ์ฌ , boolen = s1.equals (โHello Javaโ) ;
. contains : ๋ฌธ์์ด ๋ถ๋ถ๊ฒ์ฌ , boolen = s1.contains(โhungrokโ) ;
. startWith : ์์ ๋ฌธ์์ด ๊ฒ์ฌ , boolen = s1.startWith(โhttpโ) ;
. endWith : ๋ง์ง๋ง ๋ฌธ์์ด ๊ฒ์ฌ , boolen = s1.endWith(โcomโ) ;
์์ 1. format ์ ์ด์ฉํ์ฌ concatenation ์ฒ๋ฆฌ
String str1 = "abcdefgh" ;
String str2 = "ababababa" ;
String str3 = "nnnnnnnnn" ;
String str4 = "" ;
str4 = String.format(โ%s%s%s",str1,str2,str3) ;
์์ 2. getChars ์ valueOf ๋ฅผ ์ด์ฉํ์ฌ ํน์ index char ๋ณ๊ฒฝ
String str1 = โabcdefghโ ;
String str2 =โโ ;
char car[] = new char[8] ;
str1.getChars(0,str1.length(),car,0) ;
car[3] = โKโ ;
str2 = String.valueOf(car) ; //๏ abcKefgh
3. 2
Time Package
๏ง Time Package
. SE 8 ๋ถํฐ ์ง์ (๊ทธ์ ์๋ date, time, calendar ๊ฐ์ฒด ์ฌ์ฉ - ๋ชจ์์ ๊ฐ์ )
. Factory ํ์์ผ๋ก ์ง์
. ๊ฐ์ฒด๋ ํ์ฌ ํน์ ํน์ ์๊ฐ์ ์ฃผ์ด์ ๊ฐ์ฒด๋ฅผ ์์ฑ ํจ : ์. 2012.1.1 ์ผ์ ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ ํด๋น ๊ฐ์ฒด์ ์์์์ผ ์์๋ด๊ธฐ
๊ฐ์ฒด ํน์ ์๊ฐ
๊ฐ์ฒด
๊ฐ์ฒด์์ฑ
. LocalDateTiem.now()
. ZonedLocalDateTime.now()
. LocalDate.of (2013,12,25)
minusX
plusX
withX
< Methods >
get : Nano, Second, Minute, Hour, Year
: Month, MonthValue
: DayOfMonth ๏ 1~31
: DayOfWeek ๏ SUNDAY ~ SATURDAY
: DayOfYear ๏ 1~366
truncatedTo
isLeapYear
4. 3
์๋ฃ๊ตฌ์กฐ
๏ง Collection Framework
. Collection ์ด๋ ์ฌ๋ฌ Type ์ ์ง์ํ๋ ๋ฐฐ์ด์ ํตํด ์ฐ์๋ ๊ณต๊ฐ์ Data ๋ฅผ ์์งํ๊ณ ์กฐ์ํ๊ธฐ ์ฉ์ดํ๊ฒ ๋ง๋ ์ฌ๋ฌ ์ข
๋ฅ์ ๊ฐ์ฒด๋ค์ ๋งํ๋ค
(1) List : n*1 ๊ตฌ์กฐ์ ๋ฐฐ์ด๋ก์, ์์๋ฅผ ์ง๋๋ฉฐ data ์ค๋ณต์ด ๊ฐ๋ฅํ๋ค
(2) Set : n*1 ๊ตฌ์กฐ์ ๋ฐฐ์ด๋ก์, ์์์ ์๋ฏธ๊ฐ ์์ผ๋ฉฐ data ์ค๋ณต์ด ๋ถ ๊ฐ๋ฅํ๋ค
(3) Map : n*2 ๊ตฌ์กฐ์ ๋ฐฐ์ด๋ก์ ์์์ ์๋ฏธ๊ฐ ์๋ค. HashMap ๋ค์๊ฐ ๋ฅผ ์ด์ฉํ๋ฉด ๊ธฐ๋ณธ์ ์ธ Data Base ๊ธฐ๋ฅ์ด ๊ฐ๋ฅ ํ๋ค
. java.util ํ๋ถ์ Class ๊ฐ ์กด์ฌํ๋ค
. ๊ณ์ธต๊ตฌ์กฐ (Implementation ๊ด๊ณ)
Collection List
Set
Vector
ArrayList
Stack
LinkedList
SortedSet
HashSet
์์ ๋ ์งํฉ์ ์ธ ์ ์ฅ๊ณต๊ฐ ์์๊ฐ ์๋ ์ ์ฅ๊ณต๊ฐ
์งํฉ์ ์ธ ์ ์ฅ๊ณต๊ฐ
TreeSet
Map
SortedMap
HashMap
Hashtable
์ (ํค์ ๊ฐ) ์ ๋ฐ์ดํฐ
TreeMap
Interface
5. 4
์๋ฃ๊ตฌ์กฐ
๏ง Collection Framework
. ๊ฐ ๊ฐ์ฒด ๋ค Features
๊ฐ์ฒด ์ค๋ช
LinkedList . Array ๊ฐ Linked ๋์ด์์, Queue ๊ธฐ๋ฅ์ ์ด์ฉ
. add(), addFirst(), addLast(), remove(), get(index), getFirst(), getLast(), isEmpty()
. peek(), poll(), pop(), push()
Stack . LIFO ๊ตฌ์กฐ
. push(), pop(), peak(), search()
ArrayList . ์ผ๋ฐ ๋ฐฐ์ด์ ์ ๋์ ๋ฉ๋ชจ๋ฆฌ ์ฆ๊ฐ ๊ธฐ๋ฅ (์ผ๋ฐ Array ๋ size ๊ฐ ์ ์ ์ผ๋ก ํ๋ณด)
. ๋๊ธฐํ๋ฅผ ๋ณด์ฅํด ์ฃผ์ง ์๋๋ค (๋๊ธฐํ ๋ฐฉ๋ฒ List list = Collections.synchronizeList(new ArrayList(โฆ));
. add(), get(), toArray(), contains(), size()
Vector . ArrayList ์์ ๋๊ธฐํ ๊ฐ ๋ณด์ฅ ๋๋๋ก ์ต์ ํ๋ ๊ฒ ์ด๋ค (์ด๋ฐ ์ฌ์ ๋ก AL ๋๋น ๋๋ฆฌ๋ค)
. JAVA 5.0 ์ดํ Auto Boxing ์ง์
. addElement(), elementAt(), size(), contains(), indexOf(), insertElementAt(), setElementAt()
HashSet . ์์์ ์๋ฏธ๊ฐ ์์ผ๋ฉฐ, Data ์ค๋ณต ์ด ๋ถ๊ฐ๋ฅ ํ๋ค
. add(), next(), remove(), contains(), size()
TreeSet . Set ๊ธฐ๋ฅ์ ์ง๋๋ฉด์ ์ ๋ ฌ๊ธฐ๋ฅ ์ถ๊ฐ (์๋ ์ค๋ฆ์ฐจ์)
. ์ฌ์ฉ์ ๊ฐ ์ง์ ์ ๋ ฌ๋ฐฉ์ ์ง์ ๊ฐ๋ฅ (Comparator ๋ฅผ Implement ํ์ฌ compare() ๊ตฌํ)
Hashtable . Key ์ value ๋ก data ๊ด๋ฆฌ, ๋๊ธฐํ ๋ณด์ฅ , Null ํ์ฉํ์ง ์๋๋ค
. ๊ฐ์ฒด ์์ฑ : Hashtable<String, Object> h = new Hashtable<String, Object>();
. put(), get(), remove(), contains(), replace(), size(), keys(), elements()
HashMap . Key ์ value ๋ก data ๊ด๋ฆฌ, ๋๊ธฐํ ๋ณด์ฅํ์ง ์๋๋ค, Null ํ์ฉํ๋ค
. ๊ฐ์ฒด ์์ฑ : Map<String, Integer> map = new HashMap<String, Integer>();
. put(), get(), remove(), contains(), replace(), size(),
. Enumeration ๋ณํ method (keys, elements) ๊ฐ ์๋ค
TreeMap . Map ๊ธฐ๋ฅ์ ์ง๋๋ฉด์ ์ ๋ ฌ๊ธฐ๋ฅ ์ถ๊ฐ (Key ๋ฅผ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์)
. ์ฌ์ฉ์ ๊ฐ ์ง์ ์ ๋ ฌ๋ฐฉ์ ์ง์ ๊ฐ๋ฅ (Comparator ๋ฅผ Implement ํ์ฌ compare() ๊ตฌํ)
6. 5
์๋ฃ๊ตฌ์กฐ
๏ง Collection Framework
. Template Code
< HashTable ๏ Enumber ๏ Search >
Hashtable ht = new Hashtable() ;
ht.put (โa1โ,obj1) ; // Key, Element Value
ht.put (โa2โ,obj2) ;
ht.put (โa3โ,obj3) ;
Enumeration keys = ht.keys() ;
Enumeration values = ht.elements() ;
While(keys.hasMoreElements()){ // boolean for search
String key = (String) keys.nextElements() ; // To get โa1โ, โa2โ, โa3โ
Object value = ht.get(key) ; // To get obj1,obj2,obj3
}
< ๊ฐ์ฒด์์ฑ >
Hashtable ht1 = new Hashtable() ; // ht1 == ht2
Hashtable<Object, Object> ht2 = new Hashtable <Object,Object>() ;
Hashtable<String, Object> ht3 = new Hashtable <String,Object>() ;
Hashtable<String, Integer> ht4 = new Hashtable <String,Integer>() ;
Vector<String> vt1 = new Vector<String>() ;
Vector<Object> vt2 = new Vector<Object>() ;
ArrayList<String> al1 = new ArrayList<String>() ;
ArrayList<Object> al2 = new ArrayList<Object>() ;
Stack<String> st1 = new Stack<String>() ;
Stack<Object> st2 = new Stack<Object>() ;
LinkedList<String> ll1 = new LinkedList<String>() ;
LinkedList<Object> ll2 = new LinkedList<Object>() ;
7. 6
I/O
๏ง ๊ธฐ๋ณธ๊ตฌ์กฐ
. ๋ฌธ์์ด Stream ์ฒ๋ฆฌ๋ Reader / Writer ๊ฐ ๋ด๋นํ๊ณ , Byte Stream ์ฒ๋ฆฌ๋ Stream ์ด ๋ด๋นํ๋ค
. ๊ฐ ๊ฐ์ฒด ๋ณ ๊ณ์ธต๊ตฌ์กฐ
Reader --- BufferedReader
--- IntputStreamReader โ- FileReader
Writer --- BufferedWriter
--- OutputtStreamWriter โ- FileWriter
InputStream --- FileInputStream ---- SocketInputStream
(Abstract) --- ByteArrayInputStream
--- SequenceInputStream
--- StringBufferInputStream
--- FilteredInputStream ---- DataInputStream
---- BufferedIntputStream
---- PushbackInputStream
---- ObjectInputStream
OutputStream --- FileOutputStream ---- SocketOutputStream
(Abstact) --- ByteArrayOutputStream
--- FilteredOutputStream ---- DataOutputStream
---- BufferedOutputStream
---- PrintStream
---- ObjectOutputStream
InputStreamReader
InputStream
Socket File
File
FileReader
๋ฌธ์์ด Stream
Byte Stream
OutputStreamWriter
OutputStream
Socket File
File
FileWriter
Byte Stream
๋ฌธ์์ด Stream
Byte Byte
8. 7
I/O
๏ง File Handling
. File ๊ฐ์ฒด๋ File Descriptor ์ ๋ณด๋ง์ ๊ฐ์ง๊ณ Handling ํ๋ค
. ๋ฌธ์์ด Stream ์ ๋ํ์ฌ๋ FileReader / FileWriter ๋ฅผ ํตํ์ฌ ์ฒ๋ฆฌํ๋ค
File FileOutputStream
DataOutputStream
ObjectOutputStream
BufferedOutputStream
FileWriter BufferedWriter
File
Directory
File FileInputStream
DataInputStream
ObjectInputStream
BufferedInputStream
FileReader BufferedReader
get Name,Path,Parent,ParentFile
get Absolute, AbsoluteFile
list, listFiles
is Directory, Hidden, File
Mkdir, renameTo, delete, createNewFile
File
Directory
Byte Stream
Character Stream
Character Stream
Byte Stream
9. 8
I/O
๏ง Stream ์ธ๋ถ์ข
๋ฅ
๋น๊ณ Stream Description ์ฐธ๊ณ
์์ FileOuputStream ํ์ผ ๊ฐ์ฒด์ entry point ์ญํ .
์ง์ write ํ๊ฑฐ๋ Sub stream ์ Pipe line ๋์ด์ง๋ค
๊ฐ์ฒด ์์ฑ์ ์ธ์๋ก File ๊ฐ์ฒด, Append ์ ๋ฌด
write (buffer,index,size)
ByteArrayOuputStream Write ๋์ด์ง Byte ๋ฅผ ์ ์ฒด๋ก Byte[] ๋ก ๊ฐ์ง๊ณ ์์ผ๋ฉฐ
toByteArray() ๋ก Byte[] ์ ๋ฐํํ๋ค
๊ฐ์ฒด ์์ฑ์ ์ธ์๋ ์๋ค
write (buffer,index,size)
ํ์ DataOutputStream 8๊ฐ์ง Primitive data type ์ผ๋ก write ๊ฐ๋ฅ ํ๋ฉฐ
Pipe Line ์ ํตํ์ฌ ์์ Output Stream ๊ณผ ์ฐ๊ฒฐ๋๋ค
๊ฐ์ฒด ์์ฑ์ ์ธ์๋ ์์ OS
writeByte, writeInt, writeDouble, writeUTF
ObjectOutputStream ์ง๋ ฌํ ๊ฐ ๋ Object ์ write ๊ฐ๋ฅ,
Pipe Line ์ ํตํ์ฌ ์์ Output Stream ๊ณผ ์ฐ๊ฒฐ๋๋ค
๊ฐ์ฒด ์์ฑ์ ์ธ์๋ ์์ OS
writeObject (obj)
BufferedOutputStream Stream ์
์ถ๋ ฅ ํจ์จ์ ์ํ ๋ณด์กฐ Stream ๊ฐ์ฒด ์์ฑ์ ์ธ์๋ ์์ OS, Buffered Size
write(buffer)
PrintStream ๋ฌธ์๊ธฐ๋ฐ Stream ์ผ๋ก์
ํ์ค ์ถ๋ ฅ์ฅ์น (System.out) ์ ์ฐ๊ฒฐ๋์ด ์ฌ์ฉ. ํน์,
Pipe Line ์ ํตํ์ฌ ์์ Output Stream ๊ณผ ์ฐ๊ฒฐ๋๋ค
๊ฐ์ฒด ์์ฑ์ ์ธ์๋ ์์ OS
println , printf()
10. 9
Network
๏ง Socket
. Socket ์ด๋ : App ๊ณผ TCP/UDP ๋ฅผ ์ฐ๊ฒฐ ํด์ฃผ๋ ์ฅ์น ์ด๋ค (Port Number ๋ก ๊ด๋ฆฌ)
. Socket ๊ฐ์ฒด ๊ฐ ๋ง๋ค์ด ์ง๋ฉด, ํด๋น OS Socket ๊ณผ ๋์๋๋ InputStream ๊ณผ OutputStream ๊ฐ์ฒด๋ ์๋์ผ๋ก ์์ฑ๋๋ค
. ์ฌ์ฉ์๋ IS ์ OS ๋ง์ ๋ณด๊ณ Handling ํ๋ฉด ๋๋ค.
. read / write ํ์๋ ์ผ๋ฐ์ ์ธ I/O ์ ๋์ผํ๋ค.
. TCP ์ฉ (Connection Oriented) Client Socket ์ผ๋ฐ์ ์ธ ๋ชจ์ต (Server ์ฉ์ ServerSocket ์ผ๋ก ๋ณ๋ ์กด์ฌ)
. UDP ์ฉ์ ์๋์ ๊ฐ์ด ๋ณ๋์ Socket ์ผ๋ก ์กด์ฌํ๋ค
Socket
Socket
InputStream
Socket
OutputStream
OS Socket OS Socket
Out TCP/IP packetIn TCP/IP packet
read() write()
Socket
DatagramPacketDatgramSocket
MulticastSocket
send(packet)
receive (packet)
11. 10
Network
๏ง HTTP
. Socket ๊ตฌ์กฐ ์์ HttpURLConnection ๊ฐ์ฒด๊ฐ Header ๋ฅผ ๋ฐ์กํ๊ณ ์์ ํ๋ ๊ธฐ๋ฅ์ ๋ด๋นํ๋ค
(Socket ๊ฐ์ฒด๋ฅผ App ์์ ์ง์ ๋ง๋ค์ง๋ ์๊ณ , ๋ด๋ถ์ ์ผ๋ก ๋ง๋ค์ด์ง๋ค)
. Entity Body ์ data ์ ๋ํ์ฌ๋ App ์์ ์ง์ Handling ํ๋ค
Socket
InputStream OutputStream
OS Socket OS Socket
Out TCP/IP packetIn TCP/IP packet
read() write()
Socket
HttpURLConnectionURL
. openConnection() ์ ๊ฒฐ๊ณผ๋ก
HttpUrlConnection ๊ฐ์ฒด๊ฐ ๋ฐํ๋๋ค
Request HeaderResponse Header
setRequestMethod : GET/PUT/POST ์ง์
setRequestProperty : Header Parameter ์ง์
setConnectTimeout
setUseCaches
setDoOutput
setDoInput
getResponseCode
getHeaderField
getContentLength
disconnect
Entity
Body
Entity
Body
12. 11
Security (์ํธ)
๏ง ์ผ๋ฐ
. ๋น๋์นญ Key (RSA) ๋ฐ ๋์นญ Key (AES,DES,3DES) ๋ฐํ
. ๋น๋์นญ Key ๋ฅผ ์ด์ฉํ ์๋ช
๋ฐ ์ฆ๋ช
(Signature & Verify) , Encryption ๋ฐ Decryption ์ฒ๋ฆฌ
. ๋์นญ Key ๋ฅผ ์ด์ฉํ Encryption ๋ฐ Decryption ์ฒ๋ฆฌ
. ์ธ์ฆ์ ๋ฐํ ๊ธฐ๋ฅ์ ์๊ณ (3rd Party Class ๋ ๋ณธ ๊ธฐ๋ฅ์ ๊ณต), ์ธ์ฆ์๋ฅผ ์
๋ ฅ์ผ๋ก ๋ฐ์๋ค์ฌ ์ฆ๋ช
๋ฐ ์ ๋ณด๋ง ์กฐํํ๋ ๊ธฐ๋ฅ์ด ์์
. ์ฃผ๋ก Single Tone ๊ฐ์ฒด๋ก ๊ตฌํํจ
. ๋น๋์นญ Key ์๊ณ ๋ฆฌ์ฆ : SHA1 with DSA, MD5 with RSA, SHA1 with RSA, SHA256 with RSA
. ๋น๋์นญ Key ์ฌ์ฉ
. Signature / Verify : Private key ๋ก Signature ๏ ์์ ์ธก ์ Public Key ๋ก Verify
. Encryption / Decryption : Public Key ๋ก Encryption ๏ ์์ ์ธก ์ Private Key ๋ก Decryption
. Public Key (๊ณต๊ฐ Key) ๋ X509 ์ธ์ฆ์์ ์กด์ฌํจ
. HTTPS ๋ ๋น๋์นญ Key ๋ฅผ ์ฌ์ฉํ์ฌ encryption / decryption ์ฒ๋ฆฌ
13. 12
Security (์ํธ)
๏ง Class ๋ณ ๊ธฐ๋ฅ
. KeySpec ์์ด๋ Cipher , Signature ์ ์ง์ Input ์ผ๋ก ๊ฐ๋ฅ
. KeySpec ์ ๊ณต์ (์ ์ก) ํน์ ์ ์ฅ์ ์ํ์ฌ ํ์ค์ ์ ํ data format ์ผ๋ก ๋ณํํ๋ ๊ฒ์
์. PKCS#8 ์์ ์ ์๋ PrivateKeyInfo = { [privateKey] }
X509 ์์ ์ ์๋ SubjectPublicKeyInfo = { [publicKey] }
SecretKeySpec
๋์นญ.key
KeyGenerator
private.key
public.key
KeyFactory Cipher
Signature
prvkeySpec
pubkeySpec
CertificateFactory
X509.cer
KeyPairGenerator
keySpec
SecretKeyFactory
SecretKey
DESKeySpec
14. 13
GUI
๏ง ์๊ฐ
. ๋ ๊ฐ์ง ๋ฐฉ๋ฒ์ผ๋ก GUI ๋ฅผ ๊ตฌํํ๋ค : AWT Components ํน์ Swing Components ๋ฅผ ์ฌ์ฉ
. Swing ์ AWT ์ ์๋ ๋จ์ ์ ๋ณด์ํ ๊ฒ์ด๋ค
1) Lightweight component ๋ฅผ ์ ๊ณต : ์ด์์ฒด์ ๊ฐ native ๋ก ๊ตฌํ ํ component (Heavyweight ) ์ ์ฌ์ฉ์ ๋ฐ๋ฅธ ํธํ์ฑ ๋ฌธ์
2) AWT ์ ์๋ ์ถ๊ฐ๋ Component ์ ์ ๊ณต
3) AWT ๊ฐ ์ ๊ณตํ๋ Component ์ ๊ธฐ๋ฅ์ ๋ณด๊ฐ : ๋ฒํผ์ ๋กค์ค๋ฒ ์ด๋ฏธ์ง ์ฌ์ฉ, ํ์ ๋ง ๊ธฐ๋ฅ ๋ฑ,,
4) Drag & Drop ๊ธฐ๋ฅ : MIME ๊ธฐ๋ฐ ํ์ฅ ๊ฐ๋ฅํ ๋ฐ์ดํฐ type ์์คํ
์ ํตํ์ฌ JAVA ์ Non-Java ๊ฐ data ๊ตํ๋ชฉ์
OS
Component
User
Application
AWT
Package
JVM
Component
User
Application
Swing
Package
AWT
Package
15. 14
GUI
๏ง ๊ณ์ธต๊ตฌ์กฐ
. Swing ์ JComponent ๋ AWT ์ Container ๋ฅผ ์์ํ๋ค
. Swing ์ ์ต์์ Container ๋ AWT ์ ์ต์์ Container ๋ฅผ ์์ํ๋ค
16. 15
GUI
๏ง Container
. ์์ ์ ์์ญ์ ์ปดํฌ๋ํธ๋ฅผ ํฌํจ์ํค๊ณ ๊ด๋ฆฌํ๋ ์ญํ ์ ํ๋ฉฐ ์ปจํ
์ด๋๊ฐ ๋ค๋ฅธ ์ปจํ
์ด๋๋ฅผ ํฌํจํ ์๋ ์๋ค.
. ์ปจํ
์ด๋์ ์ข
๋ฅ์๋
(1) ์ต์์ Container : Frame, Applet, Dialog (JFrame, JApplet, JDialog)
(2) Sub Container : Panel, Window
. Frame ์ Window ๋ฅผ ์์ ๋ฐ์ ๊ฐ์ฒด๋ก์ Window ์ ๊ฒฝ๊ณ์ , ํ์ดํ, ๋ฉ๋ด, ์์คํ
์์ ๋ฑ์ด ์ถ๊ฐ๋ ๊ธฐ๋ฅ์ด๋ค
. Applet ์ Panel ์ ์์๋ฐ์ ๊ฐ์ฒด๋ก์, HTML ๋ด์ ํฌํจ๋์ด์ ธ HTML ์ Window ๋ฅผ ์ฌ์ฉํ๋ ๊ฐ๋
์ด๋ค
๏ง Panel
. Sub Container ์ด๋ฉฐ, ๋ค๋ฅธ Sub container (Panel) ๋ ํฌํจ ๊ฐ๋ฅํ๋ค
. Container ์ ๊ฐ์ด ๋ค๋ฅธ component ๋ฅผ ์์ ์ ์์ญ์ ํฌํจ ๊ฐ๋ฅํ๋ค
. ์ต์์ Container (Frame) ์ ํฌํจ ๋์ด์ ธ ์ฌ์ฉ๋๋ค (์ค์ค๋ก ๊ทธ๋ฆด ์ ๋ ์๋ค)
๏ง Layout ๊ฐ์ฒด
. Container ๋ด์ Component ๋ค์ ๋ฐฐ์น ์ํค๋ ๊ธฐ๋ฅ์ ํ๋ค
. Layout ์ข
๋ฅ : Flow (์ข์ฐ ์ฌํญ ๋ฐฐ์น) , Grid (ํ๋ ฌ๋ฐฐ์น) , Border (๋์๋จ๋ถ์ค์ ๋ฐฐ์น - Default) , Card (๋ค์ ์จ๊ธฐ ๋ฐฐ์น)
๏ง AWT Components
. OS ์์ ์ค์ ๊ตฌํ์ ๋ด๋นํ๋ Heavyweight Component ์ด๋ค
๏ง Swing Components
. JVM ์์ ์ค์ ๊ตฌํ์ ๋ด๋นํ๋ Lightweight Component ์ด๋ค
17. 16
GUI
๏ง AWT ์ฐ๊ฒฐ๊ตฌ์กฐ
. ์ฐ๊ฒฐ ๊ด๊ณ๊ฐ Tree ๊ตฌ์กฐ๋ฅผ ์ง๋๋ค
. Container.add() method ๋ฅผ ํตํ์ฌ ์ฐ๊ฒฐ๊ด๊ณ๋ฅผ ํ์ฑ์ํจ๋ค
. Panel ์ Panel ์ ํ๋ถ์ ์ง๋ ์ ์๋ค
public static void main(String[] args) {
Frame fr = new Frame() ;
FlowLayout flo = new FLowLayout() ;
fr.setlayout(flo) ;
Panel pan1 = new Panel() ;
Panel pan2 = new Panel() ;
Button btn1 = new Button() ;
pan1.add(pan2) ;
pan1.add(btn1) ;
Button btn2 = new Button() ;
fr.add(pan1) ;
fr.add(btn2) ;
}
Frame
Panel
Panel
Component
Component
Component
Layout
Layout
Layout
18. 17
GUI - Applet
๏ง Applet
. ์์ Application ์ด๋ ๋ป์ผ๋ก, Client ์์ Web Browser (Webkit) ๋ฅผ ํตํด ์คํํ๋ JAVA class ๋ฅผ ๋งํ๋ค
(1) HTML ๋ด์์ applet tag ๋ฅผ ์ฌ์ฉํ์ฌ (HTML5 ์์ deprecated ๋์์ผ๋ฉฐ object tag ์ฌ์ฉ) ์คํ๋ class ๋ฅผ ์ง์ ํ๋ค
(2) ํด๋น class ๋ Webkit ์ด ๋ค์ด๋ก๋ ํ์ฌ Local ์ ์์น ์ํค๊ณ JRE ์๊ฒ ์คํ์ ์์ฒญ ํ๋ค
(3) Window ์์๋ jp2launcher.exe ๊ฐ java.exe ๋ฅผ (java plug-in) ์คํ์ํค๋ ๊ตฌ์กฐ
. ๋ฐ๋์ Applet ์ ์์ ํ์ฌ์ผ ํ๋ค (Applet ์ Panel ์ ์์ํ๋ค)
. Main thread ์์ Life Cycle ์ ๊ด๋ฆฌํ๋ค (init ๏ start or paint ๏ stop ๏ destroy)
HTML
<applet codebase = URL
code=AppleTest.class
width=200 height=100
</applet>
Webkit
public class AppletTest extends Applet {
public AppletTest(){ // Constructor
}
@Override
public void init(){}
@Override
public void start(){}
@Override
public void paint(Graphic g){}
@Override
public void stop(){}
@Override
public void destroy(){}
}
Applet
Panel
Component
Layout
Layout
Applet
Class
JAVA
Plug-In
HTML
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="200" height="200"
codebase= URL
<param name="code" value="Applet1.class">
</object>
19. 18
GUI
๏ง Swing Pane
. Swing ์์๋ Pane ๊ฐ์ฒด๋ฅผ ํตํ์ฌ ๊ณต๊ฐ์ ์ธ ์์น์ ์ฐ๊ฒฐ ๊ด๊ณ๊ฐ ํ์ฑ๋๋ค
. ์์ Container (JFrame, JApplet, JDialog) ๊ฐ์ฒด ๊ฐ ์์ฑ๋๋ฉด ์ธ๊ฐ์ง Pane (JRoot, JLayered, JContent) ์ ์๋ ์์ฑ๋๋ค
. JRootPane ์ ๊ฐ์ฅ ์์ชฝ์ ์์ผ๋ฉด์ ControlPnae ์ด ์ฐจ์งํ๋ ์์ญ ๋ฐ๊นฅ์ผ๋ก Border ๋ฅผ ์ง๋๊ณ ์๋ค.
. JLayeredPane ์ ๊ฐ์ ธ๊ฐ๋ ์ด์ ๋ ๊ตฌ์ฑ๋๋ Component ์ ๋ํ์ฌ ๊ณต๊ฐ์ dimension ์ธ Z-Order ๋ฅผ ๊ฐ์ ธ๊ฐ ์ ์๋ค
JLayeredpane ์ JContentPane ํ๋ถ ์ ๋ ๊ตฌ์ฑํ ์ ์๋ค
. JContentPane ์ JMenuBar ๊ฐ ์๋ค๋ฉด JLayeredPane ์ ์ ์ฒด ์์ญ์ ๋์ด๊ฒ ๋๋ค.
์ด๋ฐ ๊ฒฝ์ฐ, Component ๋ฅผ ๋ฐ๋ก LayeredPane ์ ๋ถ์ฌ๋ ๊ฐ๋ฅํ๋ค
. JMenuBar ๋ JLayredPane ์ ๋ถ์ฌ ์ฌ์ฉํ๋๋ฐ, ์ด๋ MenuItem ์ด ๋ณด์ผ๋ High Priority Z order ๋ฅผ ๊ฐ์ ธ๊ฐ๊ธฐ ์ํจ์ด๋ค
JRoot
Pane
JLayered
Pane
JContent
Pane
JMenuBar
JFrame
20. 19
GUI
๏ง Swing Pane
. ์๋์ ๊ฐ์ด ์ธ๊ฐ์ง ๋ชจ์ต์ผ๋ก ์ฌ์ฉ Pattern ์ ๋ถ๋ฅ ํ ์ ์๋ค
(1) ์ฌ์ฉ๋ชจ์ต 1 : JMENU ๋ฅผ ๊ฐ์ ธ๊ฐ๋ ์ผ๋ฐ์ ์ธ ๊ฒฝ์ฐ
(2) ์ฌ์ฉ๋ชจ์ต 2 : JMENU ์์ด ๊ฐ์ ธ๊ฐ๋ฉด์, ๊ตฌ์ฑ๋ Component ๊ฐ Z order ๋ฅผ ๊ฐ์ ธ๊ฐ๋ ๊ฒฝ์ฐ
(3) ์ฌ์ฉ๋ชจ์ต 3 : JLayeredPane ์ ContenPane ํ๋ถ์ ๊ตฌ์ฑํ์ฌ, Component ์ ๋ํ์ฌ Z order ๋ฅผ ๊ฐ์ ธ๊ฐ๋ ๊ฒฝ์ฐ
JFrame
Jroot
Pane
JLayered
Pane
JContent
Pane
Component
JMenuBar
์ฌ์ฉ๋ชจ์ต 1
JFrame
Jroot
Pane
JLayered
Pane
Component
์ฌ์ฉ๋ชจ์ต 2
JFrame
Jroot
Pane
JLayered
Pane
Jcontent
Pane
JLayered
Pane
JMenuBar
Component
์ฌ์ฉ๋ชจ์ต 3
21. 20
GUI
๏ง Swing JLayeredPane
. JLayeredPane adds depth to a JFC/Swing container, allowing components to overlap each other when needed.
An Integer object specifies each component's depth in the container, where higher-numbered components sit "on top" of other components.
Component 3
(Priority Order 1)
Component 2
(Priority Order 2)
Component 1
(Priority Order 3)
Layered
Pane
(jlp)
jlp.add(c1,3)
jlp.add(c2,2)
jlp.add(c3,1)
moveToBack(component)
moveToFront(component)
getPosition(component)
getLayer()
22. 21
GUI
๏ง AWT Event Handling
. Listener Interface ๋ฅผ ๊ตฌํํ ๊ฐ์ฒด๋ฅผ Event ์์ค๊ฐ์ฒด์ ๋ฑ๋ก (addXListener) ํ๋ค
๊ตฌ๋ถ Event Type ๊ฐ์ฒด Event ์์ค ๊ฐ์ฒด ์ค๋ช
Listener Interface
AWT KeyEvent Component ๋ชจ๋ Component ์ ํค ๋์ ๋ฐ์์ KeyListener
MouseEvent Component ๋ชจ๋ Component ์ ๋ง์ฐ์ค ๋์ ๋ฐ์์ MouseListener
MouseMotionLister
FocusEvent Component ๋ชจ๋ Component ์ focus On/Off ์ FoxusListener
ComponentEvent Component ๋ชจ๋ Component ์ ์ํ๊ฐ์ ComponentListener
TextEvent TextField TextArea Text ๋ณ๊ฒฝ ์ TextListener
WindowEvent Window Window ์ํ๊ฐ์ WindowListener
ContainerEvent Container Component ์ถ๊ฐ ํน์ ์ญ์ ์ ContainerListener
Swing ActionEvent JButton JList
JMenuItem JTextField
Item ์ ํ ์ ActionListener
ItemEvent JCheckBox JList
JCheckBoxMenuItem
์ ํ ํน์ ํด์ง ์ ItemListener
AdjustEvent JScrollBar ์ฌ์ฉ์ ๊ฐ ์์ง ์์ ๋ AdjustmentListener
Event
์์ค๊ฐ์ฒด
Event
X
Event ๊ฐ์ฒด
App
Listener Class
App
Main Class
addXListener
Method(event)
event.getSource() ๋ฅผ ํตํ์ฌ
์์ค๊ฐ์ฒด๋ฅผ ์ ์ ์๋ค
23. 22
GUI
๏ง AWT Event Handling
. Template
package a.b.gui;
import java.awt.* ;
import javax.swing.* ;
public class Main{
public static void main(String[] args) {
JButton bt1 = new JButton() ;
bt1.addMouseListener (new AWTListenerClass . MouseListenerClass()) ;
}
}
package a.b.gui;
import java.awt.event.* ;
import java.util.* ;
public class AWTListenerClass {
public static class ActionListenerClass implements ActionListener{
@Override
public void actionPerformed (ActionEvent arg0){}
}
public static class KeyListenerClass implements KeyListener{
@Override
public void keyPressed(KeyEvent arg0) {}
public void keyReleased(KeyEvent arg0) {}
public void keyTyped(KeyEvent arg0) {}
}
public static class MouseListenerClass implements MouseListener{
@Override
public void mouseClicked(MouseEvent arg0) {}
public void mouseEntered(MouseEvent arg0) {}
public void mouseExited(MouseEvent arg0) {}
public void mousePressed(MouseEvent arg0) {}
public void mouseReleased(MouseEvent arg0) {}
}
}
24. 23
GUI
๏ง ์ฌ์ฉ์ ์ ์ Graphics
. AWT : Canvas ์ paint() ๋ฅผ Override ํ์ฌ ๊ตฌํ ํ๋ค.
. Swing : JPanel ์ paintComponent() ๋ฅผ Override ํ์ฌ ๊ตฌํ ํ๋ค.
public class CustomJP extends JPanel(){
public CustomJP(){
this.setLayout(null) ;
this.setBounds(100,100,300,300) ;
}
@Override in Component
protected void paintComponent (Graphic g){
// ์ฌ์ฉ์ ์ ์ Graphic
}
}
public class CustomCanvas extends Canvas(){
public CustomCanvas (){
this.setBounds(100,100,300,300) ;
}
@Override in Component
public void paint (Graphic g){
// ์ฌ์ฉ์ ์ ์ Graphic
}
}
25. 24
EE
๏ง Enterprise Edition
. ์๋ฒ ์ธก ์์ EE ์ ๋๋ต์ ์ธ ๋ชจ์ต์ด๋ค
Web Server
Web Container
Servlets JSP
Web Application Server (WAS)
EJB Container
E JavaBean E JavaBean
JavaMail JMS JNDI JDBC
Browser
Client
Application
Client
Mail
Server
Message
Tx.
Directory
Service
Oracle
26. 25
EE
๏ง JSP (Java Server Page) , Servlet
. ์๋ฒ์์ ์คํ๋๋ Java Class ๋ก์ , ์๋ ์ ๊ฐ์ ๋ชฉ์ ์ด๋ค
(1) Dynamic html page ; ์ฃผ์ด์ง Parameter ์ ๋์ํ๋ HTML page ๋ฅผ ๋์ ์ผ๋ก ๋ง๋ค์ด์ client ์ ์ ๊ณตํ๋ค, http://URL/index.jsp
(2) Interact with FORM ; Post ๋์ด์ง FORM ๊ฐ์ฒด์ ๋ํ์ฌ ํน์ ํ ๊ธฐ๋ฅ์ ์ํํ๋ค , FORM action = /Servlet/test1
. MVC (Model View Control) ์ฌ์ฉ๋ชจ๋ธ
(1) JSP Only : View, Controller ์ญํ ์ JSP ํผ์ ๋ด๋น
(2) JSP / Servlet : View ๋ JSP ๊ฐ ๋ด๋นํ๊ณ , Controller ์ญํ ์ Servlet ์ด ๋ด๋น
(3) JSP / JavaBean : View ๋ JSP ๊ฐ ๋ด๋นํ๊ณ , Controller ์ญํ ์ JavaBean ์ด ๋ด๋น
Web
Client
Web
Server
Servlet
(test1)
HTTP Post ?action=/Servelt/test1
Form
action=/Servlet/test1
Do Action
Web
Client
Web
Server
JSP
index.html
HTTP Get ?name=kwon
HTTP Response
index.jsp
๋์ ์์ฑ
์ฐธ๊ณ (HTTP)
. abs_path ๋ฐ Parameter ๋
URL ์ Optional ์ ๋ณด๋ก์
Request Line ์ ํฌํจ๋๋ค
27. 26
EE JSP
๏ง JSP
. HTML ๋ฌธ์ (Page) ๋ด์ 3๊ฐ์ง (์ง์์ด, Scripting, Action) Element ๋ก ํํ๋๋ค
. HTML ํ์ผ ํ์ฅ ์ ๋ช
์ โjspโ ๋ก ํ๋ค
. Runtime ์ javax.servlet.http.HttpServlet ์ ์์๋ฐ๋ Servlet class ๊ฐ ๋ง๋ค์ด ์ง๊ณ JSP Container ๊ฐ life cycle ์ ์ฃผ๊ดํ๋ค
(๊ถ๊ทน์ ์ผ๋ก๋ Servlet ๊ณผ ๋๋ฅ์ ๊ฐ๋
์ด๋ค)
. Servlet ์ ์ฌ์ฉํ๋ฉด HTML ๋ฌธ์๋ฅผ ๋ง๋ค๊ธฐ๊ฐ ๋์ด ํ์ฌ (PrintWriter ๋ฅผ ์ด์ฉ) , ํธ์ ๋ชฉ์ ์ผ๋ก ๋์ด
. EE ์์ ์ ๊ณตํ๋ JSP ์ ์๋ฌต์ ๊ฐ์ฒด : request, response, out, session, application, config, pageContext, page, exception
. MS ์ ASP (Active Server Page) ๋ PHP ์ ๋์ผํ ๊ธฐ๋ฅ์ด๋ค
. ์ง์์ด Element : <%@ page โฆ.. > , Page ์ Include ์ง์์ด ๋ ๊ฐ์ง ์ด๋ค
. Page ์ง์์ด : language, import, session, buffer, autoFlush, isThreadSafe, info, errorPage, isErrorPage,
: contentType, pageEncoding, extends
.Scripting Element :
(1) Declaration <%! โฆโฆ. %> : ๋ฉค๋ฒ๋ณ์ ๋ ๋ฉ์๋ ๋ฅผ ์ ์ธํ ๋ ์ฌ์ฉ
(2) Expression <%= โฆโฆ %> : ๊ฐ๋จํ data ์ถ๋ ฅ์ด๋ ๋ฉ์๋ ํธ์ถ์ ์ฌ์ฉ
(3) Scriptlet <% โฆโฆ.. %> : ์์ Java code ๋ง ๊ฐ๋ฅ, Page ์ ๊ฐ๊ฒฐ์ฑ์ ์ํ์ฌ ์ฌ์ฉ์ด ๊ถ๊ณ ๋์ง ์๊ณ JavaBeans ๋ฅผ ๋์ ์ฌ์ฉ
. Action Element : <jsp: โฆ.. />
28. 27
EE - Servlet
๏ง Servlet
. Client HTTP message ์์ URL (Parameter ๊ฐ ํฌํจ๋) ๋ก ์ฌ์ฉ์ด ๋์ด์ง๋ค (HTTP POST ?action=/Servlet/test1)
. Server ์ธก์์ ์ํ๋๋, JAVA ๋ก ๊ตฌํ๋ CGI (Common Gateway Interface) ์ด๋ค
. Web.xml ํ์ผ์ ํ์๋ก ํ๋ค
. ๋ฐ๋์ javax.servlet.http.HttpServlet ์ ์์ ํ์ฌ์ผ ํ๋ค
. Servlet Container ๊ฐ Life Cycle ์ ๊ด๋ฆฌํ๋ค (init ๏ service ๏ destroy)
. ์ฃผ์ํ Servlet Container ๋ก๋ Tomcat, Jetty, Jboss ๋ฑ์ด ์๋ค
public class ServletTest extends HttpServelet
{
@Override
public void init(){}
@Override
public void service(){}
@Override
public void doGet(){}
@Override
public void doPost(){}
@Override
public void destroy(){}
}
Web Server
Servlet
Container
Web Client
Servlet
Class
Web Server
HTTP Request
HTTP Response
service
doGet or doPost
By doGet or doPost
Web Application ์ค์ ํ์ผ
1) Servlet ์ ๋ณด
2) Error Page ์ ๋ณด
3) Listener ์ ๋ณด
4) Filter ์ ๋ณด
5) ๋ณด์์ค์ ์ ๋ณด
web.xml