๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ

ํ•™์Šต ๋‚ด์šฉ - Collection : ์ˆ˜์ง‘ List: ๋ชฉ๋ก ArrayList ๋ฐฐ์—ด์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฆฌ์ŠคํŠธ ์„ ํ˜•๊ตฌ์กฐ O-O-O-O-O ๊ฒ€์ƒ‰์†๋„๊ฐ€ ๋น ๋ฅด๋‹ค index๋กœ ์ ‘๊ทผํ•œ๋‹ค LinkedList ์ถ”๊ฐ€/์‚ญ์ œ ์†๋„๊ฐ€ ๋น ๋ฅด๋‹ค ArrayList arrlist = new ArrayList(); // ๊ธฐ๋ณธํ˜•์‹ //์ถ”๊ฐ€ --> .add(์ €์žฅ๊ฐ’) ๋ฅผ ํ†ตํ•ด ์ฐจ๋ก€๋Œ€๋กœ ๊ฐ’ ์ €์žฅ arrlist.add(111); Integer in = new Integer(222); arrlist.add(in); arrlist.add(new Integer(333)); int len = arrlist.size(); System.out.println("๋ชฉ๋ก์˜ ํฌ๊ธฐ " + len);// ๊ฒฐ๊ณผ : ๋ชฉ๋ก์˜ ํฌ๊ธฐ 3 for (int i = 0; i < ..
- Class Diagram ๊ฐ„๋‹จํ•˜๊ฒŒ ํด๋ž˜์Šค ๋‹ค์ด์–ด๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด๋ณด์•˜๋‹ค. ์ƒ์†์— ๋Œ€ํ•œ ํ™”์‚ดํ‘œ๋Š” ์ •ํ™•ํžˆ ์•Œ๊ฒ ๋Š”๋ฐ ๋‹ค๋ฅธ ํ๋ฆ„์„ ์–ด๋–ป๊ฒŒ ํ™”์‚ดํ‘œ๋กœ ํ‘œํ˜„ํ•˜๋Š”์ง€๋Š” ๋” ๊ณต๋ถ€ํ•ด๋ด์•ผ๊ฒ ๋‹ค. (์•ž์— +์™€ -๋Š” public ์ธ์ง€ private ์ธ์ง€ ๊ตฌ๋ณ„) - MainClass switch๋ฌธ์„ ์ด์šฉํ•ด ๋ฉ”๋‰ด๋ฅผ ๋งŒ๋“ค์–ด๋†“์•˜๋‹ค. package main; import java.io.IOException; import java.util.Scanner; import dao.DaoClass; import dto.HumanDto; public class MainClass { public static void main(String[] args) throws IOException { //HumanDto playerArr[] = new HumanDt..
ํ•™์Šต ๋‚ด์šฉ - ์ƒ์† - instanceof ๋ถ€๋ชจํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๋กœ ์ƒ์„ฑ๋œ ์ž์‹ ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ฐพ์•„์ฃผ๋Š” ์˜ˆ์•ฝ์–ด for (int i = 0; i < scArr.length; i++) { if(scArr[i] instanceof ChildOne) {// ๋ถˆ๋ฆฐ๊ฐ’์œผ๋กœ ๋‚˜ํƒ€๋‚ธ๋‹ค. System.out.println("true"); } } (cast ๋ณ€ํ™˜์€ ํ—ท๊ฐˆ๋ฆฌ๋Š” ๋ถ€๋ถ„์ด๋‹ˆ ๊ณ„์†ํ•ด์„œ ๋ด์„œ ๊ผญ ์ดํ•ดํ•  ๊ฒƒ.) public class MainClass { public static void main(String[] args) { ChildClass cc = new ChildClass(); cc.method(); ParentClass pc = new ChildClass();//Parent ์ฃผ์†Œ๊ฐ’์„ ๊ฐ€์ง„ ChildClass..
ํ•™์Šต ๋‚ด์šฉ - ์ ˆ์ฐจ์ง€ํ–ฅ : ๋ณ€์ˆ˜์„ ์–ธ, ํ•จ์ˆ˜ -> ์—ฐ์‚ฐ (์ˆœ์„œ์ง€ํ–ฅ) -> ex) line 50000 ex ) ์ฃผ์‚ฌ์œ„ (ํ•˜๋‚˜๋งŒ๋“ค์–ด๋†“์œผ๋ฉด ๊ณ„์† ์‚ฌ์šฉ) -> ํ™•์žฅ์„ฑ ์œ ์ง€๋ณด์ˆ˜ ์šฉ์ด, ์žฌ์‚ฌ์šฉ์„ฑ ์ข‹๋‹ค. ์ฝ”๋“œ ์ž‘์„ฑ์— ์žˆ์–ด ์ค‘์š”ํ•œ *๊ฐ€๋…์„ฑ*์ด ํ–ฅ์ƒ๋œ๋‹ค. - ์ƒ์„ฑ์ž (constructor) : ํ•จ์ˆ˜(๋ฉ”์†Œ๋“œ) ํด๋ž˜์Šค๋ช…๊ณผ ๊ฐ™๋‹ค return๊ฐ’์ด ์—†๋‹ค Over Load๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค class ์ƒ์„ฑ ์‹œ ์ž๋™ ํ˜ธ์ถœ ๋ณ„๋„์˜ ํ˜ธ์ถœ ๋ถˆ๊ฐ€ != ์ดˆ๊ธฐํ™” ์ƒ๋žต ๊ฐ€๋Šฅ - ์†Œ๋ฉธ์ž (destructor) (์ž๋ฐ”์—์„  ์•ˆ์“ฐ์ด์ง€๋งŒ ์ด๋Ÿฐ๊ฒŒ ์žˆ๋‹ค๋Š” ๊ฒƒ๋งŒ ์•Œ์•„๋‘์ž.) ๋ฐ˜๋“œ์‹œ 1๊ฐœ public class TestClass { int number; public TestClass() {//..
ํ•™์Šต ๋‚ด์šฉ - Exception : ์˜ˆ์™ธ != error public class Mainclass { public static void main(String[] args) { int c; try { c = 4 / 0;//try๋ฌธ์—์„œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด }catch(ArithmeticException e) { c = -1; //catch๋ฌธ์ด ์ˆ˜ํ–‰๋œ๋‹ค. } System.out.println(c); } }//๊ฒฐ๊ณผ ๊ฐ’ : -1 - 2์ง„ ํ•จ์ˆ˜ ์ง์ ‘ ๋งŒ๋“ค๊ธฐ ์œ„์— binary ๋ฉ”์†Œ๋“œ๋Š” ๋‚ด๊ฐ€ ๋งŒ๋“ค์—ˆ๊ณ , ์•„๋ž˜ change ๋ฉ”์†Œ๋“œ๋Š” ๊ฐ•์‚ฌ๋‹˜์ด ๋งŒ๋“ค์–ด์ฃผ์…จ๋‹ค. ๋‚ด๊ฐ€ ๋งŒ๋“  ๊ฒƒ๋„ ์ •์ƒ ์ž‘๋™์€ ๋˜์—ˆ์ง€๋งŒ, ์•„๋ž˜ ๋ฉ”์†Œ๋“œ์™€ ๋น„๊ตํ•ด๋ณด๋‹ˆ ๋” ๊ฐ„๋‹จํ•˜๊ฒŒ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ๊ฒŒ ๋˜์—ˆ๋‹ค. package work02; public class Mai..
ํ•™์Šต ๋‚ด์šฉ - Calendar ์ผ์ • ๊ด€๋ฆฌ, ํšŒ์› ๊ด€๋ฆฌ, ์ธ์‚ฌ ๊ด€๋ฆฌ ๋“ฑ๋“ฑ - Calendar cal = Calendar.getInstance(); ๋ฅผ ์ด์šฉํ•ด ๋ถˆ๋Ÿฌ์˜ค๊ธฐ //getter int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; // ์›”์„ 0 ~ 11๋กœ ํ‘œํ˜„ํ•˜๊ธฐ ๋•Œ๋ฌธ์— +1๋ฅผ ํ•ด์ค˜์•ผ ์ •์ƒ์ ์œผ๋กœ ์ถœ๋ ฅ int day = cal.get(Calendar.DATE); int hour = cal.get(Calendar.HOUR); int minute = cal.get(Calendar.MINUTE); int second = cal.get(Calendar.SECOND); //๋‚ ์งœ ์„ค์ • (setter) cal.set(Calendar...
ํ•™์Šต ๋‚ด์šฉ - Sorting : ์ •๋ ฌ ์˜ค๋ฆ„์ฐจ์ˆœ : 1, 2, 3.... ๋‚ด๋ฆผ์ฐจ์ˆœ : 9, 8, 7.... - ์„ ํƒ์ •๋ ฌ int[] number = { 5, 9, 1, 8, 2, 6, 4, 7, 3, 10 }; int temp; for (int i = 0; i number[j]) { //i๋ฒˆ์ง€์˜ ์ˆซ์ž j๋ฒˆ์ง€์˜ ์ˆซ์ž๋ณด๋‹ค ํด ๊ฒฝ์šฐ ๊ตํ™˜ (์˜ค๋ฆ„์ฐจ์ˆœ) //swap//๋ถ€๋“ฑํ˜ธ ๊ธฐํ˜ธ๋งŒ ๋ฐ”๊พธ๋ฉด ๋‚ด๋ฆผ์ฐจ์ˆœ temp = number[i]; number[i] = number[j]; number[j] = temp; } } } S..
ํ•™์Šต ๋‚ด์šฉ - while, do while๋ฌธ public class mainClass { public static void main(String[] args) { //while๋ฌธ ------------------------------------------------------------ int w; w = 0;//์ดˆ๊ธฐํ™” while(w
EastShine_
'๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (6 Page)